Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # golang-devops-and-auto-deploy
- image: zacksleo/golang
- stages:
- - test
- - build
- - deploy
- variables:
- GOPATH: /root
- before_script:
- - mkdir -p ~/src/github.com/zacksleo/projectname
- - cp -r . ~/src/github.com/zacksleo/projectname
- - cd ~/src/github.com/zacksleo/projectname
- lint:
- stage: test
- script:
- - golint -set_exit_status
- unit-tests:
- stage: test
- services:
- - mysql:5.6
- variables:
- MYSQL_ROOT_PASSWORD: root
- MYSQL_DATABASE: web
- MYSQL_USER: web
- MYSQL_PASSWORD: web
- script:
- - dep ensure
- - cp tests/.env .env
- - migrate -database "mysql://web:web@tcp(mysql:3306)/web" -path "./db/migrations/" up
- - go test -tags=unit_tests $(go list ./... | grep -v /vendor/ ./tests/api) -v -coverprofile .testCoverage.txt
- coverage: '/^coverage:\s(\d+(?:\.\d+)?%)/'
- integration-tests:
- stage: test
- services:
- - mysql:5.6
- variables:
- MYSQL_ROOT_PASSWORD: root
- MYSQL_DATABASE: web
- MYSQL_USER: web
- MYSQL_PASSWORD: web
- script:
- - dep ensure
- - cp tests/.env .env
- - migrate -database "mysql://web:web@tcp(mysql:3306)/web" -path "./db/migrations/" up
- - go test -tags=integration $(go list ./tests/... | grep -v /vendor/) -v
- build-bin:
- stage: test
- script:
- - dep ensure
- - env GOOS=linux GOARCH=386 go build -o $CI_PROJECT_DIR/debug
- artifacts:
- expire_in: 60 mins
- untracked: true
- name: "app"
- paths:
- - debug
- when: on_success
- build-image:
- image: docker
- stage: build
- dependencies:
- - build-bin
- script:
- - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- - docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG .
- - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
- - docker rmi $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
- only:
- - tags
- tags:
- - go
- deploy:
- image: zacksleo/node
- stage: deploy
- before_script:
- - eval $(ssh-agent -s)
- - echo "$SSH_PRIVATE_KEY" > ~/deploy.key
- - chmod 0600 ~/deploy.key
- - ssh-add ~/deploy.key
- - mkdir -p ~/.ssh
- - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
- script:
- - cd deploy/production
- - rsync -rtvhze ssh . root@$DEPLOY_SERVER:/data/gitlab/projectname --stats
- - ssh root@$DEPLOY_SERVER "docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY"
- - 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"
- only:
- - tags
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement