Skip to content

Commit 60e9e80

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

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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+
permissions:
27+
contents: 'read'
28+
id-token: 'write'
29+
30+
runs-on: ubuntu-latest
31+
steps:
32+
- name: Validate Environment Input
33+
run: |
34+
if [[ "${{ github.event.inputs.environment }}" != "development" && "${{ github.event.inputs.environment }}" != "prod" ]]; then
35+
echo "Invalid environment: ${{ github.event.inputs.environment }}. Must be 'development' or 'prod'."
36+
exit 1
37+
fi
38+
39+
# To workaround "no space left on device" issue of GitHub-hosted runner
40+
- name: Delete huge unnecessary tools folder
41+
run: rm -rf /opt/hostedtoolcache
42+
43+
- name: Checkout
44+
uses: actions/checkout@v4
45+
46+
- name: Google Auth
47+
id: auth
48+
uses: 'google-github-actions/auth@v2'
49+
with:
50+
credentials_json: ${{ secrets.GCP_CREDENTIALS }}
51+
52+
- name: Login to GCR
53+
run: gcloud auth configure-docker
54+
55+
- name: Set up Docker Buildx
56+
uses: docker/setup-buildx-action@v3
57+
58+
- name: Google Service Account
59+
run: echo "${{ secrets.GCP_SERVICE_ACCOUNT }}" | base64 -d > ./backend/google-credentials.json
60+
61+
- name: Build and Push Docker image
62+
uses: docker/build-push-action@v6
63+
with:
64+
context: .
65+
file: ./backend/modal/Dockerfile.notifications_job
66+
push: true
67+
tags: gcr.io/${{ vars.GCP_PROJECT_ID }}/${{ env.SERVICE }}:latest
68+
cache-from: type=registry,ref=gcr.io/${{ vars.GCP_PROJECT_ID }}/${{ env.SERVICE }}:buildcache
69+
cache-to: type=registry,ref=gcr.io/${{ vars.GCP_PROJECT_ID }}/${{ env.SERVICE }}:buildcache,mode=max
70+
71+
- name: Deploy to Cloud Run
72+
id: deploy
73+
uses: google-github-actions/deploy-cloudrun@v2
74+
with:
75+
job: ${{ env.SERVICE }}
76+
region: ${{ env.REGION }}
77+
image: gcr.io/${{ vars.GCP_PROJECT_ID }}/${{ env.SERVICE }}
78+
79+
# If required, use the Cloud Run url output in later steps
80+
- name: Show Output
81+
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)