This repository was archived by the owner on Apr 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
128 lines (110 loc) · 3.72 KB
/
Copy pathbuild.yml
File metadata and controls
128 lines (110 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
name: Build Images & Assets
on:
workflow_call:
pull_request:
env:
# github.sha doesn't always refer to the commit we're running on... which is fucking stupid
# So we have to do this charade
# https://github.com/orgs/community/discussions/25191
SHA: ${{ github.event.pull_request.head.sha || github.sha }}
jobs:
api-build:
name: "API/Build"
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up docker buildx
uses: docker/setup-buildx-action@v2
- name: Docker login
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build & push image
uses: docker/build-push-action@v3
with:
context: ./api/
file: ./api/Dockerfile
tags: ghcr.io/lucaspickering/beta-spray-api:${{ env.SHA }}
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: BUILD_PRODUCTION=true
- name: Build Django static assets
# Use dev settings here so we don't need to load secrets
# It'd be nice to be able to use the built image ID from the previous
# step's output, but that doesn't work because the image gets pushed
# without being exported locally. Should be fixable after:
# https://github.com/moby/buildkit/issues/1555
run: >
docker run
-v $PWD/static:/app/src/static
-e DJANGO_SETTINGS_MODULE=beta_spray.settings.settings_dev
ghcr.io/lucaspickering/beta-spray-api:${{ env.SHA }} ./m.sh collectstatic
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: api-static-assets
path: ./static/
ui-build:
name: "UI/Build"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Cache npm files
uses: actions/cache@v3
with:
path: ui/node_modules
key: ${{ runner.os }}-npm-${{ hashFiles('ui/package-lock.json') }}
- name: Install dependencies
working-directory: ui/
run: npm install
- name: Build
working-directory: ui/
run: NODE_ENV=production npm run build
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: ui-static-assets
path: ./ui/build/
general-upload:
name: "General/Upload"
runs-on: ubuntu-latest
needs:
- api-build
- ui-build
permissions:
contents: read
id-token: write
steps:
# Needed in order to pass auth creds to subsequent steps
- name: Checkout
uses: actions/checkout@v3
- name: Google Cloud auth
uses: google-github-actions/auth@v0
with:
service_account: ${{ secrets.GOOGLE_SERVICE_ACCOUNT }}
workload_identity_provider: ${{ secrets.GOOGLE_WORKLOAD_ID_PROVIDER }}
# Unpack both UI and API assets into the directory structure that we'll
# want in the bucket, so we can upload them all at once
- name: Download UI static assets
uses: actions/download-artifact@v3
with:
name: ui-static-assets
path: ./assets/
- name: Download API static assets
uses: actions/download-artifact@v3
with:
name: api-static-assets
path: ./assets/api-static/
- name: Upload static assets to GCS
uses: google-github-actions/upload-cloud-storage@v0
with:
path: ./assets/
parent: false # Don't include /assets/ in the bucket
destination: beta-spray-static/${{ env.SHA }}/