-
Notifications
You must be signed in to change notification settings - Fork 3
/
.gitlab-ci.yml
84 lines (75 loc) · 2.55 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
---
image: docker:18.01.0-ce-git
services:
- docker:18.01.0-ce-dind
stages:
- build
- deploy
variables:
DJANGO_RELEASE_IMAGE: $CI_REGISTRY_IMAGE/django:$CI_BUILD_REF_NAME
DJANGO_HOMOLOG_IMAGE: $CI_REGISTRY_IMAGE/django:$CI_BUILD_REF_NAME-$CI_COMMIT_SHORT_SHA
NGINX_HOMOLOG_IMAGE: $CI_REGISTRY_IMAGE/nginx:$CI_BUILD_REF_NAME-$CI_COMMIT_SHORT_SHA
NGINX_RELEASE_IMAGE: $CI_REGISTRY_IMAGE/nginx:$CI_BUILD_REF_NAME
KUBECONFIG: /etc/k8s-config
##########
## Homolog
##########
build to homolog:
stage: build
script:
- docker login -u "gitlab-ci-token" -p "$CI_JOB_TOKEN" $CI_REGISTRY
- docker build -f compose/production/Dockerfile --target django -t $DJANGO_HOMOLOG_IMAGE .
- docker push $DJANGO_HOMOLOG_IMAGE
- docker build -f compose/production/Dockerfile --target nginx -t $NGINX_HOMOLOG_IMAGE .
- docker push $NGINX_HOMOLOG_IMAGE
only:
- /master/
environment: homolog
tags:
- docker
deploy to homolog:
stage: deploy
image: hacklab/kubectl:latest
script:
- echo ${kube_config} | base64 -d > ${KUBECONFIG}
- kubectl -n mapaguarani-dev --record deployment.apps/django set image deployment.v1.apps/django django=$DJANGO_HOMOLOG_IMAGE
- sleep 30
- kubectl -n mapaguarani-dev --record deployment.apps/backend set image deployment.v1.apps/backend backend=$NGINX_HOMOLOG_IMAGE
only:
- /master/
environment: homolog
tags:
- docker
#############
## Production
#############
build to production:
stage: build
script:
- docker login -u "gitlab-ci-token" -p "$CI_JOB_TOKEN" $CI_REGISTRY
- docker build -f compose/production/Dockerfile --target django -t $DJANGO_RELEASE_IMAGE .
- docker tag $DJANGO_RELEASE_IMAGE $CI_REGISTRY_IMAGE/django:latest
- docker push $DJANGO_RELEASE_IMAGE
- docker push $CI_REGISTRY_IMAGE/django:latest
- docker build -f compose/production/Dockerfile --target nginx -t $NGINX_RELEASE_IMAGE .
- docker tag $NGINX_RELEASE_IMAGE $CI_REGISTRY_IMAGE/nginx:latest
- docker push $NGINX_RELEASE_IMAGE
- docker push $CI_REGISTRY_IMAGE/nginx:latest
only:
- tags
environment: production
tags:
- docker
deploy to production:
stage: deploy
image: hacklab/kubectl:latest
script:
- echo ${kube_config} | base64 -d > ${KUBECONFIG}
- kubectl -n mapaguarani-prod --record deployment.apps/django set image deployment.v1.apps/django django=$DJANGO_RELEASE_IMAGE
- sleep 30
- kubectl -n mapaguarani-prod --record deployment.apps/backend set image deployment.v1.apps/backend backend=$NGINX_RELEASE_IMAGE
only:
- tags
environment: production
tags:
- docker