This repository has been archived by the owner on Jul 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy path.gitlab-ci.yml
204 lines (184 loc) · 5.5 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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#
# kraken-tools Build File for GitLab
# This pipeline requires 11 variables to be set in the CI/CD Settings
#
# General Test Cluster Variables:
# SSH_KEY - base64 encoded ssh key for use with the test clusters (think ~/.ssh/id_rsa)
# SSH_PUBLIC_KEY - base64 encoded ssh public key for use with the test clusters (think ~/.ssh/id_rsa.pub)
#
# AWS Cluster Variables:
# AWS_CREDENTIALS - base64 encoded credentials file (think ~/.aws/credentials)
# AWS_CONFIG - base64 encoded config file (think ~/.aws/config)
#
# GKE Cluster Variables:
# GKE_CONFIG - base64 encoded json file (think ~/.config/gcloud/someconfig.json)
#
# Publish Variables:
# PUBLISH_REGISTRY - the registry you want to publish to (think quay.io)
# PUBLISH_USERNAME - the username for the registry
# PUBLISH_PASSWORD - the password for the registry
# PUBLISH_IMAGE - the image in the registry (organzation/namespace included, think samsung_cnct/kraken-tools)
#
# Cleanup Variables:
# DOCKER_USERNAME - the username that has delete privileges to the image registry
# DOCKER_PASSWORD - the password for the username that has delete privileges to the image regist
image: docker:latest
services:
- docker:dind
variables:
DOCKER_HOST: tcp://localhost:2375
DOCKER_DRIVER: overlay2
stages:
- build
- test
- publish
- cleanup
# build stage
build-branch:
stage: build
variables:
IMAGE_URI: $CI_REGISTRY_IMAGE:branch-$CI_COMMIT_REF_NAME-$CI_PIPELINE_ID
only:
- branches
before_script:
- docker info
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
script:
- docker build -t $IMAGE_URI .
- docker push $IMAGE_URI
build-tag:
stage: build
variables:
IMAGE_URI: $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
only:
- tags
before_script:
- docker info
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
script:
- docker build -t $IMAGE_URI .
- docker push $IMAGE_URI
# test
.aws-test: &aws_test_definition
stage: test
variables:
JOB_BASE_NAME: ${CI_PROJECT_NAME}
BUILD_ID: $CI_PIPELINE_ID
image: $IMAGE_URI
script:
- mkdir -p /root/.ssh /root/.aws
- echo $SSH_KEY | base64 -d > /root/.ssh/id_rsa
- chmod og-wrx /root/.ssh/id_rsa
- echo $SSH_PUBLIC_KEY | base64 -d > /root/.ssh/id_rsa.pub
- echo $AWS_CREDENTIALS | base64 -d > /root/.aws/credentials
- echo $AWS_CONFIG | base64 -d > /root/.aws/config
- /bin/bash -c /aws-testing.sh
.gke-test: &gke_test_definition
stage: test
variables:
JOB_BASE_NAME: ${CI_PROJECT_NAME}
BUILD_ID: $CI_PIPELINE_ID
image: $IMAGE_URI
script:
- mkdir -p /root/.ssh /root/.config/gcloud/
- echo $SSH_KEY | base64 -d > /root/.ssh/id_rsa
- chmod og-wrx /root/.ssh/id_rsa
- echo $SSH_PUBLIC_KEY | base64 -d > /root/.ssh/id_rsa.pub
- echo $GKE_CONFIG | base64 -d > /root/.config/gcloud/patrickRobot.json
- /bin/bash -c /gke-testing.sh
.test_cloud_template:
variables: &test_cloud_definition
JOB_BASE_NAME: ${CI_PROJECT_NAME}
BUILD_ID: $CI_PIPELINE_ID
test:aws-on-branch:
<<: *aws_test_definition
variables:
<<: *test_cloud_definition
IMAGE_URI: $CI_REGISTRY_IMAGE:branch-$CI_COMMIT_REF_NAME-$CI_PIPELINE_ID
only:
- branches
test:gke-on-branch:
<<: *gke_test_definition
variables:
<<: *test_cloud_definition
IMAGE_URI: $CI_REGISTRY_IMAGE:branch-$CI_COMMIT_REF_NAME-$CI_PIPELINE_ID
only:
- branches
test:aws-on-tags:
<<: *aws_test_definition
variables:
<<: *test_cloud_definition
IMAGE_URI: $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
only:
- tags
test:gke-on-tags:
<<: *gke_test_definition
variables:
<<: *test_cloud_definition
IMAGE_URI: $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
only:
- tags
# publish
publish-latest-master:
stage: publish
variables:
IMAGE_URI: $CI_REGISTRY_IMAGE:branch-$CI_COMMIT_REF_NAME-$CI_PIPELINE_ID
only:
- master
before_script:
- docker info
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker login -u $PUBLISH_USERNAME -p $PUBLISH_PASSWORD $PUBLISH_REGISTRY
script:
- docker pull $IMAGE_URI
- docker tag $IMAGE_URI ${PUBLISH_REGISTRY}/${PUBLISH_IMAGE}:latest
- docker push ${PUBLISH_REGISTRY}/${PUBLISH_IMAGE}:latest
publish-tagged-image:
stage: publish
only:
- /v[0-9]+\.[0-9]+(\.[0-9]+[a-z]?)?/
variables:
IMAGE_URI: $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
only:
- tags
before_script:
- docker info
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker login -u $PUBLISH_USERNAME -p $PUBLISH_PASSWORD $PUBLISH_REGISTRY
script:
- docker pull $IMAGE_URI
- docker tag $IMAGE_URI ${PUBLISH_REGISTRY}/${PUBLISH_IMAGE}:${CI_COMMIT_TAG}
- docker push ${PUBLISH_REGISTRY}/${PUBLISH_IMAGE}:${CI_COMMIT_TAG}
# cleanup test docker containers
cleanup-branch-image:
stage: cleanup
before_script:
- docker info
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
variables:
DOCKER_REGISTRY: $CI_REGISTRY
DOCKER_PROJECT: $CI_PROJECT_PATH
DOCKER_TAG: branch-$CI_COMMIT_REF_NAME-$CI_PIPELINE_ID
only:
- branches
when: always
allow_failure: true
image: registry.cnct.io/venezia/docker-registry-curl:v0.1.0
script:
- /entrypoint.sh
cleanup-tagged-image:
stage: cleanup
before_script:
- docker info
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
variables:
DOCKER_REGISTRY: $CI_REGISTRY
DOCKER_PROJECT: $CI_PROJECT_PATH
DOCKER_TAG: $CI_COMMIT_TAG
only:
- tags
when: always
allow_failure: true
image: registry.cnct.io/venezia/docker-registry-curl:v0.1.0
script:
- /entrypoint.sh