Skip to content

Commit

Permalink
can now optionally push to dockerhub
Browse files Browse the repository at this point in the history
  • Loading branch information
julienchastang committed Dec 3, 2024
1 parent 870556a commit 23416cc
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions jupyter-images/shared/build.sh
Original file line number Diff line number Diff line change
@@ -1,28 +1,44 @@
#!/bin/bash

# Check if an image name is provided
# Exit immediately if a command exits with a non-zero status
set -e

usage() {
echo "Usage: $0 <image-name> [--push]"
echo " <image-name> Name of the Docker image to build"
echo " --push Optionally push the Docker image to DockerHub"
exit 1
}

if [ -z "$1" ]; then
echo "Error: No image name provided."
echo "Usage: $0 <image-name>"
exit 1
usage
fi

IMAGE_NAME=$1
PUSH_IMAGE=false

if [ "$2" == "--push" ]; then
PUSH_IMAGE=true
fi

DATE_TAG=$(date "+%Y%b%d_%H%M%S")
RANDOM_HEX=$(openssl rand -hex 2)
TAG="${DATE_TAG}_${RANDOM_HEX}"

FULL_TAG="unidata/$IMAGE_NAME:$TAG"

# Build the Docker image
echo "Building Docker image with tag: $FULL_TAG"

docker build --no-cache --pull --tag "$FULL_TAG" .

# Check if the build was successful
if [ $? -eq 0 ]; then
echo "Docker image built successfully: $FULL_TAG"
echo "Docker image built successfully: $FULL_TAG"

if $PUSH_IMAGE; then
echo "Pushing Docker image to DockerHub: $FULL_TAG"
docker push "$FULL_TAG"
echo "Docker image pushed successfully: $FULL_TAG"
else
echo "Error: Docker build failed."
exit 1
echo "Skipping Docker image push. Use '--push' to push the image."
fi

exit 0

0 comments on commit 23416cc

Please sign in to comment.