-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from prefeitura-rio/development
Implementação de Testes Automatizados
- Loading branch information
Showing
21 changed files
with
845 additions
and
273 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
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 - | ||
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 - | ||
kubectl rollout status -w -n unificacao-prontuarios-dev deployment/unificacao-prontuarios |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: Deploy docs | ||
name: Lib - Docs | ||
|
||
on: | ||
push: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: CI - Lint | ||
name: Lib - Lint | ||
|
||
on: | ||
push: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: CI - Tests | ||
name: Lib - Tests | ||
|
||
on: | ||
push: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
--- | ||
# Deployment | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: unificacao-prontuarios | ||
spec: | ||
replicas: 1 | ||
strategy: | ||
type: RollingUpdate | ||
rollingUpdate: | ||
maxSurge: 1 | ||
maxUnavailable: 0 | ||
selector: | ||
matchLabels: | ||
app: unificacao-prontuarios | ||
minReadySeconds: 5 | ||
template: | ||
metadata: | ||
labels: | ||
app: unificacao-prontuarios | ||
spec: | ||
containers: | ||
- name: unificacao-prontuarios | ||
image: gcr.io/PROJECT_ID/IMAGE_NAME:TAG | ||
ports: | ||
- containerPort: 80 | ||
envFrom: | ||
- secretRef: | ||
name: unificacao-prontuarios-secrets | ||
readinessProbe: | ||
httpGet: | ||
path: /docs | ||
port: 80 | ||
initialDelaySeconds: 5 | ||
periodSeconds: 10 | ||
livenessProbe: | ||
httpGet: | ||
path: /docs | ||
port: 80 | ||
initialDelaySeconds: 5 | ||
periodSeconds: 10 | ||
resources: | ||
requests: | ||
memory: "512Mi" | ||
cpu: "250m" | ||
limits: | ||
memory: "1024Mi" | ||
cpu: "500m" | ||
restartPolicy: Always | ||
|
||
--- | ||
# Service | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
labels: | ||
app: unificacao-prontuarios | ||
name: unificacao-prontuarios | ||
spec: | ||
ports: | ||
- name: "80" | ||
port: 80 | ||
targetPort: 80 | ||
selector: | ||
app: unificacao-prontuarios |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.