Skip to content

Deploy Streamlit App to Cloud Run #26

Deploy Streamlit App to Cloud Run

Deploy Streamlit App to Cloud Run #26

name: Deploy Streamlit App to Cloud Run
on:
push:
branches:
- master # Triggers the action on push to the master branch
workflow_dispatch: # Allows manual triggering of the workflow from GitHub Actions
env:
REPOSITORY: streamlit-app-repo
IMAGE: streamlit-app
jobs:
deploy:
name: Deploy Streamlit to Cloud Run using Artifact Registry
runs-on: ubuntu-latest
steps:
# Step 1: Checkout the repository
- name: Checkout code
uses: actions/checkout@v3
# Step 2: Authenticate GCP
- name: Authenticate GCP
id: gcp-auth
uses: google-github-actions/auth@v2
with:
credentials_json: '${{ secrets.GCP_SA_KEY }}' # GCP service account JSON key
token_format: 'access_token'
# Step 3: Set up Google Cloud SDK
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v2
#with:
# version: 'latest'
# project_id: ${{ secrets.GCP_PROJECT_ID }}
- name: Docker Auth
id: docker-auth
uses: 'docker/login-action@v1'
with:
username: 'oauth2accesstoken'
password: '${{ steps.gcp-auth.outputs.access_token }}'
registry: '${{ secrets.GCP_REGION }}-docker.pkg.dev'
# Step 4: Configure Docker to use Artifact Registry
#- name: Authenticate Docker to Artifact Registry
# run: |
# gcloud auth configure-docker ${{ secrets.GCP_REGION }}-docker.pkg.dev
# Step 5: Build Docker Image for Streamlit app
- name: Build Docker image
run: |
docker build -t ${{ secrets.GCP_REGION }}-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/$REPOSITORY/$IMAGE:$GITHUB_SHA .
# Step 6: Push Docker image to Google Artifact Registry
- name: Push Docker image to Artifact Registry
run: |
docker push ${{ secrets.GCP_REGION }}-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/$REPOSITORY/$IMAGE:$GITHUB_SHA
# Step 7: Deploy to Cloud Run using the Artifact Registry image
- name: Deploy to Cloud Run
run: |
gcloud run deploy streamlit-app-testing \
--image ${{ secrets.GCP_REGION }}-docker.pkg.dev/${{ secrets.GCP_PROJECT_ID }}/$REPOSITORY/$IMAGE:$GITHUB_SHA \
--platform managed \
--region ${{ secrets.GCP_REGION }} \
--allow-unauthenticated