From 1cb28004c05058c68304af273153788deafbbf17 Mon Sep 17 00:00:00 2001 From: Ricardo Garcia Date: Wed, 15 Feb 2023 21:26:56 -0300 Subject: [PATCH 1/2] removendo ajustes heroku --- app.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index dca6341..041b2b7 100644 --- a/app.py +++ b/app.py @@ -1,5 +1,5 @@ from flask import Flask -import os +#import os app = Flask(__name__) @app.route("/") @@ -7,5 +7,8 @@ def pagina_inicial(): return "Desafio: Custom Message" if __name__ == '__main__': - port = os.getenv('PORT') - app.run('0.0.0.0', port=port) \ No newline at end of file + app.run() +# port = os.getenv('PORT') +# app.run('0.0.0.0', port=port) + +#removidos ajustes do Heroku \ No newline at end of file From 04fd4bc9d63aa09d56217c25aac5fe0dc0e0e51f Mon Sep 17 00:00:00 2001 From: Ricardo Garcia Date: Wed, 15 Feb 2023 22:52:08 -0300 Subject: [PATCH 2/2] docker-gcp --- .github/workflows/pipeline.yml | 63 ++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 3374064..0cff9e5 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -2,7 +2,7 @@ name: DevOpsLab Pipeline # Evento que irá acionar a pipeline -on: +on: push: branches: - main @@ -11,13 +11,13 @@ jobs: Build: runs-on: ubuntu-latest steps: - - name: Checkout Repo - uses: actions/checkout@v2 + - name: Download do Repositório + uses: actions/checkout@v3 # https://github.com/actions/checkout - name: Setup Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v4 # https://github.com/actions/setup-python with: - python-version: '3.9.15' + python-version: '3.10' - name: Install Requirements run: pip install flask @@ -25,32 +25,43 @@ jobs: - name: Unit Test run: python -m unittest -v test - - name: Login to Heroku Container registry - env: - HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }} - run: heroku container:login - - - name: Docker Image & Push Heroku Registry + - name: SonarCloud Scan + uses: SonarSource/sonarcloud-github-action@master env: - HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }} - run: heroku container:push -a ${{ secrets.HEROKU_APP_NAME }} web - + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + + - name: Docker Login + run: | + echo '${{ 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: needs: Build runs-on: ubuntu-latest steps: - - name: Deploy Heroku - env: - HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }} - run: heroku container:release -a ${{ secrets.HEROKU_APP_NAME }} web + - name: Checkout Repo + uses: actions/checkout@v3 # https://github.com/actions/checkout - # Adicionando o Repositório Remoto do Heroku para poder enviar o código da app - - name: Add Heroku Remote - run: heroku git:remote --app $HEROKU_APP_NAME - env: - HEROKU_APP_NAME: ${{ secrets.HEROKU_APP_NAME }} + - name: Auth GCP + uses: 'google-github-actions/auth@v1' # https://github.com/google-github-actions/auth + with: + credentials_json: '${{ secrets.GOOGLE_CREDENTIALS }}' - # Enviando o código da App para o Heroku fazer Deploy - - name: Push to Heroku & Deploy - run: git push heroku HEAD:main --force + - name: Cloud Run Deploy + id: deploy + run: |- + gcloud run deploy ${{ vars.GOOGLE_MYAPP }} \ + --quiet \ + --region ${{ vars.GOOGLE_REGION }} \ + --image ${{ vars.GOOGLE_ARTIFACT }}/${{ vars.GOOGLE_PROJECT_ID }}/${{ vars.GOOGLE_REPONAME }}/${{ vars.GOOGLE_MYAPP }}:latest \ + --platform managed \ + --allow-unauthenticated \ + --project ${{ vars.GOOGLE_PROJECT_ID }} \ + --format json \ No newline at end of file