Advertisement
Guest User

Untitled

a guest
Apr 26th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. set -x
  4. set -e
  5.  
  6. # allows `docker build ...` to use images cache
  7. # could be installed with: pip install restore_commit_times
  8. #restore_commit_times .
  9.  
  10. DOCKERFILE_LOCATION="$1"
  11. [ -z "$DOCKERFILE_LOCATION" ] && DOCKERFILE_LOCATION=.
  12.  
  13. [ -z "$DOCKER_NAME" ] && DOCKER_NAME=$CI_REGISTRY/$CI_PROJECT_PATH
  14. [ -z "$DOCKER_TAG" ] && DOCKER_TAG=gitlab-$CI_PIPELINE_ID
  15.  
  16. docker build -t $DOCKER_NAME:$DOCKER_TAG $DOCKERFILE_LOCATION
  17.  
  18. (
  19.  
  20. # wait for 60 seconds for lock to be released and fail on timeout
  21. flock -w 60 9 || exit 1
  22.  
  23. docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
  24.  
  25. docker push $DOCKER_NAME:$DOCKER_TAG
  26.  
  27. docker tag $DOCKER_NAME:$DOCKER_TAG $DOCKER_NAME:latest
  28. docker push $DOCKER_NAME:latest
  29.  
  30. docker tag $DOCKER_NAME:$DOCKER_TAG $DOCKER_NAME:$CI_COMMIT_REF_NAME
  31. docker push $DOCKER_NAME:$CI_COMMIT_REF_NAME
  32.  
  33. ) 9>/tmp/gitlab-ci-docker-build.lock
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement