Advertisement
Guest User

Untitled

a guest
May 2nd, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. # golang-devops-and-auto-deploy
  2. image: zacksleo/golang
  3. stages:
  4. - test
  5. - build
  6. - deploy
  7.  
  8. variables:
  9. GOPATH: /root
  10.  
  11. before_script:
  12. - mkdir -p ~/src/github.com/zacksleo/projectname
  13. - cp -r . ~/src/github.com/zacksleo/projectname
  14. - cd ~/src/github.com/zacksleo/projectname
  15. lint:
  16. stage: test
  17. script:
  18. - golint -set_exit_status
  19. unit-tests:
  20. stage: test
  21. services:
  22. - mysql:5.6
  23. variables:
  24. MYSQL_ROOT_PASSWORD: root
  25. MYSQL_DATABASE: web
  26. MYSQL_USER: web
  27. MYSQL_PASSWORD: web
  28. script:
  29. - dep ensure
  30. - cp tests/.env .env
  31. - migrate -database "mysql://web:web@tcp(mysql:3306)/web" -path "./db/migrations/" up
  32. - go test -tags=unit_tests $(go list ./... | grep -v /vendor/ ./tests/api) -v -coverprofile .testCoverage.txt
  33. coverage: '/^coverage:\s(\d+(?:\.\d+)?%)/'
  34. integration-tests:
  35. stage: test
  36. services:
  37. - mysql:5.6
  38. variables:
  39. MYSQL_ROOT_PASSWORD: root
  40. MYSQL_DATABASE: web
  41. MYSQL_USER: web
  42. MYSQL_PASSWORD: web
  43. script:
  44. - dep ensure
  45. - cp tests/.env .env
  46. - migrate -database "mysql://web:web@tcp(mysql:3306)/web" -path "./db/migrations/" up
  47. - go test -tags=integration $(go list ./tests/... | grep -v /vendor/) -v
  48. build-bin:
  49. stage: test
  50. script:
  51. - dep ensure
  52. - env GOOS=linux GOARCH=386 go build -o $CI_PROJECT_DIR/debug
  53. artifacts:
  54. expire_in: 60 mins
  55. untracked: true
  56. name: "app"
  57. paths:
  58. - debug
  59. when: on_success
  60. build-image:
  61. image: docker
  62. stage: build
  63. dependencies:
  64. - build-bin
  65. script:
  66. - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
  67. - docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG .
  68. - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
  69. - docker rmi $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
  70. only:
  71. - tags
  72. tags:
  73. - go
  74. deploy:
  75. image: zacksleo/node
  76. stage: deploy
  77. before_script:
  78. - eval $(ssh-agent -s)
  79. - echo "$SSH_PRIVATE_KEY" > ~/deploy.key
  80. - chmod 0600 ~/deploy.key
  81. - ssh-add ~/deploy.key
  82. - mkdir -p ~/.ssh
  83. - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
  84. script:
  85. - cd deploy/production
  86. - rsync -rtvhze ssh . root@$DEPLOY_SERVER:/data/gitlab/projectname --stats
  87. - ssh root@$DEPLOY_SERVER "docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY"
  88. - ssh root@$DEPLOY_SERVER "cd /data/gitlab/projectname && echo -e '\nTAG=$CI_COMMIT_TAG' >> .env && docker-compose pull app && docker-compose stop app && docker-compose rm -f app && docker-compose up -d app"
  89. only:
  90. - tags
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement