-
Notifications
You must be signed in to change notification settings - Fork 0
194 lines (177 loc) · 6.33 KB
/
api.yaml
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
name: API
on:
push:
paths:
- ".github/workflows/api*"
- "api/**/*"
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.11.x"
- name: Set up dependencies
run: |
cd api/
pip install -U pip poetry
poetry config virtualenvs.create false
poetry install --with dev
- name: Run linters
run: |
cd api/
task lint
tests:
name: Tests
runs-on: ubuntu-latest
container: python:3.11-slim
env:
INFISICAL_ADDRESS: ${{ secrets.INFISICAL_ADDRESS }}
INFISICAL_TOKEN: ${{ secrets.INFISICAL_TOKEN }}
services:
db:
image: postgres:15
env:
POSTGRES_PASSWORD: postgres
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up dependencies
run: |
cd api/
pip install -U pip poetry
poetry config virtualenvs.create false
poetry install --with dev
- name: Set up database
run: |
cd api/
aerich init-db || true
aerich upgrade || true
- name: Run tests
run: |
cd api/
task test
deploy:
name: Build and Deploy
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/development'
needs: [lint, tests]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push image
uses: docker/build-push-action@v2
with:
context: api/
file: api/Dockerfile
push: true
tags: |
ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ github.sha }}
ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ github.ref == 'refs/heads/main' && 'latest' || github.ref == 'refs/heads/development' && 'latest-dev' || github.sha }}
labels: |
org.opencontainers.image.source=${{ github.event.repository.html_url }}
org.opencontainers.image.revision=${{ github.sha }}
build-args: |
BUILDKIT_INLINE_CACHE=1
- name: Setup Google Cloud CLI
uses: google-github-actions/[email protected]
with:
service_account_key: ${{ secrets.GCP_SA_KEY }}
project_id: ${{ secrets.GCP_PROJECT_ID }}
export_default_credentials: true
- name: Get GKE credentials
uses: google-github-actions/[email protected]
with:
cluster_name: ${{ secrets.GKE_CLUSTER }}
location: ${{ secrets.GKE_ZONE }}
credentials: ${{ secrets.GCP_SA_KEY }}
- name: Set up Kustomize
run: |-
curl -sfLo kustomize https://github.com/kubernetes-sigs/kustomize/releases/download/v3.1.0/kustomize_3.1.0_linux_amd64
chmod u+x ./kustomize
mv ./kustomize api/
- name: Deploy (main)
if: github.ref == 'refs/heads/main'
run: |-
cd api/
./kustomize edit set image gcr.io/PROJECT_ID/IMAGE_NAME:TAG=ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ github.sha }}
./kustomize build . | kubectl apply -n unificacao-prontuarios-prod -f -
cat <<EOF | kubectl apply -n unificacao-prontuarios-prod -f -
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: unificacao-prontuarios-ingress
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /
cert-manager.io/cluster-issuer: "letsencrypt"
nginx.ingress.kubernetes.io/ssl-redirect: "true"
spec:
tls:
- hosts:
- unificacao-prontuarios.dados.rio
secretName: unificacao-prontuarios-tls
rules:
- host: unificacao-prontuarios.dados.rio
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: unificacao-prontuarios
port:
number: 80
EOF
kubectl rollout status -w -n unificacao-prontuarios-prod deployment/unificacao-prontuarios
- name: Deploy (development)
if: github.ref == 'refs/heads/development'
run: |-
cd api/
./kustomize edit set image gcr.io/PROJECT_ID/IMAGE_NAME:TAG=ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ github.sha }}
./kustomize build . | kubectl apply -n unificacao-prontuarios-dev -f -
cat <<EOF | kubectl apply -n unificacao-prontuarios-prod -f -
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: unificacao-prontuarios-ingress
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /
cert-manager.io/cluster-issuer: "letsencrypt"
nginx.ingress.kubernetes.io/ssl-redirect: "true"
spec:
tls:
- hosts:
- unificacao-prontuarios-dev.dados.rio
secretName: unificacao-prontuarios-tls
rules:
- host: unificacao-prontuarios-dev.dados.rio
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: unificacao-prontuarios
port:
number: 80
EOF
kubectl rollout status -w -n unificacao-prontuarios-dev deployment/unificacao-prontuarios