-
Notifications
You must be signed in to change notification settings - Fork 1
/
.gitlab-ci.yml
109 lines (104 loc) · 2.96 KB
/
.gitlab-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
stages:
- test
- build
- deploy
Test core:
stage: test
only:
refs:
- merge_requests
changes:
- core/**/*
services:
- postgres:10.4-alpine
- influxdb:1.5.2-alpine
image: registry.gitlab.com/bitreport/bitreport/python3.7-core
variables:
INFLUX_HOST: influxdb
POSTGRES_HOST: postgres
script:
- python3 -m venv venv
- . venv/bin/activate
- pip install --upgrade pip
- pip install -r core/requirements.txt
- pytest --cov=core/app --cov-config core/.coveragerc
cache:
key: core-packages
paths:
- venv/
Test dashboard:
stage: test
only:
refs:
- merge_requests
changes:
- dashboard/**/*
services:
- postgres:10.4-alpine
image: registry.gitlab.com/bitreport/bitreport/ruby2.6-dashboard
variables:
RAILS_ENV: test
POSTGRES_DB: dashboard_test
POSTGRES_USER: postgres
POSTGRES_PASSWORD: ""
script:
- cd dashboard
- bundle install --path vendor/bundle
- bundle exec rails db:create db:migrate:with_data
- bundle exec rspec --format documentation --no-profile
cache:
key: dashboard-gems
paths:
- dashboard/vendor/bundle/
Do nothing xD:
stage: test
image: alpine:3.7
variables:
GIT_STRATEGY: none
except:
refs:
- merge_requests
changes:
- dashboard/**/*
- core/**/*
script:
- echo "(っ◕‿◕)っ"
Update docker registry:
stage: build
only:
refs:
- master
image: tmaier/docker-compose:latest
variables:
COMPOSE_FILE: docker-compose.production.yml
DOCKER_DRIVER: overlay2
services:
- docker:dind
before_script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker-compose pull -q --ignore-pull-failures core dashboard web 2>&1 | (grep -oh "\w*:[0-9a-zA-Z-]* not found" || true) | awk -F ':' '{print $1}' | while read -r service; do echo "${service}:${CI_COMMIT_REF_NAME} doesn't exist yet" && (docker pull ${CI_REGISTRY_IMAGE}/${service}:master > /dev/null && docker tag ${CI_REGISTRY_IMAGE}/${service}:master ${CI_REGISTRY_IMAGE}/${service}:${CI_COMMIT_REF_NAME} && docker push ${CI_REGISTRY_IMAGE}/${service}:${CI_COMMIT_REF_NAME} || true); done
- docker images
script:
- docker-compose build core dashboard web
- docker-compose push
Deploy to production:
stage: deploy
only:
refs:
- master
tags:
- deploy
environment:
name: production
url: https://bitreport.org
before_script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
script:
- docker stack deploy -c docker-compose.production.yml --with-registry-auth bitreport
- sleep 10
- docker exec $(docker ps -q -f name=dashboard) bundle exec rails db:migrate:with_data
- docker exec $(docker ps -q -f name=core) flask db migrate
- docker exec $(docker ps -q -f name=core) flask db upgrade
- docker exec $(docker ps -q -f name=dashboard) bundle exec rails assets:precompile
after_script:
- docker image prune -f