Created
November 28, 2021 22:25
-
-
Save brianjbayer/0a54ec636e75b6353286fe91a19c8c7a to your computer and use it in GitHub Desktop.
Script to Docker Build a Tagged Image
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
#!/bin/sh | |
# This script builds the image with either the specified argument | |
# or default git long sha of the last commit | |
IMAGE_NAME=${IMAGE_NAME:-SET-THE-dockerid/repository-name} | |
must_be_git_repos() { | |
git rev-parse --git-dir > /dev/null 2>&1 | |
errcode=$? | |
if [ $errcode -ne 0 ]; then | |
echo "OOPSIE, not git repository, you must specify tag" | |
exit $errcode | |
fi | |
} | |
## MAIN ## | |
if [ -z "$1" ]; then | |
must_be_git_repos | |
GIT_SHA=$(git log -1 --pretty=%H) | |
TAG=${GIT_SHA} | |
else | |
TAG=$1 | |
fi | |
TAGGED_IMAGE=${IMAGE_NAME}:${TAG} | |
docker build --no-cache -t ${TAGGED_IMAGE} . |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment