-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
can now optionally push to dockerhub
- Loading branch information
1 parent
870556a
commit 23416cc
Showing
1 changed file
with
26 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |