Skip to content

Commit 61b0c82

Browse files
Add Dockerfile for notifications job and Github action workflow
1 parent 90b3c3d commit 61b0c82

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Deploy Notifications Job to Cloud RUN
2+
3+
on:
4+
push:
5+
branches: [ "migrate-noti-job-to-gcp" ]
6+
paths:
7+
- '**/*'
8+
workflow_dispatch:
9+
inputs:
10+
environment:
11+
description: 'Select the environment to deploy to'
12+
required: true
13+
default: 'development'
14+
branch:
15+
description: 'Branch to deploy from'
16+
required: true
17+
default: 'main'
18+
19+
env:
20+
SERVICE: notifications-job
21+
REGION: us-central1
22+
23+
jobs:
24+
deploy:
25+
# environment: ${{ github.event.inputs.environment }}
26+
environment: development
27+
permissions:
28+
contents: 'read'
29+
id-token: 'write'
30+
31+
runs-on: ubuntu-latest
32+
steps:
33+
# - name: Validate Environment Input
34+
# run: |
35+
# if [[ "${{ github.event.inputs.environment }}" != "development" && "${{ github.event.inputs.environment }}" != "prod" ]]; then
36+
# echo "Invalid environment: ${{ github.event.inputs.environment }}. Must be 'development' or 'prod'."
37+
# exit 1
38+
# fi
39+
40+
# To workaround "no space left on device" issue of GitHub-hosted runner
41+
- name: Delete huge unnecessary tools folder
42+
run: rm -rf /opt/hostedtoolcache
43+
44+
- name: Checkout
45+
uses: actions/checkout@v4
46+
47+
- name: Google Auth
48+
id: auth
49+
uses: 'google-github-actions/auth@v2'
50+
with:
51+
credentials_json: ${{ secrets.GCP_CREDENTIALS }}
52+
53+
- name: Login to GCR
54+
run: gcloud auth configure-docker
55+
56+
- name: Set up Docker Buildx
57+
uses: docker/setup-buildx-action@v3
58+
59+
- name: Google Service Account
60+
run: echo "${{ secrets.GCP_SERVICE_ACCOUNT }}" | base64 -d > ./backend/google-credentials.json
61+
62+
- name: Build and Push Docker image
63+
uses: docker/build-push-action@v6
64+
with:
65+
context: .
66+
file: ./backend/modal/Dockerfile.notifications_job
67+
push: true
68+
tags: gcr.io/${{ vars.GCP_PROJECT_ID }}/${{ env.SERVICE }}:latest
69+
cache-from: type=registry,ref=gcr.io/${{ vars.GCP_PROJECT_ID }}/${{ env.SERVICE }}:buildcache
70+
cache-to: type=registry,ref=gcr.io/${{ vars.GCP_PROJECT_ID }}/${{ env.SERVICE }}:buildcache,mode=max
71+
72+
- name: Deploy to Cloud Run
73+
id: deploy
74+
uses: google-github-actions/deploy-cloudrun@v2
75+
with:
76+
job: ${{ env.SERVICE }}
77+
region: ${{ env.REGION }}
78+
image: gcr.io/${{ vars.GCP_PROJECT_ID }}/${{ env.SERVICE }}
79+
80+
# If required, use the Cloud Run url output in later steps
81+
- name: Show Output
82+
run: echo ${{ steps.deploy.outputs.url }}
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
FROM python:3.11 AS builder
2+
3+
ENV PATH="/opt/venv/bin:$PATH"
4+
RUN python -m venv /opt/venv
5+
6+
COPY backend/requirements.txt /tmp/requirements.txt
7+
RUN pip install --no-cache-dir --upgrade -r /tmp/requirements.txt
8+
9+
FROM python:3.11-slim
10+
11+
WORKDIR /app
12+
ENV PATH="/opt/venv/bin:$PATH"
13+
14+
RUN apt-get update && apt-get -y install ffmpeg curl unzip && rm -rf /var/lib/apt/lists/*
15+
16+
COPY --from=builder /opt/venv /opt/venv
17+
COPY backend/database /app/database
18+
COPY backend/utils /app/utils
19+
COPY backend/modal/ .
20+
21+
CMD ["uvicorn", "job_modal:app"]

0 commit comments

Comments
 (0)