-
Notifications
You must be signed in to change notification settings - Fork 0
140 lines (120 loc) · 4.19 KB
/
build-matrices.yaml
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
name: Docker Build Matrices
# This job generates build matrices using base images built two hours earlier
on:
schedule:
- cron: 0 3 * * *
# On pull request we test updates to images
pull_request: []
# On push to main we build and deploy images
push:
branches:
- main
jobs:
generate:
name: Test Changed Docker Builds
runs-on: ubuntu-latest
outputs:
dockerbuild_matrix: ${{ steps.dockerbuild.outputs.dockerbuild_matrix }}
empty_matrix: ${{ steps.dockerbuild.outputs.dockerbuild_matrix_empty }}
steps:
# START PULL REQUEST / PUSH checkout and file derivation =======================
- uses: actions/checkout@v3
if: github.event_name != 'schedule'
with:
fetch-depth: 0
- name: Get changed files
id: changed-files
if: github.event_name != 'schedule'
uses: tj-actions/changed-files@aa52cfcd81f1a00a6bf1241a8cad6adec4d80638 # v33
with:
separator: " "
- name: Convert changed Dockerfile to uptodate
if: github.event_name != 'schedule'
id: parsed_files
env:
changed_files: ${{ steps.changed-files.outputs.all_changed_files }}
run: /bin/bash .github/scripts/prepare_paths.sh
- name: Generate Build Matrix
if: github.event_name != 'schedule'
uses: vsoch/uptodate@main
id: dockerbuild_pr
with:
root: ${{ steps.parsed_files.outputs.parsed_files }}
parser: dockerbuild
flags: "--registry ghcr.io/llnl --all"
# END PULL REQUEST / PUSH checkout and file derivation =======================
# START SCHEDULED checkout and file derivation =======================
- uses: actions/checkout@v3
if: github.event_name == 'schedule'
with:
fetch-depth: 0
- name: Generate Build Matrix
uses: vsoch/uptodate@main
if: github.event_name == 'schedule'
id: dockerbuild_scheduled
with:
root: .
parser: dockerbuild
flags: "--registry ghcr.io/llnl --all"
# END SCHEDULED checkout and file derivation
- name: View Build Matrix Result
id: dockerbuild
env:
result: ${{ steps.dockerbuild_pr.outputs.dockerbuild_matrix }}
result_scheduled: ${{ steps.dockerbuild_scheduled.outputs.dockerbuild_matrix }}
run: /bin/bash .github/scripts/combine_results.sh
build:
needs:
- generate
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
result: ${{ fromJson(needs.generate.outputs.dockerbuild_matrix) }}
if: ${{ needs.generate.outputs.dockerbuild_matrix != '[]' }}
name: "Build ${{ matrix.result.container_name }}"
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: GHCR Login
if: (github.event_name != 'pull_request')
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ secrets.GHCR_USERNAME }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Make Space For Build
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf /usr/local/lib/android
sudo rm -rf /opt/ghc
sudo rm -rf /opt/hostedtoolcache/CodeQL
sudo docker image prune --all --force
- name: Pull Docker Layers
env:
container: ${{ matrix.result.container_name }}
run: docker pull ${container} || exit 0
- name: Update to relative path
id: relative_path
env:
filename: ${{ matrix.result.filename }}
run: /bin/bash .github/scripts/relative_path.sh
- name: Build ${{ matrix.result.container_name }}
id: builder
env:
container: ${{ matrix.result.container_name }}
prefix: ${{ matrix.result.command_prefix }}
filename: ${{ steps.relative_path.outputs.relative_path }}
run: |
/bin/bash .github/scripts/build_simple.sh || (
res=$?
df -h # In case of out of space, hopefully show *where*
exit $res
)
- name: Deploy Container
if: (github.event_name != 'pull_request')
env:
container: ${{ matrix.result.container_name }}
run: docker push ${container}