Skip to content

Commit

Permalink
feat - add cd workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilevk committed May 7, 2024
1 parent 04f5bac commit c82a758
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/cd_workflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Build and Deploy to Cloud Run

on:
push:
branches: [ "main" ]

env:
PROJECT_ID: ${{ secrets.project_id }} # TODO: update Google Cloud project id
GAR_LOCATION: ${{ vars.gar_location }} # TODO: update Artifact Registry location
SERVICE: ${{ vars.service_name }} # TODO: update Cloud Run service name
REGION: ${{ vars.service_region }} # TODO: update Cloud Run service region

jobs:
deploy:
# Add 'id-token' with the intended permissions for workload identity federation
permissions:
contents: 'read'
id-token: 'write'

runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

# NOTE: Alternative option - authentication via credentials json
- name: Google Auth
id: auth
uses: 'google-github-actions/auth@v2'
with:
credentials_json: '${{ secrets.GCP_CREDENTIALS }}'

- name: Build and Push Container
run: |-
gcloud auth configure-docker ${{ env.GAR_LOCATION }}-docker.pkg.dev
docker build -t "${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}/${{ github.sha }}" ./
docker push "${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}/${{ github.sha }}"
# END - Docker auth and build

- name: Deploy to Cloud Run
id: deploy
uses: google-github-actions/deploy-cloudrun@v2
with:
service: ${{ env.SERVICE }}
region: ${{ env.REGION }}
# NOTE: If using a pre-built image, update the image name here
image: ${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}/${{ github.sha }}

# If required, use the Cloud Run url output in later steps
- name: Show Output
run: echo ${{ steps.deploy.outputs.url }}
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM python:3.11.8-slim

WORKDIR /

RUN pip install poetry

COPY ./poetry.lock ./poetry.lock
COPY ./pyproject.toml ./pyproject.toml

RUN poetry export -f requirements.txt --output requirements.txt --without-hashes

RUN pip install --no-cache-dir --upgrade -r ./requirements.txt

COPY ./app /app
COPY ./entrypoint.sh /entrypoint.sh

ENTRYPOINT ["bash", "./entrypoint.sh"]
2 changes: 2 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export ENV=prod
uvicorn app.main:app --host 0.0.0.0 --port $PORT

0 comments on commit c82a758

Please sign in to comment.