-
Notifications
You must be signed in to change notification settings - Fork 3
/
.gitlab-ci.yml
73 lines (64 loc) · 2.08 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
stages:
- build
- deploy
variables:
DOCKER_DRIVER: overlay2
IMAGE_NAME: $CI_REGISTRY_IMAGE
IMAGE_TAG: $CI_COMMIT_REF_SLUG
REPO_NAME: ""
## Build
build-image:
stage: build
image: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/docker:20.10.16
services:
- name: docker:20.10.16-dind
variables:
DOCKER_TLS_CERTDIR: ""
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
script:
- echo $IMAGE_NAME:$IMAGE_TAG
- docker build -t $IMAGE_NAME:$IMAGE_TAG .
- docker push $IMAGE_NAME:$IMAGE_TAG
- docker rmi $IMAGE_NAME:$IMAGE_TAG # remove local image from shared runner
- docker logout $CI_REGISTRY
## deploy to k8s staging
deploy_to_k8s_staging:
stage: deploy
needs: ["build-image"]
before_script:
# create the .kube/ directory
- mkdir -p ~/.kube/
# move the config file to default location
- echo $KUBE_CONFIG_INFO | base64 -d > ~/.kube/config
- unset HTTPS_PROXY
variables:
DOCKER_IMAGE: $IMAGE_NAME:$IMAGE_TAG
image: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/alpine/k8s:1.25.16
script:
- export KUBECONFIG=~/.kube/config
- sed -i "s#<DOCKER_IMAGE>#${DOCKER_IMAGE}#g" ./k8s/base/app/django-deployment.yaml
- kubectl apply -k ./k8s/overlays/staging
- kubectl rollout restart deployment django-deployment-staging -n tark-staging
## deploy to k8s production
deploy_to_k8s_production:
stage: deploy
needs: ["build-image"]
before_script:
# create the .kube/ directory
- mkdir -p ~/.kube/
# move the config file to default location
- echo $KUBE_CONFIG_INFO | base64 -d > ~/.kube/config
- unset HTTPS_PROXY
variables:
DOCKER_IMAGE: $IMAGE_NAME:$IMAGE_TAG
image: ${CI_DEPENDENCY_PROXY_GROUP_IMAGE_PREFIX}/alpine/k8s:1.25.16
script:
- export KUBECONFIG=~/.kube/config
- sed -i "s#<DOCKER_IMAGE>#${DOCKER_IMAGE}#g" ./k8s/base/app/django-deployment.yaml
- kubectl apply -k ./k8s/overlays/production
- kubectl rollout restart deployment django-deployment-production -n tark-production
only:
- main
- migrate_to_k8s
when: manual