This repository has been archived by the owner on Apr 2, 2024. It is now read-only.
generated from AMRC-FactoryPlus/acs-template
-
Notifications
You must be signed in to change notification settings - Fork 0
152 lines (133 loc) · 4.47 KB
/
build-pull-request.yml
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
name: Build
on:
pull_request:
branches:
- 'v1-stable'
- 'main'
jobs:
# Check
check:
name: Ensure Latest
runs-on: ubuntu-latest
steps:
- name: Git checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Check if branch is ahead of v1-stable
run: |
if ! git merge-base --is-ancestor origin/v1-stable ${{ github.event.pull_request.head.sha }};
then echo "This branch is not up to date with v1-stable. Skipping build to save resources.";
exit 1; fi
# Backend
# Build the backend first, which includes the frontend layers at the beginning. We then build the frontend which will
# immediately build from the cache in the backend layers but without the bloat of the backend layers.
build:
name: Build
needs: check
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log into registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/amrc-factoryplus/acs-manager
- name: Check Backend Builder
id: check-backend-builder
run: |
docker manifest inspect ghcr.io/amrc-factoryplus/acs-manager:backend-build-1.1.0 || echo "needs-build=true" >> $GITHUB_OUTPUT
- name: Build Backend Builder
id: build-backend-builder
if: steps.check-backend-builder.outputs.needs-build == 'true'
uses: docker/build-push-action@v4
with:
context: .
file: ./.docker/Dockerfiles/Dockerfile.backend-build
push: true
tags: ghcr.io/amrc-factoryplus/acs-manager:backend-build-1.1.0
- name: Check Backend Base
id: check-backend-base
run: |
docker manifest inspect ghcr.io/amrc-factoryplus/acs-manager:prod-base-php82-1.0.6 || echo "needs-build=true" >> $GITHUB_OUTPUT
- name: Build Backend Base
id: build-backend-base
if: steps.check-backend-base.outputs.needs-build == 'true'
uses: docker/build-push-action@v4
with:
context: .
file: ./.docker/Dockerfiles/Dockerfile.backend-base
push: true
tags: ghcr.io/amrc-factoryplus/acs-manager:prod-base-php82-1.0.6
- name: Build Backend
id: build-backend
uses: docker/build-push-action@v4
with:
context: .
file: ./.docker/Dockerfiles/Dockerfile
load: true
tags: ${{ steps.meta.outputs.tags }}-backend
labels: ${{ steps.meta.outputs.labels }}
outputs: type=docker,dest=/tmp/image.tar
- name: Upload Backend
uses: actions/upload-artifact@v2
with:
name: ${{ github.event.number }}
path: /tmp/image.tar
- name: Build & Push Frontend
id: build-and-push-frontend
uses: docker/build-push-action@v4
with:
context: .
push: true
file: ./.docker/Dockerfiles/Dockerfile
target: production-frontend
tags: ${{ steps.meta.outputs.tags }}-frontend
labels: ${{ steps.meta.outputs.labels }}
push-backend:
name: Push Backend
runs-on: ubuntu-latest
needs: build
permissions:
contents: read
packages: write
id-token: write
pull-requests: write
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to GitHub container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/amrc-factoryplus/acs-manager
- name: Download artifact
uses: actions/download-artifact@v2
with:
name: ${{ github.event.number }}
path: /tmp
- name: Load and push image
run: |
docker load --input /tmp/image.tar
docker image ls -a
docker push ${{ steps.meta.outputs.tags }}-backend