Created
May 29, 2021 10:39
-
-
Save TommyTheTribe/28a4fcc5da308551574e0431c80e7eb7 to your computer and use it in GitHub Desktop.
build.sh
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 | |
set -e | |
cd "$(dirname "$0")" | |
VERSION="$(git describe --always | sed 's/^v//')" | |
PACKAGE="$(git config --get remote.origin.url | awk -F '@[^:/]+[:/]?' '{print $(NF)}' | sed s'/.git$//')" | |
DOCKER_TAG=${DOCKER_TAG:-$VERSION} | |
DOCKER_REGISTRY=${DOCKER_REGISTRY:=rg.fr-par.scw.cloud/thetribe} # ICI VALUER LE BON REGISTRY DOCKER | |
DOCKER_IMAGE=${DOCKER_IMAGE:=$DOCKER_REGISTRY/$PACKAGE:$DOCKER_TAG} | |
DOCKERFILE=${DOCKERFILE:-"Dockerfile"} | |
COMMIT_SHA=`git rev-parse --short HEAD` | |
build_image () { | |
docker build \ | |
$TARGET \ | |
--pull \ | |
--force-rm \ | |
--no-cache \ | |
--label "commit-sha=$COMMIT_SHA" \ | |
--tag "$DOCKER_IMAGE" \ | |
-f $DOCKERFILE \ | |
. | |
echo "Docker image successfully built: | |
Dockerfile recipe: $DOCKERFILE | |
Package: $PACKAGE | |
Version: $DOCKER_TAG | |
Registry: $DOCKER_REGISTRY" | |
} | |
push_image () { | |
docker push $DOCKER_IMAGE | |
echo "Docker image pushed: $DOCKER_IMAGE" | |
} | |
while test -n "$1"; do | |
case "$1" in | |
--push) | |
PUSH_ENABLED="true" ;; | |
esac | |
shift | |
done | |
build_image | |
[ -n "$PUSH_ENABLED" ] && push_image | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment