-
Notifications
You must be signed in to change notification settings - Fork 0
92 lines (74 loc) · 3.11 KB
/
pipeline.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
# Nome do Workflow
name: DevOpsLab Pipeline
# Evento que irá acionar a pipeline
on:
push:
branches:
- main
jobs:
Build:
runs-on: ubuntu-latest
steps:
- name: Download do Repositório
uses: actions/checkout@v3 # https://github.com/actions/checkout
with:
fetch-depth: 0
- name: Setup Python
uses: actions/setup-python@v4 # https://github.com/actions/setup-python
with:
python-version: "3.10"
- name: Install Requirements
run: pip install tox
- name: Unit Test
run: tox -e py
- name: SonarCloud Scan
uses: sonarsource/sonarcloud-github-action@master #https://github.com/marketplace/actions/sonarcloud-scan
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- name: Docker Login
run: |
echo -E '${{ secrets.GOOGLE_CREDENTIALS }}' > key.json
cat key.json | docker login -u _json_key --password-stdin '${{ vars.GOOGLE_ARTIFACT }}'
- name: Build & Push Image
run: |
docker build -t ${{ vars.GOOGLE_ARTIFACT }}/${{ vars.GOOGLE_PROJECT_ID }}/${{ vars.GOOGLE_REPONAME }}/${{ vars.GOOGLE_MYAPP }}:latest .
docker push ${{ vars.GOOGLE_ARTIFACT }}/${{ vars.GOOGLE_PROJECT_ID }}/${{ vars.GOOGLE_REPONAME }}/${{ vars.GOOGLE_MYAPP }}:latest
Deploy-Homolog:
needs: Build
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3 # https://github.com/actions/checkout
- name: Auth GCP
uses: "google-github-actions/auth@v1" # https://github.com/google-github-actions/auth
with:
credentials_json: "${{ secrets.GOOGLE_CREDENTIALS }}"
- name: Cloud Run Deploy - Homolog
id: homolog-deploy
uses: "google-github-actions/deploy-cloudrun@v1" # https://github.com/marketplace/actions/deploy-to-cloud-run
with:
service: ${{ vars.GOOGLE_MYAPP }}-homolog
image: ${{ vars.GOOGLE_ARTIFACT }}/${{ vars.GOOGLE_PROJECT_ID }}/${{ vars.GOOGLE_REPONAME }}/${{ vars.GOOGLE_MYAPP }}:latest
flags: "--allow-unauthenticated"
- name: Test Homolog
run: 'curl "${{ steps.homolog-deploy.outputs.url }}"'
Deploy-Production:
needs: Deploy-Homolog
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3 # https://github.com/actions/checkout
- name: Auth GCP
uses: "google-github-actions/auth@v1" # https://github.com/google-github-actions/auth
with:
credentials_json: "${{ secrets.GOOGLE_CREDENTIALS }}"
- name: Cloud Run Deploy - Production
id: prod-deploy
uses: "google-github-actions/deploy-cloudrun@v1" # https://github.com/marketplace/actions/deploy-to-cloud-run
with:
service: ${{ vars.GOOGLE_MYAPP }}-prod
image: ${{ vars.GOOGLE_ARTIFACT }}/${{ vars.GOOGLE_PROJECT_ID }}/${{ vars.GOOGLE_REPONAME }}/${{ vars.GOOGLE_MYAPP }}:latest
flags: "--allow-unauthenticated"
- name: Test Prod
run: 'curl "${{ steps.prod-deploy.outputs.url }}"'