Advertisement
Guest User

gitlab-ci example

a guest
Feb 13th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 2.23 KB | None | 0 0
  1. image: docker:latest
  2.  
  3. stages:
  4.  - build
  5.   - tag_push
  6.   - testing
  7.   - cleanup
  8.   - deploy
  9.  
  10. variables:
  11.   IMAGE: $CI_REGISTRY_IMAGE:$CI_BUILD_REF_SLUG
  12.   TAG: $CI_COMMIT_TAG
  13.  
  14. before_script:
  15.    - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY
  16.  
  17. build:
  18.   stage: build
  19.   script:
  20.    - docker image build --pull -t $IMAGE .
  21.     - docker push $IMAGE
  22.   only:
  23.    - branches
  24.  
  25. pytest:
  26.   before_script: []
  27.   stage: testing
  28.   image: $IMAGE
  29.   script:
  30.    - python3 -m pytest
  31.   only:
  32.    - branches
  33.    
  34. tag_push:
  35.   stage: tag_push
  36.   script:
  37.    - docker image build --pull -t $CI_REGISTRY_IMAGE .
  38.     - docker image tag $CI_REGISTRY_IMAGE $CI_REGISTRY_IMAGE:$TAG
  39.     - docker push $CI_REGISTRY_IMAGE:$TAG
  40.   only:
  41.    - tags
  42.  
  43. .deploy-template: &deploy-definition
  44.   stage: deploy
  45.   image: ********
  46.   before_script:
  47.    - which ssh-agent || ( apk --update add openssh-client )
  48.     - mkdir -p ~/.ssh
  49.     - echo "$DEPLOYMENT_SIGNATURE" | tr -d '\r' > ~/.ssh/id_rsa
  50.     - chmod 600 ~/.ssh/id_rsa
  51.     - eval $(ssh-agent -s)
  52.     - ssh-add ~/.ssh/id_rsa
  53.     - sed -i "s/# Host */Host */g" /etc/ssh/ssh_config
  54.     - sed -i "s/#   ForwardAgent no/ForwardAgent yes/g" /etc/ssh/ssh_config
  55.  
  56. deploy-api:
  57.   <<: *deploy-definition
  58.   script:
  59.    - 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"
  60.   when: manual
  61.   only:
  62.    - tags
  63.  
  64. test-deploy:
  65.   <<: *deploy-definition
  66.   image: ********
  67.   script:
  68.    - 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"
  69.   when: manual
  70.   only:
  71.    - branches
  72.  
  73. clean:
  74.   stage: cleanup
  75.   script:
  76.    docker image rm -f $(docker image inspect -f '{{.Id}}' "$IMAGE")
  77.   when: always
  78.   only:
  79.    - branches
  80.  
  81. clean-tag-image:
  82.   stage: cleanup
  83.   script:
  84.    docker image rm -f $(docker image inspect -f '{{.Id}}' "$CI_REGISTRY_IMAGE:$TAG")
  85.   when: always
  86.   only:
  87.    - tags
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement