|
1 | 1 | #!/bin/sh |
2 | 2 |
|
| 3 | +# Exit immediately if a command exits with a non-zero status (-e). |
| 4 | +# Treat unset variables as an error (-u). |
| 5 | +# Enable the use of "glob" characters in pathnames, but only if they match (-f). |
3 | 6 | set -euf |
4 | 7 |
|
5 | | -# Use Podman if installed, else use Docker |
6 | | -if hash podman 2> /dev/null |
7 | | -then |
8 | | - DOCKER_COMMAND=podman |
| 8 | +# --- Configuration --- |
| 9 | +IMAGE_NAME="aleph-sdk-python" |
| 10 | +DOCKERFILE_PATH="docker/python-3.9.dockerfile" |
| 11 | +CONTAINER_MOUNT_PATH="/opt/${IMAGE_NAME}" |
| 12 | + |
| 13 | +# --- Determine Container Runtime (Podman vs. Docker) --- |
| 14 | + |
| 15 | +# Use 'command -v' for a more portable and reliable check for the container runtime. |
| 16 | +if command -v podman > /dev/null 2>&1; then |
| 17 | + DOCKER_COMMAND=podman |
| 18 | + echo "INFO: Using Podman as the container runtime." |
| 19 | +elif command -v docker > /dev/null 2>&1; then |
| 20 | + DOCKER_COMMAND=docker |
| 21 | + echo "INFO: Using Docker as the container runtime." |
9 | 22 | else |
10 | | - DOCKER_COMMAND=docker |
| 23 | + echo "ERROR: Neither 'podman' nor 'docker' commands were found." >&2 |
| 24 | + exit 1 |
11 | 25 | fi |
12 | 26 |
|
13 | | -$DOCKER_COMMAND build -t aleph-sdk-python -f docker/python-3.9.dockerfile . |
14 | | -$DOCKER_COMMAND run -ti --rm --entrypoint /bin/bash -v "$(pwd)":/opt/aleph-sdk-python aleph-sdk-python |
| 27 | +# --- Build the Docker Image --- |
| 28 | + |
| 29 | +# Build the image using the determined command and specified Dockerfile path. |
| 30 | +# -t: Tags the image with the defined name. |
| 31 | +echo "INFO: Building image ${IMAGE_NAME} using ${DOCKERFILE_PATH}..." |
| 32 | +$DOCKER_COMMAND build -t "${IMAGE_NAME}" -f "${DOCKERFILE_PATH}" . |
| 33 | + |
| 34 | +# --- Run the Interactive Development Container --- |
| 35 | + |
| 36 | +# Run the container for interactive development. |
| 37 | +# -ti: Allocates a pseudo-TTY and keeps STDIN open (interactive). |
| 38 | +# --rm: Automatically remove the container when it exits. |
| 39 | +# --entrypoint /bin/bash: Overrides the default entrypoint to provide a shell prompt. |
| 40 | +# -v: Mounts the current working directory ($PWD) into the container for source access. |
| 41 | +echo "INFO: Running interactive container. Source code mounted at ${CONTAINER_MOUNT_PATH}." |
| 42 | +$DOCKER_COMMAND run \ |
| 43 | + -ti \ |
| 44 | + --rm \ |
| 45 | + --entrypoint /bin/bash \ |
| 46 | + -v "$(pwd)":"${CONTAINER_MOUNT_PATH}" \ |
| 47 | + "${IMAGE_NAME}" |
0 commit comments