-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path.gitlab-ci.yml
174 lines (144 loc) · 5.7 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
services:
- docker:dind
before_script:
- apk update && apk upgrade && apk add --no-cache bash openssh
variables:
DOCKER_DRIVER: overlay2
stages:
- test
- release
- deploy
test:
stage: test
image: vaeum/alpine-python3-pip3
before_script:
- pip install -r requirements.txt
variables:
POSTGRES_DB: postgres
POSTGRES_USER: postgres
POSTGRES_PASSWORD: ''
POLLSAPI_PG_HOST: postgres
services:
- postgres:9.6-alpine
script:
- python manage.py test
release:
stage: release
image: docker:latest
before_script:
- export COMMIT_SHA=$(echo $CI_COMMIT_SHA | cut -c1-8)
- apk update
- apk upgrade
- apk add python python-dev py-pip build-base
- apk add --update ca-certificates
- apk add --update -t deps curl
- apk del --purge deps
- rm /var/cache/apk/*
script:
# Build our image
- docker build -t $GCP_PROJECT_ID/$CI_PROJECT_NAME:$COMMIT_SHA .
# Write our GCP service account private key into a file
- echo $GCLOUD_SERVICE_KEY | base64 -d > ${HOME}/gcloud-service-key.json
# Download and install Google Cloud SDK
- wget https://dl.google.com/dl/cloudsdk/release/google-cloud-sdk.tar.gz
- tar zxvf google-cloud-sdk.tar.gz && ./google-cloud-sdk/install.sh --usage-reporting=false --path-update=true
# Update gcloud components
- google-cloud-sdk/bin/gcloud --quiet components update
# Give access to gcloud project
- google-cloud-sdk/bin/gcloud auth activate-service-account --key-file ${HOME}/gcloud-service-key.json || die "unable to authenticate service account for gcloud"
# Get current projects credentials to access it
- google-cloud-sdk/bin/gcloud container clusters get-credentials pollsapi --zone asia-south1-a --project test-gcp-208915
# Configure container registry to push using docker
- docker login -u _json_key --password-stdin https://gcr.io < ${HOME}/gcloud-service-key.json
# Push the image using docker
- docker push $GCP_PROJECT_ID/$CI_PROJECT_NAME:$COMMIT_SHA
only:
- master
migrations:
image: google/cloud-sdk:alpine
stage: deploy
variables:
KUBE_LATEST_VERSION: "v1.8.5"
before_script:
- export COMMIT_SHA=$(echo $CI_COMMIT_SHA | cut -c1-8)
- apk update
- apk upgrade
- apk add --update ca-certificates
- apk add --update -t deps curl
- curl -L https://storage.googleapis.com/kubernetes-release/release/${KUBE_LATEST_VERSION}/bin/linux/amd64/kubectl -o /usr/local/bin/kubectl
- chmod +x /usr/local/bin/kubectl
- apk del --purge deps
- rm /var/cache/apk/*
script:
# Write our GCP service account private key into a file
- echo $GCLOUD_SERVICE_KEY | base64 -d > ${HOME}/gcloud-service-key.json
# Update gcloud components
- gcloud --quiet components update
# Give access to gcloud project
- gcloud auth activate-service-account --key-file ${HOME}/gcloud-service-key.json || die "unable to authenticate service account for gcloud"
- gcloud container clusters get-credentials pollsapi --zone asia-south1-a --project test-gcp-208915
# Run kubectl apply to apply any changes made in env variables, etc
- kubectl apply -f polls-migration.yml
environment: production
when: manual
only:
- master
collect-static:
image: google/cloud-sdk:alpine
stage: deploy
variables:
KUBE_LATEST_VERSION: "v1.8.5"
before_script:
- export COMMIT_SHA=$(echo $CI_COMMIT_SHA | cut -c1-8)
- apk update
- apk upgrade
- apk add --update ca-certificates
- apk add --update -t deps curl
- curl -L https://storage.googleapis.com/kubernetes-release/release/${KUBE_LATEST_VERSION}/bin/linux/amd64/kubectl -o /usr/local/bin/kubectl
- chmod +x /usr/local/bin/kubectl
- apk del --purge deps
- rm /var/cache/apk/*
script:
# Write our GCP service account private key into a file
- echo $GCLOUD_SERVICE_KEY | base64 -d > ${HOME}/gcloud-service-key.json
# Update gcloud components
- gcloud --quiet components update
# Give access to gcloud project
- gcloud auth activate-service-account --key-file ${HOME}/gcloud-service-key.json || die "unable to authenticate service account for gcloud"
- gcloud container clusters get-credentials pollsapi --zone asia-south1-a --project test-gcp-208915
# Run kubectl apply to apply any changes made in env variables, etc
- kubectl apply -f polls-collect-static.yml
environment: production
when: manual
only:
- master
deploy:
image: google/cloud-sdk:alpine
stage: deploy
variables:
KUBE_LATEST_VERSION: "v1.8.5"
before_script:
- export COMMIT_SHA=$(echo $CI_COMMIT_SHA | cut -c1-8)
- apk update
- apk upgrade
- apk add --update ca-certificates
- apk add --update -t deps curl
- curl -L https://storage.googleapis.com/kubernetes-release/release/${KUBE_LATEST_VERSION}/bin/linux/amd64/kubectl -o /usr/local/bin/kubectl
- chmod +x /usr/local/bin/kubectl
- apk del --purge deps
- rm /var/cache/apk/*
script:
# Write our GCP service account private key into a file
- echo $GCLOUD_SERVICE_KEY | base64 -d > ${HOME}/gcloud-service-key.json
# Update gcloud components
- gcloud --quiet components update
# Give access to gcloud project
- gcloud auth activate-service-account --key-file ${HOME}/gcloud-service-key.json || die "unable to authenticate service account for gcloud"
- gcloud container clusters get-credentials pollsapi --zone asia-south1-a --project test-gcp-208915
# Run kubectl apply to apply any changes made in env variables, etc
- kubectl apply -f pollsapi.yml
# Update deployment with new image
- kubectl set image deployment/polls-api ${CI_PROJECT_NAME}=$GCP_PROJECT_ID/$CI_PROJECT_NAME:$COMMIT_SHA
environment: production
only:
- master