Skip to content

Commit 9624e95

Browse files
authored
Update build-to-publish.sh
1 parent 545f4a8 commit 9624e95

File tree

1 file changed

+39
-10
lines changed

1 file changed

+39
-10
lines changed

scripts/build-to-publish.sh

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,50 @@
11
#!/bin/sh
22

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).
36
set -euf
47

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
918
else
10-
DOCKER_COMMAND=docker
19+
# Fall back to the default Docker command if Podman is not found.
20+
CONTAINER_CMD=docker
1121
fi
1222

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 ---
1539

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 \
1847
-w /opt/aleph-sdk-python \
1948
-v "$(pwd)/dist":/opt/aleph-sdk-python/dist \
2049
--entrypoint /bin/bash \
21-
aleph-sdk-python
50+
"${PYTHON_IMAGE_TAG}"

0 commit comments

Comments
 (0)