Skip to content

Commit 7eb6318

Browse files
author
Edward Thomson
committed
reusable
1 parent cf75403 commit 7eb6318

File tree

2 files changed

+73
-60
lines changed

2 files changed

+73
-60
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Generate the containers that we use for builds.
2+
name: Build Containers
3+
4+
on:
5+
workflow_call:
6+
7+
env:
8+
docker-registry: ghcr.io
9+
docker-config-path: source/ci/docker
10+
11+
jobs:
12+
# Build the docker container images that we will use for our Linux
13+
# builds. This will identify the last commit to the repository that
14+
# updated the docker images, and try to download the image tagged with
15+
# that sha. If it does not exist, we'll do a docker build and push
16+
# the image up to GitHub Packages for the actual CI/CD runs. We tag
17+
# with both the sha and "latest" so that the subsequent runs need not
18+
# know the sha. Only do this on CI builds (when the event is a "push")
19+
# because PR builds from forks lack permission to write packages.
20+
containers:
21+
strategy:
22+
matrix:
23+
container:
24+
- name: xenial
25+
- name: bionic
26+
- name: focal
27+
- name: docurium
28+
- name: bionic-x86
29+
dockerfile: bionic
30+
base: multiarch/ubuntu-core:x86-bionic
31+
qemu: true
32+
- name: bionic-arm32
33+
dockerfile: bionic
34+
base: multiarch/ubuntu-core:armhf-bionic
35+
qemu: true
36+
- name: bionic-arm64
37+
dockerfile: bionic
38+
base: multiarch/ubuntu-core:arm64-bionic
39+
qemu: true
40+
- name: centos7
41+
- name: centos8
42+
runs-on: ubuntu-latest
43+
name: "Create container: ${{ matrix.container.name }}"
44+
steps:
45+
- name: Check out repository
46+
uses: actions/checkout@v3
47+
with:
48+
path: source
49+
fetch-depth: 0
50+
if: github.event_name != 'pull_request'
51+
- name: Setup QEMU
52+
run: docker run --rm --privileged multiarch/qemu-user-static:register --reset
53+
if: matrix.container.qemu == true
54+
- name: Download existing container
55+
run: |
56+
"${{ github.workspace }}/source/ci/getcontainer.sh" "${{ matrix.container.name }}" "${{ matrix.container.dockerfile }}"
57+
env:
58+
DOCKER_REGISTRY: ${{ env.docker-registry }}
59+
GITHUB_TOKEN: ${{ secrets.github_token }}
60+
working-directory: ${{ env.docker-config-path }}
61+
if: github.event_name != 'pull_request'
62+
- name: Build and publish image
63+
run: |
64+
if [ "${{ matrix.container.base }}" != "" ]; then
65+
BASE_ARG="--build-arg BASE=${{ matrix.container.base }}"
66+
fi
67+
docker build -t ${{ env.docker-registry-container-sha }} --build-arg UID=$(id -u) --build-arg GID=$(id -g) ${BASE_ARG} -f ${{ env.dockerfile }} .
68+
docker tag ${{ env.docker-registry-container-sha }} ${{ env.docker-registry-container-latest }}
69+
docker push ${{ env.docker-registry-container-sha }}
70+
docker push ${{ env.docker-registry-container-latest }}
71+
working-directory: ${{ env.docker-config-path }}
72+
if: github.event_name != 'pull_request' && env.docker-container-exists != 'true'

.github/workflows/main.yml

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -14,67 +14,8 @@ env:
1414
docker-config-path: source/ci/docker
1515

1616
jobs:
17-
# Build the docker container images that we will use for our Linux
18-
# builds. This will identify the last commit to the repository that
19-
# updated the docker images, and try to download the image tagged with
20-
# that sha. If it does not exist, we'll do a docker build and push
21-
# the image up to GitHub Packages for the actual CI/CD runs. We tag
22-
# with both the sha and "latest" so that the subsequent runs need not
23-
# know the sha. Only do this on CI builds (when the event is a "push")
24-
# because PR builds from forks lack permission to write packages.
2517
containers:
26-
strategy:
27-
matrix:
28-
container:
29-
- name: xenial
30-
- name: bionic
31-
- name: focal
32-
- name: docurium
33-
- name: bionic-x86
34-
dockerfile: bionic
35-
base: multiarch/ubuntu-core:x86-bionic
36-
qemu: true
37-
- name: bionic-arm32
38-
dockerfile: bionic
39-
base: multiarch/ubuntu-core:armhf-bionic
40-
qemu: true
41-
- name: bionic-arm64
42-
dockerfile: bionic
43-
base: multiarch/ubuntu-core:arm64-bionic
44-
qemu: true
45-
- name: centos7
46-
- name: centos8
47-
runs-on: ubuntu-latest
48-
name: "Create container: ${{ matrix.container.name }}"
49-
steps:
50-
- name: Check out repository
51-
uses: actions/checkout@v3
52-
with:
53-
path: source
54-
fetch-depth: 0
55-
if: github.event_name != 'pull_request'
56-
- name: Setup QEMU
57-
run: docker run --rm --privileged multiarch/qemu-user-static:register --reset
58-
if: matrix.container.qemu == true
59-
- name: Download existing container
60-
run: |
61-
"${{ github.workspace }}/source/ci/getcontainer.sh" "${{ matrix.container.name }}" "${{ matrix.container.dockerfile }}"
62-
env:
63-
DOCKER_REGISTRY: ${{ env.docker-registry }}
64-
GITHUB_TOKEN: ${{ secrets.github_token }}
65-
working-directory: ${{ env.docker-config-path }}
66-
if: github.event_name != 'pull_request'
67-
- name: Build and publish image
68-
run: |
69-
if [ "${{ matrix.container.base }}" != "" ]; then
70-
BASE_ARG="--build-arg BASE=${{ matrix.container.base }}"
71-
fi
72-
docker build -t ${{ env.docker-registry-container-sha }} --build-arg UID=$(id -u) --build-arg GID=$(id -g) ${BASE_ARG} -f ${{ env.dockerfile }} .
73-
docker tag ${{ env.docker-registry-container-sha }} ${{ env.docker-registry-container-latest }}
74-
docker push ${{ env.docker-registry-container-sha }}
75-
docker push ${{ env.docker-registry-container-latest }}
76-
working-directory: ${{ env.docker-config-path }}
77-
if: github.event_name != 'pull_request' && env.docker-container-exists != 'true'
18+
uses: ./.github/workflows/build-containers.yml
7819

7920
# Run our CI/CD builds. We build a matrix with the various build targets
8021
# and their details. Then we build either in a docker container (Linux)

0 commit comments

Comments
 (0)