-
Notifications
You must be signed in to change notification settings - Fork 1
138 lines (119 loc) · 4.24 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
name: Flux View Build Matrices
on:
# Enable for testing builds for a PR
workflow_dispatch:
pull_request: []
push:
branches:
- main
jobs:
generate:
name: Generate Build Matrix
runs-on: ubuntu-latest
outputs:
dockerbuild_matrix: ${{ steps.dockerbuild.outputs.dockerbuild_matrix }}
empty_matrix: ${{ steps.dockerbuild.outputs.dockerbuild_matrix_empty }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Generate Build Matrix
uses: vsoch/uptodate@main
id: dockerbuild
with:
root: .
parser: dockerbuild
flags: "--registry ghcr.io/converged-computing --all"
- name: View and Check Build Matrix Result
env:
result: ${{ steps.dockerbuild.outputs.dockerbuild_matrix }}
run: |
echo ${result}
if [[ "${result}" == "[]" ]]; then
printf "The matrix is empty, will not trigger next workflow.\n"
else
printf "The matrix is not empty, and we should continue on to the next workflow.\n"
fi
build:
needs: [generate]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
result: ${{ fromJson(needs.generate.outputs.dockerbuild_matrix) }}
arch: [linux/amd64, linux/arm64]
if: ${{ needs.generate.outputs.empty_matrix == 'false' }}
name: Build ${{ matrix.result.container_name }} ${{ matrix.arch }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- uses: actions/setup-go@v3
- name: Add custom buildx ARM builder
if: (matrix.arch == 'linux/arm64')
run: |
docker buildx create --name armbuilder
docker buildx use armbuilder
docker buildx inspect --bootstrap
- name: GHCR Login
if: (github.event_name != 'pull_request')
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
# Uncomment if need more build space
# - name: Run Actions Cleaner
# uses: rse-ops/actions-cleaner/ubuntu@main
- name: Set Container name
env:
container: ${{ matrix.result.container_name }}
run: |
container_name=$(python .github/container_name.py "${container}" flux-view)
echo "Container name is ${container_name}"
echo "container_name=${container_name}" >> $GITHUB_ENV
echo "container_arch=x86_64" >> $GITHUB_ENV
- name: Set Container name
if: (matrix.arch == 'linux/arm64')
env:
container: ${{ matrix.result.container_name }}
run: |
container_name=$(python .github/container_name.py "${container}" flux-view-arm)
echo "Container name is ${container_name}"
echo "container_name=${container_name}" >> $GITHUB_ENV
echo "container_arch=arm" >> $GITHUB_ENV
- name: Pull Docker Layers
run: docker pull ghcr.io/converged-computing/${container_name} || exit 0
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Prepare ${{ env.container_name }}
id: builder
env:
prefix: ${{ matrix.result.command_prefix }}
filename: ${{ matrix.result.filename }}
run: |
basedir=$(dirname $filename)
printf "Base directory is ${basedir}\n"
printf "Building ${container_name}\n"
# Get relative path to PWD and generate dashed name from it
cd $basedir
echo "${prefix} -t ${container_name} ."
build_args="$(echo "${prefix#*--build-arg}")"
# Add build-arg for anaconda download
echo "dockerfile_dir=${basedir}" >> $GITHUB_ENV
echo "build_args=${build_args}" >> $GITHUB_ENV
echo "filename=${filename}" >> $GITHUB_ENV
- name: Build ${{ matrix.dockerfile[1] }}
uses: docker/build-push-action@v3
with:
context: ${{ env.dockerfile_dir }}
file: ${{ env.filename }}
platforms: ${{ matrix.arch }}
push: ${{ github.event_name != 'pull_request' }}
build-args: |
${{ env.build_args }}
ARCH=${{ env.container_arch }}
tags: ${{ env.container_name }}