-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
151 lines (139 loc) · 3.82 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
145
146
147
148
149
150
151
image: $CI_REGISTRY/softformance/lab/docker-builds:19.03-compose
services:
- docker:19-dind
variables:
DOCKER_HOST: tcp://docker:2375/
DOCKER_DRIVER: overlay2
DOCKER_BUILDKIT: 1
COMPOSE_DOCKER_CLI_BUILD: 1
STACK_PREFIX: "spacebeaver"
before_script:
- docker-compose --version
- echo -n $CI_JOB_TOKEN | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY
stages:
- setup
- test
- compile
- build
- deploy
setup:
stage: setup
script:
- echo ${NODE_MODULES}
only:
- develop
- master
test:
stage: test
coverage: '/TOTAL.+ ([0-9]{1,3}%)/'
script:
- echo $(ls -a)
- echo $(pwd)
- docker pull $CI_REGISTRY_IMAGE:ci || true
- docker-compose -f compose/ci.yml -p $STACK_PREFIX up -d
- docker-compose -f compose/ci.yml -p $STACK_PREFIX exec -T -w /app app make test
- docker-compose -f compose/ci.yml -p $STACK_PREFIX down
only:
- develop
- master
compile-staging:
stage: compile
script:
- docker pull $CI_REGISTRY_IMAGE:staging || true
- docker-compose -f compose/ci.yml -p $STACK_PREFIX up -d
- docker-compose -f compose/ci.yml -p $STACK_PREFIX down -v
environment:
name: staging
only:
- develop
dependencies:
- test
artifacts:
paths:
- src/static/dist
expire_in: 1 week
compile-production:
stage: compile
script:
- docker pull $CI_REGISTRY_IMAGE:production || true
- docker-compose -f compose/ci.yml -p $STACK_PREFIX up -d
- docker-compose -f compose/ci.yml -p $STACK_PREFIX down -v
environment:
name: production
only:
- master
dependencies:
- test
artifacts:
paths:
- src/static/dist
expire_in: 1 week
build-staging:
stage: build
script:
- docker pull $CI_REGISTRY_IMAGE:staging || true
- docker-compose -f compose/staging.yml -p $STACK_PREFIX build app
- docker-compose -f compose/staging.yml -p $STACK_PREFIX push app
environment:
name: staging
only:
- develop
dependencies:
- compile-staging
build-production:
stage: build
script:
- docker pull $CI_REGISTRY_IMAGE:production || true
- docker-compose -f compose/production.yml -p $STACK_PREFIX build app
- docker-compose -f compose/production.yml -p $STACK_PREFIX push app
environment:
name: production
only:
- master
dependencies:
- compile-production
deploy-staging:
stage: deploy
before_script:
- docker-compose --version
- echo -n $CI_JOB_TOKEN | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY
# https://docs.gitlab.com/ee/ci/ssh_keys/
- 'command -v ssh-agent >/dev/null || ( apk update && apk add openssh-client )'
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan $HOST >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
script:
- docker -H=ssh://root@$HOST stack deploy -c compose/staging.yml --prune --with-registry-auth $STACK_PREFIX
- docker logout $CI_REGISTRY
environment:
name: staging
only:
- develop
dependencies:
- build-staging
deploy-production:
stage: deploy
before_script:
- docker-compose --version
- echo -n $CI_JOB_TOKEN | docker login -u $CI_REGISTRY_USER --password-stdin $CI_REGISTRY
# https://docs.gitlab.com/ee/ci/ssh_keys/
- 'command -v ssh-agent >/dev/null || ( apk update && apk add openssh-client )'
- eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' | ssh-add -
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- ssh-keyscan $HOST >> ~/.ssh/known_hosts
- chmod 644 ~/.ssh/known_hosts
script:
- docker -H=ssh://root@$HOST stack deploy -c compose/production.yml --prune --with-registry-auth $STACK_PREFIX
- docker logout $CI_REGISTRY
environment:
name: production
when: manual
only:
- master
dependencies:
- build-production