-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.gitlab-ci.yml
More file actions
136 lines (124 loc) · 2.67 KB
/
.gitlab-ci.yml
File metadata and controls
136 lines (124 loc) · 2.67 KB
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
#
# before setup this CI, don't forget to add at ssh's host into /etc/ssh/sshd_config file this:
# ------
# AcceptEnv CI_*
# ------
# and restart sshd
#
image: docker:stable
stages:
- test
- build
- push
- deploy
variables:
DOCKER_DRIVER: overlay2
DOCKER_HOST: unix:///var/run/docker.sock
CI_DEV_API_PATH: /data/joinimpact/api
.job_template: &push_def
script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
.job_template: &deploy_via_ssh_def
script:
- apk add --no-cache openssh-client
- printf $SSH_KEY | base64 -d > /tmp/dev_ssh_key
- chmod 400 /tmp/dev_ssh_key
- printf "bash -x -c
'cd $CI_DEV_API_PATH
&& git checkout $CI_COMMIT_REF_NAME
&& git pull origin $CI_COMMIT_REF_NAME
&& docker-compose stop --timeout 90
$CI_PROJECT_NAME
&& docker-compose pull --parallel -q
$CI_PROJECT_NAME
&& docker-compose up --no-start
$CI_PROJECT_NAME
&& docker-compose start
$CI_PROJECT_NAME
'"
| ssh -T
-o SendEnv="CI_*"
-o StrictHostKeyChecking=no
-o ConnectTimeout=30
-o BatchMode=yes
-i /tmp/dev_ssh_key
$SSH_USER@$SSH_HOST
-p $SSH_PORT
test:
stage: test
allow_failure: true
image: golang:1.14-buster
script:
- go get -u golang.org/x/lint/golint
- make lint
build:
stage: build
allow_failure: false
script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker build . --pull -f Dockerfile -t $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
- env
push:
stage: push
allow_failure: false
<<: *push_def
only:
- master
- /^r-.*$/
push-branch:
stage: push
<<: *push_def
except:
refs:
- master
- tags
when: manual
push-tag:
stage: push
allow_failure: false
<<: *push_def
only:
refs:
- tags
variables:
- $PUSH_TAGS
deploy-dev:
stage: deploy
allow_failure: false
<<: *deploy_via_ssh_def
variables:
SSH_KEY: $DEV_SSH_KEY
SSH_USER: $DEV_SSH_USER
SSH_HOST: $DEV_SSH_HOST
SSH_PORT: $DEV_SSH_PORT
environment:
name: dev
url: https://dev.joinimpact.org/
only:
- master
except:
variables:
- $SKIP_DEPLOY
- $SKIP_DEPLOY_DEV
deploy-dev-manual:
stage: deploy
<<: *deploy_via_ssh_def
variables:
SSH_KEY: $DEV_SSH_KEY
SSH_USER: $DEV_SSH_USER
SSH_HOST: $DEV_SSH_HOST
SSH_PORT: $DEV_SSH_PORT
dependencies:
- push-branch
environment:
name: dev-manual
url: https://dev.joinimpact.org/
except:
refs:
- master
- tags
variables:
- $SKIP_DEPLOY
- $SKIP_DEPLOY_DEV
when: manual