Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- image: docker:latest
- stages:
- - build
- - tag_push
- - testing
- - cleanup
- - deploy
- variables:
- IMAGE: $CI_REGISTRY_IMAGE:$CI_BUILD_REF_SLUG
- TAG: $CI_COMMIT_TAG
- before_script:
- - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY
- build:
- stage: build
- script:
- - docker image build --pull -t $IMAGE .
- - docker push $IMAGE
- only:
- - branches
- pytest:
- before_script: []
- stage: testing
- image: $IMAGE
- script:
- - python3 -m pytest
- only:
- - branches
- tag_push:
- stage: tag_push
- script:
- - docker image build --pull -t $CI_REGISTRY_IMAGE .
- - docker image tag $CI_REGISTRY_IMAGE $CI_REGISTRY_IMAGE:$TAG
- - docker push $CI_REGISTRY_IMAGE:$TAG
- only:
- - tags
- .deploy-template: &deploy-definition
- stage: deploy
- image: ********
- before_script:
- - which ssh-agent || ( apk --update add openssh-client )
- - mkdir -p ~/.ssh
- - echo "$DEPLOYMENT_SIGNATURE" | tr -d '\r' > ~/.ssh/id_rsa
- - chmod 600 ~/.ssh/id_rsa
- - eval $(ssh-agent -s)
- - ssh-add ~/.ssh/id_rsa
- - sed -i "s/# Host */Host */g" /etc/ssh/ssh_config
- - sed -i "s/# ForwardAgent no/ForwardAgent yes/g" /etc/ssh/ssh_config
- deploy-api:
- <<: *deploy-definition
- script:
- - ansible-playbook /deploy/api_retail.yml -i /deploy/production.ini --extra-vars "service_user_login=$SERVICE_USER_LOGIN service_user_pass=$SERVICE_USER_PASS MONGO_PASSWORD=$MONGO_PASSWORD MONGO_USERNAME=$MONGO_USERNAME repo_tag=$TAG ansible_sudo_pass=$ANSIBLE_PASS"
- when: manual
- only:
- - tags
- test-deploy:
- <<: *deploy-definition
- image: ********
- script:
- - ansible-playbook /deploy/test_deploy_retail.yml -i /deploy/test.ini --extra-vars "service_user_login=$SERVICE_USER_LOGIN service_user_pass=$SERVICE_USER_PASS MONGO_PASSWORD=$MONGO_PASSWORD MONGO_USERNAME=$MONGO_USERNAME ansible_sudo_pass=$ANSIBLE_PASS"
- when: manual
- only:
- - branches
- clean:
- stage: cleanup
- script:
- docker image rm -f $(docker image inspect -f '{{.Id}}' "$IMAGE")
- when: always
- only:
- - branches
- clean-tag-image:
- stage: cleanup
- script:
- docker image rm -f $(docker image inspect -f '{{.Id}}' "$CI_REGISTRY_IMAGE:$TAG")
- when: always
- only:
- - tags
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement