Guest User

Untitled

a guest
Jul 22nd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. # Official docker image.
  2. image: docker:latest
  3.  
  4. services:
  5. - docker:dind
  6.  
  7. .ssh_template: &ssh_definition # Hidden key that defines an anchor named 'job_definition'
  8. before_script:
  9. - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
  10. - apk add --update rsync openssh-client
  11.  
  12. # For Docker builds disable host key checking. Be aware that by adding that
  13. # you are suspectible to man-in-the-middle attacks.
  14. # WARNING: Use this only with the Docker executor, if you use it with shell
  15. # you will overwrite your user's SSH config.
  16. - mkdir -p ~/.ssh
  17. - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
  18. # In order to properly check the server's host key, assuming you created the
  19. # SSH_SERVER_HOSTKEYS variable previously, uncomment the following two lines
  20. # instead.
  21. # - mkdir -p ~/.ssh
  22. # - '[[ -f /.dockerenv ]] && echo "$SSH_SERVER_HOSTKEYS" > ~/.ssh/known_hosts'
  23. # Pull docker image you build to this job runner
  24. - docker pull $CI_REGISTRY_IMAGE:$DOCKER_TAG
  25. # Save Image file
  26. - docker save $CI_REGISTRY_IMAGE:$DOCKER_TAG > $DOCKER_TAG
  27. # Compress it for faster transfer
  28. - tar czf $DOCKER_TAG.tgz $DOCKER_TAG
  29. - scp $DOCKER_TAG.tgz $SSH:$DIR
  30. - ssh $SSH "cd $DIR;tar xzf $DOCKER_TAG.tgz"
  31. # And load image on production server
  32. - ssh $SSH "cd $DIR;docker load < $DOCKER_TAG"
  33. # Remove unnecessary file
  34. - ssh $SSH "cd $DIR;rm $DOCKER_TAG $DOCKER_TAG.tgz"
  35. - rm $DOCKER_TAG $DOCKER_TAG.tgz
  36.  
  37. build:
  38. stage: build
  39. script:
  40. - docker build --pull -t "$CI_REGISTRY_IMAGE" .
  41. - docker push "$CI_REGISTRY_IMAGE"
  42. only:
  43. - master
  44.  
  45. deploy:
  46. # Inherit from parent, you could make other task like test, migrate and other
  47. <<: *ssh_definition
  48. stage: deploy
  49. script:
  50. - ssh $SSH "cd $DIR; docker-compose up -d web"
  51. variables:
  52. DIR: 'PROJECT_DIR_ON_SERVER'
  53. PRODUCTION_STAGING: 'production'
  54. SSH: 'root@YOUR_SERVER_IP'
  55. DOCKER_TAG: 'latest'
Add Comment
Please, Sign In to add comment