VAMOAROMPERTODO2 #63
Workflow file for this run
This file contains hidden or 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
| name: Build and Deploy to Cloud Run | |
| on: | |
| push: #pull_request: | |
| workflow_dispatch: | |
| env: | |
| PROJECT_ID: ${{ vars.GCP_PROJECT_ID }} | |
| PROJECT_REGION: ${{ vars.GCP_PROJECT_REGION }} | |
| SERVICE_NAME: ${{ vars.GCP_SERVICE_API_NAME }} | |
| JOB_NAME: ${{ vars.GCP_SERVICE_API_NAME }}-update-groups | |
| ARTIFACT_REGISTRY: ${{ vars.GCP_ARTIFACT_REGISTRY }} | |
| jobs: | |
| build-and-push: | |
| name: Build and Push to Artifact Registry | |
| runs-on: ubuntu-latest | |
| environment: GCP-Rozen | |
| permissions: | |
| contents: 'read' | |
| id-token: 'write' | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Authenticate Cloud CLI | |
| uses: 'google-github-actions/auth@v2' | |
| with: | |
| credentials_json: ${{ secrets.GCP_SA_KEY }} | |
| - name: Set up Cloud SDK | |
| uses: 'google-github-actions/setup-gcloud@v2' | |
| - name: Authorize Docker push | |
| run: gcloud auth configure-docker ${{ env.PROJECT_REGION }}-docker.pkg.dev | |
| - name: Define image tag | |
| id: image_tag | |
| run: echo "TAG=${{ env.PROJECT_REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.ARTIFACT_REGISTRY }}/${{ env.SERVICE_NAME }}:${{ github.sha }}" >> $GITHUB_ENV | |
| - name: Build and Push Docker Image | |
| run: |- | |
| docker build -t $TAG . | |
| docker push $TAG | |
| deploy-to-cloud-run: | |
| name: Deploy Service to Cloud Run | |
| needs: build-and-push | |
| runs-on: ubuntu-latest | |
| environment: GCP-Rozen | |
| if: github.event_name == 'push' || github.event_name == 'pull_request' | |
| permissions: | |
| contents: 'read' | |
| id-token: 'write' | |
| steps: | |
| - name: Authenticate Cloud CLI | |
| uses: 'google-github-actions/auth@v2' | |
| with: | |
| credentials_json: ${{ secrets.GCP_SA_KEY }} | |
| - name: Set up Cloud SDK | |
| uses: 'google-github-actions/setup-gcloud@v2' | |
| - name: Define image tag for deployment | |
| id: image_tag | |
| run: echo "TAG=${{ env.PROJECT_REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.ARTIFACT_REGISTRY }}/${{ env.SERVICE_NAME }}:${{ github.sha }}" >> $GITHUB_ENV | |
| - name: Get existing service URL | |
| id: get_url | |
| run: echo "URL=$(gcloud run services describe ${{ env.SERVICE_NAME }} --platform managed --region ${{ env.PROJECT_REGION }} --format 'value(status.url)')" >> $GITHUB_ENV | |
| - name: Deploy to Cloud Run | |
| run: |- | |
| gcloud run deploy ${{ env.SERVICE_NAME }} \ | |
| --image $TAG \ | |
| --region ${{ env.PROJECT_REGION }} \ | |
| --service-account ${{ vars.GCP_SA_EMAIL }} \ | |
| --max-instances=${{ vars.GCP_SERVICE_API_MAX_INSTANCES }} \ | |
| --set-secrets=TELEGRAM_BOT_TOKEN=${{ vars.GCP_SECRET_TG_BOT_TOKEN }}:latest \ | |
| --set-secrets=DB_USER=${{ vars.GCP_SECRET_DB_USER }}:latest \ | |
| --set-secrets=DB_PASSWORD=${{ vars.GCP_SECRET_DB_PASSWORD }}:latest \ | |
| --set-secrets=DB_URL=${{ vars.GCP_SECRET_DB_URL }}:latest \ | |
| --set-env-vars=DB_PORT=${{ vars.GCP_DB_PORT }} \ | |
| --set-secrets=S3_ACCESS_ID=${{ vars.GCP_SECRET_S3_ACCESS_ID }}:latest \ | |
| --set-secrets=S3_ACCESS_SECRET=${{ vars.GCP_SECRET_S3_ACCESS_SECRET }}:latest \ | |
| --set-secrets=S3_HOST=${{ vars.GCP_SECRET_S3_HOST }}:latest \ | |
| --set-env-vars=S3_BUCKET=${{ vars.GCP_S3_BUCKET }} \ | |
| --set-env-vars=WEBHOOK_URL=${{ env.URL }} \ | |
| --platform managed \ | |
| --allow-unauthenticated | |
| deploy-cron-job-to-cloud-run: | |
| name: Deploy CronJob to Cloud Run | |
| needs: build-and-push | |
| runs-on: ubuntu-latest | |
| environment: GCP-Rozen | |
| if: github.event_name == 'push' | |
| permissions: | |
| contents: 'read' | |
| id-token: 'write' | |
| steps: | |
| - name: Authenticate Cloud CLI | |
| uses: 'google-github-actions/auth@v2' | |
| with: | |
| credentials_json: ${{ secrets.GCP_SA_KEY }} | |
| - name: Set up Cloud SDK | |
| uses: 'google-github-actions/setup-gcloud@v2' | |
| - name: Define image tag for deployment | |
| run: echo "TAG=${{ env.PROJECT_REGION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.ARTIFACT_REGISTRY }}/${{ env.SERVICE_NAME }}:${{ github.sha }}" >> $GITHUB_ENV | |
| - name: Deploy Cron Job to Cloud Run | |
| run: |- | |
| gcloud run jobs deploy ${{ env.JOB_NAME }} \ | |
| --image $TAG \ | |
| --region ${{ env.PROJECT_REGION }} \ | |
| --command=python \ | |
| --args=cron.py \ | |
| --schedule="0 0 * * *" \ | |
| --time-zone="America/Argentina/Buenos_Aires" \ | |
| --service-account ${{ vars.GCP_SA_EMAIL }} \ | |
| --set-secrets=TELEGRAM_BOT_TOKEN=${{ vars.GCP_SECRET_TG_BOT_TOKEN }}:latest \ | |
| --set-secrets=DB_USER=${{ vars.GCP_SECRET_DB_USER }}:latest \ | |
| --set-secrets=DB_PASSWORD=${{ vars.GCP_SECRET_DB_PASSWORD }}:latest \ | |
| --set-secrets=DB_URL=${{ vars.GCP_SECRET_DB_URL }}:latest \ | |
| --set-env-vars=DB_PORT=${{ vars.GCP_DB_PORT }} |