-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
163 lines (150 loc) · 5.1 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
stages:
- build
- test
- deploy
variables:
CORRECT_OUTPUT: "Hello, world!"
# nginx
nginx:build:
stage: build
image: docker
services:
- docker:dind
variables:
DOCKER_HOST: "tcp://docker:2375"
IMAGE_TAG_BASE: $CI_REGISTRY_IMAGE/nginx
script:
- cd nginx
- docker build . -t $IMAGE_TAG_BASE:$CI_COMMIT_SHORT_SHA
- docker tag $IMAGE_TAG_BASE:$CI_COMMIT_SHORT_SHA $IMAGE_TAG_BASE:$CI_PIPELINE_ID
- docker tag $IMAGE_TAG_BASE:$CI_COMMIT_SHORT_SHA $IMAGE_TAG_BASE:latest
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker push $IMAGE_TAG_BASE:$CI_COMMIT_SHORT_SHA
- docker push $IMAGE_TAG_BASE:$CI_PIPELINE_ID
- docker push $IMAGE_TAG_BASE:latest
nginx:test:
stage: test
needs:
- nginx:build
image: docker
services:
- docker:dind
variables:
DOCKER_HOST: "tcp://docker:2375"
IMAGE_TAG_BASE: $CI_REGISTRY_IMAGE/nginx
script:
- docker run -d --name test $IMAGE_TAG_BASE:$CI_PIPELINE_ID && sleep 3
- export TEST_OUTPUT=$(docker exec test curl -sSfL localhost)
- test "$TEST_OUTPUT" == "$CORRECT_OUTPUT" || (echo $OUTPUT && exit 1)
nginx:deploy:
stage: deploy
needs:
- nginx:test
# rules:
# - if: '$CI_PIPELINE_SOURCE == "external_pull_request_event"'
# when: never
image: registry.gitlab.com/gitlab-org/cloud-deploy/aws-base
variables:
IMAGE_TAG_BASE: $CI_REGISTRY_IMAGE/nginx
script:
- curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl
- chmod +x ./kubectl
- aws eks update-kubeconfig --name $CLUSTER_NAME
- sed -i "s,_IMAGE_,$IMAGE_TAG_BASE:$CI_PIPELINE_ID,g" nginx/kubernetes/deploy.yaml
- ./kubectl apply -f nginx/kubernetes/deploy.yaml
# python
python:build:
stage: build
image: docker
services:
- docker:dind
variables:
DOCKER_HOST: "tcp://docker:2375"
IMAGE_TAG_BASE: $CI_REGISTRY_IMAGE/python
script:
- cd python
- docker build . -t $IMAGE_TAG_BASE:$CI_COMMIT_SHORT_SHA
- docker tag $IMAGE_TAG_BASE:$CI_COMMIT_SHORT_SHA $IMAGE_TAG_BASE:$CI_PIPELINE_ID
- docker tag $IMAGE_TAG_BASE:$CI_COMMIT_SHORT_SHA $IMAGE_TAG_BASE:latest
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker push $IMAGE_TAG_BASE:$CI_COMMIT_SHORT_SHA
- docker push $IMAGE_TAG_BASE:$CI_PIPELINE_ID
- docker push $IMAGE_TAG_BASE:latest
python:test:
stage: test
needs:
- python:build
image: docker
services:
- docker:dind
variables:
DOCKER_HOST: "tcp://docker:2375"
IMAGE_TAG_BASE: $CI_REGISTRY_IMAGE/python
script:
- docker run -d --name test $IMAGE_TAG_BASE:$CI_PIPELINE_ID && sleep 3
- export TEST_OUTPUT=$(docker exec test curl -sSfL localhost)
- test "$TEST_OUTPUT" == "$CORRECT_OUTPUT" || (echo $OUTPUT && exit 1)
python:deploy:
stage: deploy
needs:
- python:test
# rules:
# - if: '$CI_PIPELINE_SOURCE == "external_pull_request_event"'
# when: never
image: registry.gitlab.com/gitlab-org/cloud-deploy/aws-base
variables:
IMAGE_TAG_BASE: $CI_REGISTRY_IMAGE/python
script:
- curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl
- chmod +x ./kubectl
- aws eks update-kubeconfig --name $CLUSTER_NAME
- sed -i "s,_IMAGE_,$IMAGE_TAG_BASE:$CI_PIPELINE_ID,g" python/kubernetes/deploy.yaml
- ./kubectl apply -f python/kubernetes/deploy.yaml
# golang
golang:build:
stage: build
image: docker
services:
- docker:dind
variables:
DOCKER_HOST: "tcp://docker:2375"
IMAGE_TAG_BASE: $CI_REGISTRY_IMAGE/golang
script:
- cd golang
- docker build . -t $IMAGE_TAG_BASE:$CI_COMMIT_SHORT_SHA
- docker tag $IMAGE_TAG_BASE:$CI_COMMIT_SHORT_SHA $IMAGE_TAG_BASE:$CI_PIPELINE_ID
- docker tag $IMAGE_TAG_BASE:$CI_COMMIT_SHORT_SHA $IMAGE_TAG_BASE:latest
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker push $IMAGE_TAG_BASE:$CI_COMMIT_SHORT_SHA
- docker push $IMAGE_TAG_BASE:$CI_PIPELINE_ID
- docker push $IMAGE_TAG_BASE:latest
golang:test:
stage: test
needs:
- golang:build
image: docker
services:
- docker:dind
variables:
DOCKER_HOST: "tcp://docker:2375"
IMAGE_TAG_BASE: $CI_REGISTRY_IMAGE/golang
script:
- docker run -d --name test $IMAGE_TAG_BASE:$CI_PIPELINE_ID && sleep 3
- export TEST_OUTPUT=$(docker exec test curl -sSfL localhost)
- test "$TEST_OUTPUT" == "$CORRECT_OUTPUT" || (echo $OUTPUT && exit 1)
golang:deploy:
stage: deploy
needs:
- golang:test
# rules:
# - if: '$CI_PIPELINE_SOURCE == "external_pull_request_event"'
# when: never
image: registry.gitlab.com/gitlab-org/cloud-deploy/aws-base
variables:
IMAGE_TAG_BASE: $CI_REGISTRY_IMAGE/golang
script:
- curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl
- chmod +x ./kubectl
- aws eks update-kubeconfig --name $CLUSTER_NAME
- sed -i "s,_IMAGE_,$IMAGE_TAG_BASE:$CI_PIPELINE_ID,g" golang/kubernetes/deploy.yaml
- ./kubectl apply -f golang/kubernetes/deploy.yaml