-
Notifications
You must be signed in to change notification settings - Fork 5
75 lines (73 loc) · 2.61 KB
/
Copy pathdocker.yml
File metadata and controls
75 lines (73 loc) · 2.61 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
name: Docker
on:
push:
branches:
- "master"
- "dev"
env:
ENVIRONMENT: ${{ github.ref_name == 'master' && 'prod' || 'staging' }}
IMAGE_NAME: ${{ github.ref_name == 'master' && 'freerooms' || 'freerooms-staging' }}
BRANCH_NAME: ${{ github.base_ref || github.ref_name }}
jobs:
build:
name: "Build (${{ matrix.name }})"
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
context: [backend, frontend]
include:
- context: backend
name: backend
- context: frontend
name: frontend
steps:
- name: Checkout repository
uses: actions/checkout@v7
- name: Set up QEMU
uses: docker/setup-qemu-action@v4
with:
platforms: arm64
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
- name: Create staging .env file
if: ${{ env.BRANCH_NAME == 'dev' && matrix.context == 'frontend' }}
run: echo "NEXT_PUBLIC_STAGING=true" >> .env
working-directory: frontend
- name: Build and push Docker image
uses: docker/build-push-action@v7
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
platforms: linux/amd64
file: ${{ matrix.context }}.dockerfile
tags: |
ghcr.io/devsoc-unsw/${{ env.IMAGE_NAME }}-${{ matrix.name }}:${{ github.sha }}
ghcr.io/devsoc-unsw/${{ env.IMAGE_NAME }}-${{ matrix.name }}:latest
labels: ${{ steps.meta.outputs.labels }}
build-args: |
${{ env.BRANCH_NAME == 'dev' && matrix.context == 'frontend' && 'NEXT_PUBLIC_STAGING=true' || '' }}
deploy:
name: Deploy (CD)
runs-on: ubuntu-latest
needs: [build]
concurrency: staging
if: ${{ github.event_name != 'pull_request' && (github.ref_name == 'dev' || github.ref_name == 'master') }}
steps:
- name: Dispatch deployment
uses: devsoc-unsw/deployment-dispatch-action@main
with:
deployment-dispatcher-app-id: ${{ vars.DEPLOYMENT_DISPATCHER_APP_ID }}
deployment-dispatcher-app-private-key: ${{ secrets.DEPLOYMENT_DISPATCHER_APP_PRIVATE_KEY }}
updates: |
ghcr.io/devsoc-unsw/${{ env.IMAGE_NAME }}-backend=${{ github.sha }}
ghcr.io/devsoc-unsw/${{ env.IMAGE_NAME }}-frontend=${{ github.sha }}