Skip to content

Commit 4ce90fa

Browse files
committed
ci: implement auto-deploy
1 parent 583239c commit 4ce90fa

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

.github/workflows/publish.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Build and Deploy to Cloud Run
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
7+
env:
8+
PROJECT_ID: ${{vars.PROJECT_ID}}
9+
GAR_LOCATION: ${{vars.GAR_LOCATION}}
10+
SERVICE: ${{vars.SERVICE}}
11+
SERVICENAME: ${{vars.SERVICENAME}}
12+
REGION: ${{vars.REGION}}
13+
14+
jobs:
15+
deploy:
16+
permissions:
17+
contents: 'read'
18+
id-token: 'write'
19+
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v2
24+
25+
- name: Google Auth
26+
id: auth
27+
uses: 'google-github-actions/auth@v0'
28+
with:
29+
token_format: 'access_token'
30+
workload_identity_provider: '${{ vars.WIF_PROVIDER }}'
31+
service_account: '${{ vars.WIF_SERVICE_ACCOUNT }}'
32+
- name: Docker Auth
33+
id: docker-auth
34+
uses: 'docker/login-action@v1'
35+
with:
36+
username: 'oauth2accesstoken'
37+
password: '${{ steps.auth.outputs.access_token }}'
38+
registry: '${{ env.GAR_LOCATION }}-docker.pkg.dev'
39+
40+
- name: Build and Push Container
41+
run: |-
42+
docker build -t "${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}:${{ github.sha }}" ./
43+
docker push "${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}:${{ github.sha }}"
44+
45+
- name: Deploy to Cloud Run
46+
id: deploy
47+
uses: google-github-actions/deploy-cloudrun@v0
48+
with:
49+
service: ${{ env.SERVICENAME }}
50+
region: ${{ env.REGION }}
51+
image: ${{ env.GAR_LOCATION }}-docker.pkg.dev/${{ env.PROJECT_ID }}/${{ env.SERVICE }}:${{ github.sha }}
52+
53+
- name: Show Output
54+
run: echo ${{ steps.deploy.outputs.url }}

dockerfile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM python:3.11
2+
3+
WORKDIR /app
4+
5+
COPY requirements.txt .
6+
7+
RUN pip install --no-cache-dir -r requirements.txt
8+
9+
COPY . .
10+
11+
RUN python3 manage.py migrate
12+
RUN python3 manage.py load_items
13+
14+
EXPOSE 8000
15+
16+
17+
18+
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
django==4.2.13

0 commit comments

Comments
 (0)