Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Official docker image.
- image: docker:latest
- services:
- - docker:dind
- .ssh_template: &ssh_definition # Hidden key that defines an anchor named 'job_definition'
- before_script:
- - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
- - apk add --update rsync openssh-client
- # For Docker builds disable host key checking. Be aware that by adding that
- # you are suspectible to man-in-the-middle attacks.
- # WARNING: Use this only with the Docker executor, if you use it with shell
- # you will overwrite your user's SSH config.
- - mkdir -p ~/.ssh
- - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
- # In order to properly check the server's host key, assuming you created the
- # SSH_SERVER_HOSTKEYS variable previously, uncomment the following two lines
- # instead.
- # - mkdir -p ~/.ssh
- # - '[[ -f /.dockerenv ]] && echo "$SSH_SERVER_HOSTKEYS" > ~/.ssh/known_hosts'
- # Pull docker image you build to this job runner
- - docker pull $CI_REGISTRY_IMAGE:$DOCKER_TAG
- # Save Image file
- - docker save $CI_REGISTRY_IMAGE:$DOCKER_TAG > $DOCKER_TAG
- # Compress it for faster transfer
- - tar czf $DOCKER_TAG.tgz $DOCKER_TAG
- - scp $DOCKER_TAG.tgz $SSH:$DIR
- - ssh $SSH "cd $DIR;tar xzf $DOCKER_TAG.tgz"
- # And load image on production server
- - ssh $SSH "cd $DIR;docker load < $DOCKER_TAG"
- # Remove unnecessary file
- - ssh $SSH "cd $DIR;rm $DOCKER_TAG $DOCKER_TAG.tgz"
- - rm $DOCKER_TAG $DOCKER_TAG.tgz
- build:
- stage: build
- script:
- - docker build --pull -t "$CI_REGISTRY_IMAGE" .
- - docker push "$CI_REGISTRY_IMAGE"
- only:
- - master
- deploy:
- # Inherit from parent, you could make other task like test, migrate and other
- <<: *ssh_definition
- stage: deploy
- script:
- - ssh $SSH "cd $DIR; docker-compose up -d web"
- variables:
- DIR: 'PROJECT_DIR_ON_SERVER'
- PRODUCTION_STAGING: 'production'
- SSH: 'root@YOUR_SERVER_IP'
- DOCKER_TAG: 'latest'
Add Comment
Please, Sign In to add comment