Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- set -x
- set -e
- # allows `docker build ...` to use images cache
- # could be installed with: pip install restore_commit_times
- #restore_commit_times .
- DOCKERFILE_LOCATION="$1"
- [ -z "$DOCKERFILE_LOCATION" ] && DOCKERFILE_LOCATION=.
- [ -z "$DOCKER_NAME" ] && DOCKER_NAME=$CI_REGISTRY/$CI_PROJECT_PATH
- [ -z "$DOCKER_TAG" ] && DOCKER_TAG=gitlab-$CI_PIPELINE_ID
- docker build -t $DOCKER_NAME:$DOCKER_TAG $DOCKERFILE_LOCATION
- (
- # wait for 60 seconds for lock to be released and fail on timeout
- flock -w 60 9 || exit 1
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker push $DOCKER_NAME:$DOCKER_TAG
- docker tag $DOCKER_NAME:$DOCKER_TAG $DOCKER_NAME:latest
- docker push $DOCKER_NAME:latest
- docker tag $DOCKER_NAME:$DOCKER_TAG $DOCKER_NAME:$CI_COMMIT_REF_NAME
- docker push $DOCKER_NAME:$CI_COMMIT_REF_NAME
- ) 9>/tmp/gitlab-ci-docker-build.lock
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement