Skip to content

Commit 14ef21b

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

File tree

4 files changed

+131
-189
lines changed

4 files changed

+131
-189
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: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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+
pipx install tox
65+
66+
- name: Set up Docker Buildx
67+
uses: docker/setup-buildx-action@v3
68+
with:
69+
# network=host driver-opt needed to push to local registry
70+
driver-opts: network=host
71+
buildkitd-flags: --debug
72+
73+
- name: Run tox -e ee
74+
shell: bash
75+
run: tox -e ee
76+
77+
- name: Push the built image to ${{ inputs.registry }} by digest for ${{ matrix.platform }}
78+
id: push-final
79+
if: inputs.push == 'true'
80+
uses: docker/build-push-action@v6
81+
with:
82+
context: ${{ github.workspace }}/final
83+
provenance: false
84+
file: ${{ github.workspace }}/final/Containerfile
85+
build-contexts: |
86+
${{ inputs.final_image }}-base=docker-image://localhost:5000/${{ inputs.final_image }}-base:latest
87+
platforms: ${{ matrix.platform }}
88+
outputs: type=image,name=${{ inputs.registry }}/${{ inputs.namespace }}/${{ inputs.final_image }},push-by-digest=true,name-canonical=true,push=true
89+
90+
- name: Export digest
91+
if: inputs.push == 'true'
92+
shell: bash
93+
run: |
94+
rm -rf /tmp/digests
95+
mkdir -p /tmp/digests
96+
digest="${{ steps.push-final.outputs.digest }}"
97+
touch "/tmp/digests/${digest#sha256:}"
98+
99+
- name: Upload digest
100+
if: inputs.push == 'true'
101+
uses: actions/upload-artifact@v4
102+
with:
103+
name: digests-${{ env.PLATFORM_PAIR }}
104+
path: /tmp/digests/*
105+
if-no-files-found: error
106+
retention-days: 1
107+
108+
# this step is ONLY needed for maintainence of self hosted runners
109+
- name: Cleanup docker
110+
shell: bash
111+
if: always()
112+
run: |
113+
docker system prune -af --volumes

.github/workflows/tox.yml

Lines changed: 11 additions & 49 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
@@ -110,8 +72,8 @@ jobs:
11072
pypi:
11173
name: Publish to PyPI registry
11274
needs:
113-
- build-image
114-
- tox
75+
- ee
76+
# - tox
11577
if: github.event_name == 'release' && github.event.action == 'published'
11678
environment: release # approval
11779
runs-on: ubuntu-22.04

tox.ini

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package = editable
1818
extras =
1919
test
2020
pass_env =
21+
ADT_CONTAINER_ENGINE
2122
CI
2223
CONTAINER_*
2324
DOCKER_*
@@ -111,20 +112,22 @@ commands =
111112
python -m build --outdir {toxinidir}/dist/ {toxinidir}
112113
sh -c "python -m twine check --strict {toxinidir}/dist/*"
113114

114-
[testenv:image]
115+
[testenv:ee]
115116
description =
116-
Build the container image
117+
Build and tests the execution environmwent (ee) container image
117118
skip_install = true
118119
deps =
119120
ansible-builder
121+
; docker-squash
120122
build
121123
setuptools # https://github.com/ansible/ansible-builder/issues/644
122124
commands_pre =
123125
commands =
124126
python -m build --outdir {toxinidir}/final/dist/ --wheel {toxinidir}
125127
ansible-builder create -f execution-environment.yml --output-filename Containerfile -v3
126-
podman build --squash-all context/ --tag community-ansible-dev-tools-base:latest
127-
podman build --squash-all final/ --tag community-ansible-dev-tools:test
128+
{env:ADT_CONTAINER_ENGINE:podman} build --squash-all context/ --tag community-ansible-dev-tools-base:latest
129+
{env:ADT_CONTAINER_ENGINE:podman} build --squash-all final/ --tag community-ansible-dev-tools:test
130+
; docker-squash ${{ inputs.namespace }}/${{ inputs.final_image }}:test
128131
pytest --only-container --image-name community-ansible-dev-tools:test
129132
allowlist_externals =
130133
podman

0 commit comments

Comments
 (0)