|
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 | +# Disable globbing (-f) for robust parsing (though often omitted). |
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 | +# Define constants for the image name and build paths |
| 9 | +PYTHON_IMAGE_TAG="aleph-sdk-python" |
| 10 | +DOCKERFILE_PATH="docker/python-3.9.dockerfile" |
| 11 | +DIST_DIR="./dist" |
| 12 | + |
| 13 | +# --- Container Engine Detection --- |
| 14 | + |
| 15 | +# Check if Podman is installed and executable. Prioritize Podman over Docker. |
| 16 | +if hash podman 2> /dev/null; then |
| 17 | + CONTAINER_CMD=podman |
9 | 18 | else |
10 | | - DOCKER_COMMAND=docker |
| 19 | + # Fall back to the default Docker command if Podman is not found. |
| 20 | + CONTAINER_CMD=docker |
11 | 21 | fi |
12 | 22 |
|
13 | | -mkdir -p ./dist |
14 | | -chmod 0777 ./dist |
| 23 | +echo "Using container engine: ${CONTAINER_CMD}" |
| 24 | + |
| 25 | +# --- Setup Output Directory --- |
| 26 | + |
| 27 | +# Create the 'dist' directory and set maximum permissions (0777) to ensure |
| 28 | +# the container user can write build artifacts back to the host volume. |
| 29 | +# NOTE: 0777 is highly permissive; adjust if security is paramount. |
| 30 | +mkdir -p "${DIST_DIR}" && chmod 0777 "${DIST_DIR}" |
| 31 | +echo "Created writable output directory: ${DIST_DIR}" |
| 32 | + |
| 33 | +# --- Build the Docker Image --- |
| 34 | + |
| 35 | +# Build the image using the detected container engine, tag it, and specify the Dockerfile. |
| 36 | +"${CONTAINER_CMD}" build -t "${PYTHON_IMAGE_TAG}" -f "${DOCKERFILE_PATH}" . |
| 37 | + |
| 38 | +# --- Run the Container Interactively --- |
15 | 39 |
|
16 | | -$DOCKER_COMMAND build -t aleph-sdk-python -f docker/python-3.9.dockerfile . |
17 | | -$DOCKER_COMMAND run -ti --rm \ |
| 40 | +# Run the container to drop into an interactive shell for development/testing. |
| 41 | +# -ti: Interactive and pseudo-TTY allocation. |
| 42 | +# --rm: Remove the container filesystem after the container exits. |
| 43 | +# -w /opt/aleph-sdk-python: Set the working directory inside the container. |
| 44 | +# -v "$(pwd)/dist": Mount the host's dist directory to the container's output path. |
| 45 | +# --entrypoint /bin/bash: Override the default entrypoint to open a shell. |
| 46 | +"${CONTAINER_CMD}" run -ti --rm \ |
18 | 47 | -w /opt/aleph-sdk-python \ |
19 | 48 | -v "$(pwd)/dist":/opt/aleph-sdk-python/dist \ |
20 | 49 | --entrypoint /bin/bash \ |
21 | | - aleph-sdk-python |
| 50 | + "${PYTHON_IMAGE_TAG}" |
0 commit comments