-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
107 lines (94 loc) · 3 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
#include: '/templates/padrao.template.yml'
include: 'https://gitlab.fslab.dev/fslab/modelo-ci-cd/-/raw/master/templates/padrao.template.yml'
variables:
IMG_WEILPLACE_API: registry.fslab.dev/erickweil/weilplace-api
IMG_WEILPLACE_SITE: registry.fslab.dev/erickweil/weilplace-site
KUBECTL_CONFIG: $KUBECTL_CONFIG
API_SHARED_SECRET: $API_SHARED_SECRET
SESSION_SECRET: $SESSION_SECRET
OAUTH2_CLIENT_ID: $OAUTH2_CLIENT_ID
stages:
- test
- publish
- deploy
test:
extends:
- .on-commit-main
- .disable-git-clone
needs: []
stage: test
script:
- echo $FUNCIONA_VARIAVEIS
- ls -lhas
- echo "Nome da imagem weilplace-api"
- echo $IMG_WEILPLACE_API
- echo "Nome da imagem weilplace-site"
- echo $IMG_WEILPLACE_SITE
- echo "Primeira linha da configuração kubectl"
- head -n1 $KUBECTL_CONFIG
- echo $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
merge-test-api:
image: node:alpine
extends: .on-create-merge-main
needs: []
stage: test
script:
- mv ./backend/.env.example ./backend/.env
- cd ./backend
- npm install
- npm run test
# artifacts:
# paths:
# - backend/node_modules
build-weilplace-api:
extends:
- .on-commit-main
- .build-docker
needs: ["test"]
stage: publish
variables:
BUILD_DIR: "./backend"
BUILD_TAG: $IMG_WEILPLACE_API:latest
before_script:
- mv ./backend/.env.example ./backend/.env
# Não tá legal, a imagem com secret? o secret deveria estar no kubernetes não?
- echo "SESSION_SECRET=\"$SESSION_SECRET\"" >> ./backend/.env
- echo "API_SHARED_SECRET=\"$API_SHARED_SECRET\"" >> ./backend/.env
- echo "OAUTH2_CLIENT_ID=\"$OAUTH2_CLIENT_ID\"" >> ./backend/.env
build-weilplace-site:
extends:
- .on-commit-main
- .build-docker
needs: ["test"]
stage: publish
variables:
BUILD_DIR: "./frontend"
BUILD_TAG: $IMG_WEILPLACE_SITE:latest
before_script:
- cp ./frontend/.env.production ./frontend/.env.local
- echo "NEXT_PUBLIC_OAUTH2_CLIENT_ID=\"$OAUTH2_CLIENT_ID\"" >> ./frontend/.env.local
# https://juju.is/tutorials/using-gitlab-as-a-container-registry#7-pull-your-container
deploy-weilplace:
extends: .on-commit-main
needs: ["build-weilplace-site","build-weilplace-api"]
stage: deploy
image:
name: bitnami/kubectl:latest
entrypoint: ['']
script:
# Para ter as credenciais do kubectl
- cat $KUBECTL_CONFIG > ~/.kube/config
#- cat ~/.kube/config
# Debug
- kubectl config get-contexts
- kubectl get node
- kubectl get pods
# Pedir para parar (Dependendo do que mudar na configuração não vai funciona só re-aplicar com 'rollout restart')
- kubectl delete deployment weilplace-api || true
- kubectl delete deployment weilplace-site || true
- kubectl delete deployment weilplace-pixelsaver || true
# Espera 10 segundos para ter certeza que parou tudo
- sleep 10
# Aplicar novamente os deployments
- kubectl apply -f ./backend/deployment.yaml
- kubectl apply -f ./frontend/deployment.yaml