-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
156 lines (145 loc) · 4.52 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
152
153
154
155
156
image: node:8-alpine
# This are NOT jobs and it will be ignored by GitLab-CI
.login_gitlab_registry: &login # This is an anchor
docker login registry.gitlab.com -u ${GITLAB_REGISTRY_USER} -p ${GITLAB_REGISTRY_PASS}
.install_dependencies: &install_dependencies
apk add --no-cache bash curl gawk git sed util-linux pciutils usbutils coreutils binutils findutils grep
.generate_env_file: &generate_env_file
cp environment/.prod.env .env
.build_push_gitlab: &build_push
- ./scripts/generate_docker_image.sh registry.gitlab.com/intellidrone/api_new ${custom_tag} ${CI_COMMIT_SHA}
- docker push registry.gitlab.com/intellidrone/api_new:${custom_tag}
cache:
paths:
- node_modules/
- .env
stages:
- build
- test
- deploy
build:
stage: build
before_script:
- apk add --no-cache python make gcc g++
script:
#- npm install
- echo "skip building"
test:
services:
- mongo:4.0
stage: test
script:
- echo test
deploy-server-master:
stage: deploy
before_script:
- 'which ssh-agent || ( apk add --update openssh )'
- apk add --update bash
- apk add --update git
- mkdir -p ~/.ssh
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/robotagro
- chmod 700 ~/.ssh/robotagro
- eval "$(ssh-agent -s)"
- ssh-add ~/.ssh/robotagro
- ssh-keyscan -H 'gitlab.com' >> ~/.ssh/known_hosts
# For Docker builds disable host key checking. Be aware that by adding that
# you are suspectible to man-in-the-middle attacks.
# WARNING: Use this only with the Docker executor, if you use it with shell
# you will overwrite your user's SSH config.
#- mkdir -p ~/.ssh
#- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
# In order to properly check the server's host key, assuming you created the
# SSH_SERVER_HOSTKEYS variable previously, uncomment the following two lines
# instead.
# - mkdir -p ~/.ssh
# - '[[ -f /.dockerenv ]] && echo "$SSH_SERVER_HOSTKEYS" > ~/.ssh/known_hosts'
script:
- npm i -g pm2
- pm2 deploy ecosystem.config.js production --node-args="--env=production"
when: on_success
only:
- master
deploy-server-develop:
stage: deploy
before_script:
- 'which ssh-agent || ( apk add --update openssh )'
- apk add --update bash
- apk add --update git
- mkdir -p ~/.ssh
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/robotagro
- chmod 700 ~/.ssh/robotagro
- eval "$(ssh-agent -s)"
- ssh-add ~/.ssh/robotagro
- ssh-keyscan -H 'gitlab.com' >> ~/.ssh/known_hosts
# For Docker builds disable host key checking. Be aware that by adding that
# you are suspectible to man-in-the-middle attacks.
# WARNING: Use this only with the Docker executor, if you use it with shell
# you will overwrite your user's SSH config.
#- mkdir -p ~/.ssh
#- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
# In order to properly check the server's host key, assuming you created the
# SSH_SERVER_HOSTKEYS variable previously, uncomment the following two lines
# instead.
# - mkdir -p ~/.ssh
# - '[[ -f /.dockerenv ]] && echo "$SSH_SERVER_HOSTKEYS" > ~/.ssh/known_hosts'
script:
- npm i -g pm2
- pm2 deploy ecosystem.config.js development --node-args="--env=development"
when: on_success
only:
- develop
deploy-image-develop:
image: docker:latest
services:
- docker:dind
variables:
DOCKER_DRIVER: overlay
custom_tag: '${CI_COMMIT_REF_NAME}'
stage: deploy
dependencies:
- build
before_script:
- *login # This is a reference to the anchor.
- apk add --update bash git
script:
*build_push # This is a reference to the anchor.
when: on_success
only:
- develop
deploy-image-master:
image: docker:latest
services:
- docker:dind
# Use the OverlayFS driver for improved performance.
variables:
DOCKER_DRIVER: overlay
custom_tag: 'latest'
stage: deploy
dependencies:
- build
before_script:
- *login # This is a reference to the anchor.
- *install_dependencies
script:
*build_push # This is a reference to the anchor.
when: on_success
only:
- master
deploy-image-tag:
image: docker:latest
services:
- docker:dind
variables:
DOCKER_DRIVER: overlay
custom_tag: '${CI_COMMIT_TAG}'
stage: deploy
dependencies:
- build
before_script:
- *login # This is a reference to the anchor.
- *install_dependencies
script:
*build_push # This is a reference to the anchor.
when: on_success
only:
- tags