Skip to content

Auto deploy to gcp (#13) #7

Auto deploy to gcp (#13)

Auto deploy to gcp (#13) #7

name: Publish Docker image to GHCR and Google Artifact Registry
on:
push:
branches:
- main # Or master, or your default branch
jobs:
build_and_publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write # Required to publish packages to GHCR
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v1
with:
credentials_json: ${{ secrets.GCP_SA_KEY }}
- name: Configure Docker for Artifact Registry
run: gcloud auth configure-docker us-west2-docker.pkg.dev --quiet
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: |
ghcr.io/${{ github.repository }}
us-west2-docker.pkg.dev/title-gen/titlegenerator/titlecreator
tags: |
type=raw,value=latest
type=sha,format=short
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Deploy to Cloud Run
run: |
gcloud run services replace cloudrun.yaml \
--region=us-west1 \
--project=title-gen