Skip to content

Add output to deploy job #7

Add output to deploy job

Add output to deploy job #7

Workflow file for this run

name: 'Continuous Delivery'
on:
push:
branches:
- main
- release/*
- feature/*
jobs:
deploy:
runs-on: ubuntu-latest
env:
PROJECT_ID: ${{ secrets.GCP_PROJECT_ID }}
SERVICE_ACCOUNT_KEY: ${{ secrets.GCP_SA_KEY }}
APP_NAME: 'flight-delay-api'
REGION: 'us-central1'
outputs:
url: ${{ steps.deploy.outputs.url }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Print environment variables (debugging)
run: |
echo "PROJECT_ID=${{ env.PROJECT_ID }}"
echo "SERVICE_ACCOUNT_KEY=${{ env.SERVICE_ACCOUNT_KEY }}" | head -c 20
- name: Set up Google Cloud SDK
uses: google-github-actions/[email protected]
with:
service_account_key: ${{ env.SERVICE_ACCOUNT_KEY }}
project_id: ${{ env.PROJECT_ID }}
export_default_credentials: true
- name: Configure Docker to use the gcloud command-line tool as a credential helper
run: gcloud auth configure-docker
- name: Build Docker image
run: |
docker build -t gcr.io/${{ env.PROJECT_ID }}/${{ env.APP_NAME }} . --platform linux/amd64
- name: Push Docker image
run: |
docker push gcr.io/${{ env.PROJECT_ID }}/${{ env.APP_NAME }}
- name: Deploy to Cloud Run
id: deploy
run: |
echo "Deploying to Cloud Run"
URL=$(gcloud run deploy ${{ env.APP_NAME }} \
--image gcr.io/${{ env.PROJECT_ID }}/${{ env.APP_NAME }} \
--platform managed \
--region ${{ env.REGION }} \
--allow-unauthenticated \
--format 'value(status.url)')
echo "url=$URL" >> $GITHUB_OUTPUT
echo "Deployed to $URL"
- name: Set STRESS_URL for Makefile
run: echo "STRESS_URL=${{steps.deploy.outputs.url}}" >> $GITHUB_ENV
stress-test:
runs-on: ubuntu-latest
needs: deploy
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-test.txt
- name: Print STRESS_URL (debugging)
run: echo "STRESS_URL=${{ needs.deploy.outputs.url }}"
- name: Run stress test
env:
STRESS_URL: ${{ needs.deploy.outputs.url }}
run: |
make stress-test STRESS_URL=${{ env.STRESS_URL}}