Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 39 additions & 10 deletions scripts/build-to-publish.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,50 @@
#!/bin/sh

# Exit immediately if a command exits with a non-zero status (-e).
# Treat unset variables as an error (-u).
# Disable globbing (-f) for robust parsing (though often omitted).
set -euf

# Use Podman if installed, else use Docker
if hash podman 2> /dev/null
then
DOCKER_COMMAND=podman
# Define constants for the image name and build paths
PYTHON_IMAGE_TAG="aleph-sdk-python"
DOCKERFILE_PATH="docker/python-3.9.dockerfile"
DIST_DIR="./dist"

# --- Container Engine Detection ---

# Check if Podman is installed and executable. Prioritize Podman over Docker.
if hash podman 2> /dev/null; then
CONTAINER_CMD=podman
else
DOCKER_COMMAND=docker
# Fall back to the default Docker command if Podman is not found.
CONTAINER_CMD=docker
fi

mkdir -p ./dist
chmod 0777 ./dist
echo "Using container engine: ${CONTAINER_CMD}"

# --- Setup Output Directory ---

# Create the 'dist' directory and set maximum permissions (0777) to ensure
# the container user can write build artifacts back to the host volume.
# NOTE: 0777 is highly permissive; adjust if security is paramount.
mkdir -p "${DIST_DIR}" && chmod 0777 "${DIST_DIR}"
echo "Created writable output directory: ${DIST_DIR}"

# --- Build the Docker Image ---

# Build the image using the detected container engine, tag it, and specify the Dockerfile.
"${CONTAINER_CMD}" build -t "${PYTHON_IMAGE_TAG}" -f "${DOCKERFILE_PATH}" .

# --- Run the Container Interactively ---

$DOCKER_COMMAND build -t aleph-sdk-python -f docker/python-3.9.dockerfile .
$DOCKER_COMMAND run -ti --rm \
# Run the container to drop into an interactive shell for development/testing.
# -ti: Interactive and pseudo-TTY allocation.
# --rm: Remove the container filesystem after the container exits.
# -w /opt/aleph-sdk-python: Set the working directory inside the container.
# -v "$(pwd)/dist": Mount the host's dist directory to the container's output path.
# --entrypoint /bin/bash: Override the default entrypoint to open a shell.
"${CONTAINER_CMD}" run -ti --rm \
-w /opt/aleph-sdk-python \
-v "$(pwd)/dist":/opt/aleph-sdk-python/dist \
--entrypoint /bin/bash \
aleph-sdk-python
"${PYTHON_IMAGE_TAG}"