-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
186 lines (176 loc) · 6.32 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
variables:
CONTAINER_IMAGE: gdr.abyle.org/$CI_PROJECT_PATH
stages:
- build
- test
- build_static
- build_image
- container_scanning
- release
- deploy
#before_script:
#- mkdir -p /go/src/github.com/torlenor
#- ln -s $CI_PROJECT_DIR /go/src/git.abyle.org/hps/alolstats
#- cd /go/src/git.abyle.org/hps/alolstats
build:
image: golang:1.12
stage: build
script:
- make
unit_tests:
image: golang:1.12
stage: test
services:
- mongo:latest
script:
- make test
- go tool cover -func coverage.out
build_static:
image: golang:1.12
stage: build_static
artifacts:
expire_in: 1 week
paths:
- ./bin/
script:
- make build-static
create_docker_image:
stage: build_image
dependencies:
- build_static
tags:
- docker-from-docker
script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN gdr.abyle.org
- docker pull $CONTAINER_IMAGE:latest || true
- docker build --cache-from $CONTAINER_IMAGE:latest --tag $CONTAINER_IMAGE:$CI_COMMIT_SHA .
- docker push $CONTAINER_IMAGE:$CI_COMMIT_SHA
# container_scanning:
# image: docker:stable
# stage: container_scanning
# dependencies:
# - create_docker_image
# tags:
# - docker-in-docker
# variables:
# DOCKER_DRIVER: overlay2
# ## Define two new variables based on GitLab's CI/CD predefined variables
# ## https://docs.gitlab.com/ee/ci/variables/#predefined-variables-environment-variables
# CI_APPLICATION_REPOSITORY: $CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG
# CI_APPLICATION_TAG: $CI_COMMIT_SHA
# allow_failure: true
# services:
# - docker:stable-dind
# script:
# - docker run -d --name db arminc/clair-db:latest
# - docker run -p 6060:6060 --link db:postgres -d --name clair --restart on-failure arminc/clair-local-scan:v2.0.1
# - apk add -U wget ca-certificates
# - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN gdr.abyle.org
# - docker pull $CONTAINER_IMAGE:$CI_COMMIT_SHA
# - wget https://github.com/arminc/clair-scanner/releases/download/v8/clair-scanner_linux_amd64
# - mv clair-scanner_linux_amd64 clair-scanner
# - chmod +x clair-scanner
# - touch clair-whitelist.yml
# - while( ! wget -q -O /dev/null http://docker:6060/v1/namespaces ) ; do sleep 1 ; done
# - retries=0
# - echo "Waiting for clair daemon to start"
# - while( ! wget -T 10 -q -O /dev/null http://docker:6060/v1/namespaces ) ; do sleep 1 ; echo -n "." ; if [ $retries -eq 10 ] ; then echo " Timeout, aborting." ; exit 1 ; fi ; retries=$(($retries+1)) ; done
# - ./clair-scanner -c http://docker:6060 --ip $(hostname -i) -r gl-container-scanning-report.json -l clair.log -w clair-whitelist.yml $CONTAINER_IMAGE:$CI_COMMIT_SHA || true
# - cat gl-container-scanning-report.json
# artifacts:
# reports:
# container_scanning: gl-container-scanning-report.json
# deploy_testing:
# stage: deploy
# dependencies:
# - create_docker_image
# image: gdr.abyle.org/abyle/dockerfiles/abyle-acicddeploy:latest
# environment: testing
# before_script:
# - mkdir -p "${HOME}/.ssh/"
# - echo "${SSH_PRIVATE_KEY}" > "${HOME}/.ssh/id_rsa"
# - chmod 700 "${HOME}/.ssh/id_rsa"
# - echo "$SSH_KNOWN_HOSTS" > "${HOME}/.ssh/known_hosts"
# - chmod 644 "${HOME}/.ssh/known_hosts"
# only:
# - master
# script:
# - echo deploying to testing environment... $CONTAINER_IMAGE:$CI_COMMIT_SHA
# - export TRANSACTIONID=`uuidgen`
# - mkdir ${CICD_TOKEN}
# - >
# echo "{
# \"cicdToken\": \"${CICD_TOKEN}\",
# \"transactionId\": \"${TRANSACTIONID}\",
# \"target\": {
# \"type\": \"PortainerStackTarget\",
# \"stackName\": \"alolstatsdev\",
# \"portainerEndpointId\": 1,
# \"serviceName\": \"alolstats_dev.docker.abyle.org\",
# \"serviceAttributes\": {
# \"image\": \"$CONTAINER_IMAGE:$CI_COMMIT_SHA\"
# }
# }
# }" > "${CICD_TOKEN}"/job.cicd.json
# - scp -r "${CICD_TOKEN}"/ "${SSH_USER}@${SSH_HOST}:${SSH_REMOTE_ACICD_BASE_PATH}/incoming"
# - export OUTPUT=`ssh ${SSH_USER}@${SSH_HOST} -C "acicdstatus.py -f ${SSH_REMOTE_ACICD_BASE_PATH}/status/${TRANSACTIONID}.json"`
# - export EXITCODE=`echo ${OUTPUT} | jq .shellExitCode`
# - echo ${OUTPUT} | jq
# - test -n "$EXITCODE" && exit $EXITCODE
release:
stage: release
dependencies:
- create_docker_image
tags:
- docker-from-docker
script:
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN gdr.abyle.org
- docker pull $CONTAINER_IMAGE:$CI_COMMIT_SHA
- docker tag $CONTAINER_IMAGE:$CI_COMMIT_SHA $CONTAINER_IMAGE:$CI_COMMIT_TAG
- docker tag $CONTAINER_IMAGE:$CI_COMMIT_SHA $CONTAINER_IMAGE:latest
- docker push $CONTAINER_IMAGE:$CI_COMMIT_TAG
- docker push $CONTAINER_IMAGE:latest
only:
- tags
except:
- branches
# deploy_production:
# stage: deploy
# dependencies:
# - release
# image: gdr.abyle.org/abyle/dockerfiles/abyle-acicddeploy:latest
# environment: production
# before_script:
# - mkdir -p "${HOME}/.ssh/"
# - echo "${SSH_PRIVATE_KEY}" > "${HOME}/.ssh/id_rsa"
# - chmod 700 "${HOME}/.ssh/id_rsa"
# - echo "$SSH_KNOWN_HOSTS" > "${HOME}/.ssh/known_hosts"
# - chmod 644 "${HOME}/.ssh/known_hosts"
# script:
# - echo deploying to production environment... $CONTAINER_IMAGE:$CI_COMMIT_TAG
# - export TRANSACTIONID=`uuidgen`
# - mkdir ${CICD_TOKEN}
# - >
# echo "{
# \"cicdToken\": \"${CICD_TOKEN}\",
# \"transactionId\": \"${TRANSACTIONID}\",
# \"target\": {
# \"type\": \"PortainerStackTarget\",
# \"stackName\": \"alolstats\",
# \"portainerEndpointId\": 1,
# \"serviceName\": \"alolstats.docker.abyle.org\",
# \"serviceAttributes\": {
# \"image\": \"$CONTAINER_IMAGE:$CI_COMMIT_TAG\"
# }
# }
# }" > "${CICD_TOKEN}"/job.cicd.json
# - scp -r "${CICD_TOKEN}"/ "${SSH_USER}@${SSH_HOST}:${SSH_REMOTE_ACICD_BASE_PATH}/incoming"
# - export OUTPUT=`ssh ${SSH_USER}@${SSH_HOST} -C "acicdstatus.py -f ${SSH_REMOTE_ACICD_BASE_PATH}/status/${TRANSACTIONID}.json"`
# - export EXITCODE=`echo ${OUTPUT} | jq .shellExitCode`
# - echo ${OUTPUT} | jq
# - test -n "$EXITCODE" && exit $EXITCODE
# only:
# - tags
# except:
# - branches
# when: manual