Skip to content

Commit 2a725c3

Browse files
committed
gha: replace build-test composite action with a reusable workflow
1 parent b73f692 commit 2a725c3

File tree

4 files changed

+181
-185
lines changed

4 files changed

+181
-185
lines changed

.github/actions/build-test/action.yml

Lines changed: 0 additions & 136 deletions
This file was deleted.

.github/workflows/.build-image.yml

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
---
2+
name: Build & Test
3+
# description: Build the final container image and run tests on it
4+
5+
on:
6+
workflow_call:
7+
inputs:
8+
registry:
9+
type: string
10+
description: Target registry to push the final image.
11+
default: ghcr.io
12+
namespace:
13+
description: Namespace of the container image.
14+
default: ansible
15+
type: string
16+
final_image:
17+
description: Name of the final image.
18+
default: community-ansible-dev-tools
19+
type: string
20+
push:
21+
description: If it should push the result of not. Accepts only true / false strings.
22+
default: ${{ github.event_name == 'release' && github.event.action == 'published' }}
23+
type: string
24+
jobs:
25+
build-test:
26+
runs-on: ${{ matrix.builder }}
27+
name: ${{ matrix.name }}
28+
strategy:
29+
fail-fast: false
30+
matrix:
31+
include:
32+
- builder: devtools-multiarch-builder
33+
platform: linux/amd64
34+
name: amd64
35+
- builder: devtools-arm64-runner
36+
platform: linux/arm64
37+
name: arm64
38+
services:
39+
registry:
40+
image: registry:2
41+
ports:
42+
- 5000:5000
43+
44+
steps:
45+
- name: Check out repository
46+
uses: actions/checkout@v4
47+
48+
- name: Login to GitHub Container Registry
49+
uses: docker/login-action@v3
50+
with:
51+
registry: ghcr.io
52+
username: ${{ github.actor }}
53+
password: ${{ secrets.GITHUB_TOKEN }}
54+
55+
- name: Prune docker system
56+
run: sudo ./final/docker-prune.sh
57+
58+
- name: Prepare
59+
shell: bash
60+
run: |
61+
platform=${{ matrix.platform }}
62+
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
63+
sudo apt install -y python3-pip python3-build pipx
64+
65+
- name: Set up Docker Buildx
66+
uses: docker/setup-buildx-action@v3
67+
with:
68+
# network=host driver-opt needed to push to local registry
69+
driver-opts: network=host
70+
buildkitd-flags: --debug
71+
72+
- name: Install or upgrade tools needed for the build and test
73+
shell: bash
74+
id: ansible-builder-install
75+
run: |
76+
set -ex
77+
python3 -m pipx install --force ansible-builder
78+
python3 -m build --outdir final/dist/ --wheel
79+
80+
- name: Create a build context and Containerfile for base EE
81+
shell: bash
82+
run: |
83+
ansible-builder create -f ${{ github.workspace }}/execution-environment.yml --output-filename Containerfile -v3
84+
85+
- name: Build base image for ${{ matrix.platform }}
86+
uses: docker/build-push-action@v6
87+
id: build-base
88+
with:
89+
context: context
90+
provenance: false
91+
file: context/Containerfile
92+
platforms: ${{ matrix.platform }}
93+
push: true
94+
tags: localhost:5000/${{ inputs.final_image }}-base:latest
95+
cache-from: type=gha,scope=build-${{ env.PLATFORM_PAIR }}
96+
cache-to: type=gha,scope=build-${{ env.PLATFORM_PAIR }}
97+
98+
- name: Show available images & base image manifest
99+
shell: bash
100+
run: |
101+
curl -X GET http://localhost:5000/v2/${{ inputs.final_image }}-base/tags/list
102+
docker manifest inspect localhost:5000/${{ inputs.final_image }}-base --insecure -v
103+
104+
- name: Build final image for ${{ matrix.platform }}
105+
id: build-final
106+
uses: docker/build-push-action@v6
107+
env:
108+
DOCKER_BUILD_SUMMARY: "false"
109+
with:
110+
context: ${{ github.workspace }}/final
111+
provenance: false
112+
file: ${{ github.workspace }}/final/Containerfile
113+
load: true
114+
tags: |
115+
${{ inputs.namespace }}/${{ inputs.final_image }}:test
116+
build-contexts: |
117+
${{ inputs.final_image }}-base=docker-image://localhost:5000/${{ inputs.final_image }}-base:latest
118+
platforms: ${{ matrix.platform }}
119+
cache-from: type=gha,scope=build-${{ env.PLATFORM_PAIR }}
120+
cache-to: type=gha,scope=build-${{ env.PLATFORM_PAIR }}
121+
122+
- name: Squash image layers to save disk space
123+
shell: bash
124+
run: |
125+
python3 -m pipx install --force docker-squash
126+
docker-squash ${{ inputs.namespace }}/${{ inputs.final_image }}:test
127+
128+
- name: Run tests against the container
129+
shell: bash
130+
run: |
131+
python3 -m pipx install --force "tox>=4.0.0"
132+
tox -e test-image -- --container-engine docker --image-name ${{ inputs.namespace }}/${{ inputs.final_image }}:test
133+
134+
- name: Push the built image to ${{ inputs.registry }} by digest for ${{ matrix.platform }}
135+
id: push-final
136+
if: inputs.push == 'true'
137+
uses: docker/build-push-action@v6
138+
with:
139+
context: ${{ github.workspace }}/final
140+
provenance: false
141+
file: ${{ github.workspace }}/final/Containerfile
142+
build-contexts: |
143+
${{ inputs.final_image }}-base=docker-image://localhost:5000/${{ inputs.final_image }}-base:latest
144+
platforms: ${{ matrix.platform }}
145+
outputs: type=image,name=${{ inputs.registry }}/${{ inputs.namespace }}/${{ inputs.final_image }},push-by-digest=true,name-canonical=true,push=true
146+
147+
- name: Export digest
148+
if: inputs.push == 'true'
149+
shell: bash
150+
run: |
151+
rm -rf /tmp/digests
152+
mkdir -p /tmp/digests
153+
digest="${{ steps.push-final.outputs.digest }}"
154+
touch "/tmp/digests/${digest#sha256:}"
155+
156+
- name: Upload digest
157+
if: inputs.push == 'true'
158+
uses: actions/upload-artifact@v4
159+
with:
160+
name: digests-${{ env.PLATFORM_PAIR }}
161+
path: /tmp/digests/*
162+
if-no-files-found: error
163+
retention-days: 1
164+
165+
# this step is ONLY needed for maintainence of self hosted runners
166+
- name: Cleanup docker
167+
shell: bash
168+
if: always()
169+
run: |
170+
docker system prune -af --volumes

.github/workflows/tox.yml

Lines changed: 9 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -20,58 +20,17 @@ concurrency:
2020
cancel-in-progress: true
2121

2222
jobs:
23-
tox:
24-
uses: ansible/team-devtools/.github/workflows/tox.yml@main
25-
build-image:
26-
runs-on: ${{ matrix.builder }}
27-
name: ${{ matrix.name }}
28-
# uses same runner for image building, but devspace image builds faster
29-
needs:
30-
- devspaces
31-
services:
32-
registry:
33-
image: registry:2
34-
ports:
35-
- 5000:5000
36-
37-
strategy:
38-
fail-fast: false
39-
matrix:
40-
include:
41-
- builder: devtools-multiarch-builder
42-
platform: linux/amd64
43-
name: amd64
44-
- builder: devtools-arm64-runner
45-
platform: linux/arm64
46-
name: arm64
47-
48-
steps:
49-
- name: Check out repository
50-
uses: actions/checkout@v4
51-
52-
- name: Login to GitHub Container Registry
53-
uses: docker/login-action@v3
54-
with:
55-
registry: ghcr.io
56-
username: ${{ github.actor }}
57-
password: ${{ secrets.GITHUB_TOKEN }}
58-
59-
- name: Prune docker system
60-
run: sudo ./final/docker-prune.sh
61-
62-
- name: Build the container image for ${{ matrix.platform }} and test it
63-
uses: ./.github/actions/build-test
64-
# this needs to be passed only when on release pipeline:
65-
with:
66-
registry: ghcr.io
67-
push: ${{ github.event_name == 'release' && github.event.action == 'published' }}
23+
# tox:
24+
# uses: ansible/team-devtools/.github/workflows/tox.yml@main
25+
ee:
26+
uses: ./.github/workflows/.build-image.yml
6827

6928
publish-image:
7029
environment: release # approval
7130
runs-on: ubuntu-latest
7231
needs:
73-
- build-image
74-
- tox
32+
- ee
33+
# - tox
7534
if: github.event_name == 'release' && github.event.action == 'published'
7635
steps:
7736
- name: Check out repository
@@ -91,6 +50,9 @@ jobs:
9150

9251
devspaces:
9352
runs-on: devtools-multiarch-builder
53+
# uses same runner for image building
54+
needs:
55+
- ee
9456
steps:
9557
- name: Check out repository
9658
uses: actions/checkout@v4

tox.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ commands =
111111
python -m build --outdir {toxinidir}/dist/ {toxinidir}
112112
sh -c "python -m twine check --strict {toxinidir}/dist/*"
113113

114-
[testenv:image]
114+
[testenv:ee]
115115
description =
116-
Build the container image
116+
Build and tests the execution environmwent (ee) container image
117117
skip_install = true
118118
deps =
119119
ansible-builder

0 commit comments

Comments
 (0)