-
Notifications
You must be signed in to change notification settings - Fork 4
/
.gitlab-ci.yml
144 lines (131 loc) · 4.47 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
image: tmaier/docker-compose:19.03
services:
- docker:19.03-dind
stages:
- build
- static analysis
- test
- clean-up
- deploy
variables:
DOCKER_HOST: tcp://docker:2375/
# Use the overlayfs driver for improved performance.
DOCKER_DRIVER: overlay2
# Disable TLS since we're running inside local network.
DOCKER_TLS_CERTDIR: ""
# Use Docker BuildKit for better caching and faster builds
DOCKER_BUILDKIT: 1
BUILDKIT_INLINE_CACHE: 1
COMPOSE_DOCKER_CLI_BUILD: 1
# Test images
CLIENT_IMAGE: $CI_REGISTRY_IMAGE/client:$CI_COMMIT_SHORT_SHA
SERVER_IMAGE: $CI_REGISTRY_IMAGE/server:$CI_COMMIT_SHORT_SHA
# Jobs:
build-main:
stage: build
only: [main]
before_script:
- chmod u+x wait.sh && ./wait.sh
- docker login -u $CI_REGISTRY_USER -p $CI_JOB_TOKEN $CI_REGISTRY
script:
- docker-compose --env-file .env.development build --parallel
- docker-compose --env-file .env.development push
build:
stage: build
except: [main]
before_script:
- chmod u+x wait.sh && ./wait.sh
- docker login -u $CI_REGISTRY_USER -p $CI_JOB_TOKEN $CI_REGISTRY
script:
- docker-compose --env-file .env.ci build --parallel
- docker-compose --env-file .env.ci push
analysis-client:
stage: static analysis
except: [main]
needs: [build]
before_script:
- apk add --no-cache bash
- chmod u+x wait.sh && ./wait.sh
- docker login -u $CI_REGISTRY_USER -p $CI_JOB_TOKEN $CI_REGISTRY
script:
- docker run $CLIENT_IMAGE npx eslint .
- echo "Static analysis on the client passed!"
allow_failure: true
analysis-server:
stage: static analysis
except: [main]
needs: [build]
before_script:
- apk add --no-cache bash
- chmod u+x wait.sh && ./wait.sh
- docker login -u $CI_REGISTRY_USER -p $CI_JOB_TOKEN $CI_REGISTRY
script:
- docker run $SERVER_IMAGE flake8 --max-line-length 99 --statistics .
- echo "Static analysis on the server passed!"
allow_failure: true
test-client:
stage: test
except: [main]
needs: [analysis-client]
before_script:
- apk add --no-cache bash
- chmod u+x wait.sh && ./wait.sh
- docker login -u $CI_REGISTRY_USER -p $CI_JOB_TOKEN $CI_REGISTRY
script:
- docker run $CLIENT_IMAGE npm test
- echo "Tests on the client passed!"
allow_failure: true
test-server:
stage: test
except: [main]
needs: [analysis-server]
before_script:
- apk add --no-cache bash
- chmod u+x wait.sh && ./wait.sh
- docker info
- docker login -u $CI_REGISTRY_USER -p $CI_JOB_TOKEN $CI_REGISTRY
script:
- docker-compose --env-file .env.ci up --build -d
- docker exec backend coverage run manage.py test
- docker exec backend coverage report
- echo "Tests on the server passed!"
allow_failure: true
clean-up:
stage: clean-up
except: [main]
needs: [build, test-client, test-server]
variables:
SERVER_IMAGE: $CI_PROJECT_PATH/server:$CI_COMMIT_SHORT_SHA
CLIENT_IMAGE: $CI_PROJECT_PATH/client:$CI_COMMIT_SHORT_SHA
REG_URL: "https://github.com/genuinetools/reg/releases/download/v$REG_VERSION/reg-linux-amd64"
REG_SHA256: ade837fc5224acd8c34732bf54a94f579b47851cc6a7fd5899a98386b782e228
REG_VERSION: 0.16.1
before_script:
- apk add --no-cache bash
- apk add --no-cache curl
- chmod u+x wait.sh && ./wait.sh
- curl --fail --show-error --location $REG_URL --output /usr/local/bin/reg
- echo "$REG_SHA256 /usr/local/bin/reg" | sha256sum -c -
- chmod a+x /usr/local/bin/reg
script:
- /usr/local/bin/reg rm -d --auth-url $CI_REGISTRY -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $SERVER_IMAGE
- /usr/local/bin/reg rm -d --auth-url $CI_REGISTRY -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CLIENT_IMAGE
- echo "Test images deleted from the registry!"
push-container:
stage: deploy
only: [main]
needs: [build-main]
variables:
# Production registry
DIGITAL_OCEAN_REGISTRY: registry.digitalocean.com
DIGITAL_OCEAN_REPOSITORY: ebook-fixer
before_script:
- apk add --no-cache curl
- chmod u+x wait.sh && ./wait.sh
- docker info
script:
- docker login -u $DIGITAL_OCEAN_TOKEN -p $DIGITAL_OCEAN_TOKEN $DIGITAL_OCEAN_REGISTRY
- docker build -t $DIGITAL_OCEAN_REGISTRY/$DIGITAL_OCEAN_REPOSITORY/server:latest server/
- docker push $DIGITAL_OCEAN_REGISTRY/$DIGITAL_OCEAN_REPOSITORY/server:latest
- sleep 20
- "curl -X POST -H \"Content-Type: application/json\" -H \"Authorization: Bearer $DIGITAL_OCEAN_TOKEN\" \"https://api.digitalocean.com/v2/registry/$DIGITAL_OCEAN_REPOSITORY/garbage-collection\""