Created
August 29, 2018 22:46
-
-
Save chrisgoffinet/cd3da653c9cbfaaab28e86bc2107613a to your computer and use it in GitHub Desktop.
docker helper
This file contains hidden or 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/bash | |
set -euo pipefail | |
CMD="$1" | |
login() | |
{ | |
if [ -z "${DOCKER_USER:-}" ] || [ -z "${DOCKER_PASS:-}" ]; then | |
echo "Please set DOCKER_USER and DOCKER_PASS environment variables." | |
exit 1 | |
fi | |
docker login -u $DOCKER_USER -p $DOCKER_PASS | |
} | |
case $CMD in | |
build) | |
REPO="$2" | |
BUILD_PATH="$3" | |
BRANCH=`echo $4 | sed 's/\//-/g'` | |
COMMIT="$5" | |
BUILD_NUMBER="$6" | |
CI_TAG="$REPO:ci" | |
login | |
docker pull $CI_TAG || true | |
docker build --cache-from $CI_TAG -t $CI_TAG "$BUILD_PATH" | |
docker tag $CI_TAG $REPO:"sha-$COMMIT" | |
docker tag $CI_TAG $REPO:"branch-$BRANCH" | |
docker tag $CI_TAG $REPO:"build-$BUILD_NUMBER" | |
;; | |
push) | |
REPO="$2" | |
login | |
docker push $REPO | |
;; | |
*) | |
echo "Unknown command $CMD" | |
exit 1 | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment