Skip to content
This repository was archived by the owner on Aug 26, 2024. It is now read-only.

Commit 4c75986

Browse files
committed
Refactor taskfile
- avoid parametrized recursive call of build step
1 parent 322f61d commit 4c75986

File tree

7 files changed

+54
-26
lines changed

7 files changed

+54
-26
lines changed

.github/workflows/task.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ jobs:
4747
cache: "pip"
4848

4949
- name: Set cache for galaxy
50-
uses: actions/cache@v3
51-
if: "contains(matrix.command, 'build')"
50+
uses: actions/cache@v4
5251
with:
5352
path: |
5453
collections
5554
key: galaxy-${{ hashFiles('_build/requirements.yml') }}
55+
save-always: true
5656

5757
- uses: dorny/paths-filter@v2
5858
id: changes
@@ -62,7 +62,7 @@ jobs:
6262
- 'base/**'
6363
6464
- name: "Run: task base"
65-
if: steps.changes.outputs.base == 'true'
65+
if: steps.changes.outputs.base == 'true' && matrix.command == 'build'
6666
run: task base
6767

6868
- name: "Run: task ${{ matrix.command }}"

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
.task
55
out
66
collections
7+
.creator-base.done
8+
.creator-ee.done

Containerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Overly simplified single stage build process: we take all binary dependencies
22
# using dnf and use pip to install the rest.
33

4-
# this arg must be declared before FROM
5-
ARG EE_BASE_IMAGE=quay.io/ansible/creator-base:latest
4+
# this arg must be declared before FROM, also do not include registry part as
5+
# it seems to confuse podman and make it avoid using locally build base image.
6+
ARG EE_BASE_IMAGE=creator-base:latest
67
FROM $EE_BASE_IMAGE
78
# this arg must be declared after FROM
89
ARG CONTAINER_NAME

Taskfile.yml

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ tasks:
2929
- echo Done {{.VERSION}}!
3030
base:
3131
desc: Build base image
32+
deps:
33+
- setup
3234
sources:
3335
- base/*
34-
- .task/.{{.CNT_NAME}}.done
36+
- .{{.CNT_NAME}}.done
3537
vars: &base-vars
3638
VERSION: "latest"
3739
CNT_NAME: creator-base
@@ -40,24 +42,44 @@ tasks:
4042
CNT_ROOT: base/
4143
RELEASE_PRECHECK: "true"
4244
cmds:
43-
- task: build
44-
vars: *base-vars
45+
- podman container prune -f
46+
- podman manifest exists {{.CNT_NAME_TAG}} && podman manifest rm {{.CNT_NAME_TAG}} || true
47+
- podman image exists {{.CNT_NAME_TAG}} && podman image rm -f {{.CNT_NAME_TAG}} || true
48+
- podman buildx build ${EXTRA_OPTS:---platform=linux/amd64,linux/arm64} --load {{.CNT_ROOT}} --manifest localhost/{{.CNT_NAME_TAG}}
49+
# running manifest exists is mandatory as this fails if no manifest is
50+
# created locally. If this is skipped the inspect might pull the last
51+
# published manifest instead of using the local one.
52+
- podman manifest exists {{.CNT_NAME_TAG}}
53+
# Fail if the manifest does not contain exactly two images
54+
# Validate image
55+
- ./_build/validate {{.CNT_NAME_TAG}}
56+
# Without next step, podman will pull the base image from quay.io instead
57+
# of using the locally built image when we chain: task base && task build
58+
- podman tag localhost/{{.CNT_NAME_TAG}} quay.io/ansible/{{.CNT_NAME}}:latest
59+
- touch .{{.CNT_NAME}}.done
60+
- echo "=== {{.CNT_NAME_TAG}} is ready! ==="
4561
interactive: true
4662
clean:
4763
desc: Clean up all files that not tracked by git
4864
cmds:
4965
- git clean -dxf
66+
# will clean cached images to ensure podman will rebuild containers instead of using a cached result
67+
- podman image prune -f
5068
setup:
5169
desc: Install dependencies
5270
env:
5371
# used inside test-setup.sh
5472
OS: "{{OS}}"
5573
ARCH: "{{ARCH}}"
74+
# needed to avoid warning about installing from galaxy
75+
ANSIBLE_COLLECTIONS_PATH: collections
5676
cmds:
5777
- bash ./_build/test-setup.sh
78+
- ansible-galaxy collection install -r _build/requirements.yml -p collections
5879
sources:
59-
- _build/test-setup.sh
6080
- Taskfile.yml
81+
- _build/requirements.yml
82+
- _build/test-setup.sh
6183
generates:
6284
- out/log/manifest.yml
6385
run: once
@@ -66,13 +88,11 @@ tasks:
6688
desc: Build the project
6789
deps:
6890
- setup
69-
env:
70-
# needed to avoid warning about installing from galaxy
71-
ANSIBLE_COLLECTIONS_PATH: collections
91+
- base
7292
cmds:
73-
- ansible-galaxy collection install -r _build/requirements.yml -p collections
93+
- podman container prune -f
7494
- podman manifest exists {{.CNT_NAME_TAG}} && podman manifest rm {{.CNT_NAME_TAG}} || true
75-
- podman image exists {{.CNT_NAME_TAG}} && podman image rm {{.CNT_NAME_TAG}} || true
95+
- podman image exists {{.CNT_NAME_TAG}} && podman image rm -f {{.CNT_NAME_TAG}} || true
7696
- podman buildx build ${EXTRA_OPTS:---platform=linux/amd64,linux/arm64} --build-arg=CONTAINER_NAME={{.CNT_NAME_TAG}} --load {{.CNT_ROOT}} --manifest {{.CNT_NAME_TAG}}
7797
# running manifest exists is mandatory as this fails if no manifest is
7898
# created locally. If this is skipped the inspect might pull the last
@@ -84,22 +104,22 @@ tasks:
84104
# Without next step, podman will pull the base image from quay.io instead
85105
# of using the locally built image when we chain: task base && task build
86106
- podman tag localhost/{{.CNT_NAME_TAG}} quay.io/ansible/{{.CNT_NAME}}:latest
87-
- touch .task/.{{.CNT_NAME}}.done
107+
- touch .{{.CNT_NAME}}.done
88108
- echo "=== {{.CNT_NAME_TAG}} is ready! ==="
89109
sources:
90110
- Taskfile.yml
91111
- base/*
92112
- _build/*
93113
- Containerfile
94114
generates:
95-
- .task/.{{.CNT_NAME}}.done
115+
- .{{.CNT_NAME}}.done
96116
interactive: true
97117
exec:
98118
desc: Open a container shell
99119
deps:
100120
- build
101121
cmds:
102-
- podman run --rm -it {{.CNT_NAME_TAG}} /bin/bash
122+
- podman run --arch=$(arch) --rm -it {{.CNT_NAME_TAG}} /bin/bash
103123
sources:
104124
- Taskfile.yml
105125
interactive: true

_build/test-setup.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ if [[ "${OS:-}" == "darwin" && "${SKIP_PODMAN:-}" != '1' ]]; then
9191
time podman machine init
9292
time podman machine start
9393
podman info
94-
podman run hello-world
94+
podman run --arch="$(arch)" --rm hello-world
9595
}
9696
fi
9797

@@ -148,6 +148,9 @@ if [[ "${PODMAN_VERSION}" != 'null' ]] && [[ "${SKIP_PODMAN:-}" != '1' ]]; then
148148
echo .
149149
fi
150150
fi
151+
# verify podman ability to execute multi-arch commands:
152+
podman run --arch=arm64 -qit bash arch
153+
podman run --arch=amd64 -qit bash arch
151154

152155
# Create a build manifest so we can compare between builds and machines, this
153156
# also has the role of ensuring that the required executables are present.

_build/validate

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,24 @@ CNT=${1:-quay.io/ansible/creator-ee:latest}
77

88
# creator-base container is expected to have python3
99
if [[ "$CNT" == *"creator-base"* ]]; then
10-
podman run -i "$CNT" python3 --version
10+
podman run --arch="$(arch)" --rm -i "$CNT" python3 --version
1111
exit 0
1212
fi
1313
# Do not use `-t` (interactive) with podman, especially inside scripts/automation as it is
1414
# likely to cause problems.
15-
podman run -i --user="$(id -u)" -e EP_DEBUG=1 "$CNT" uname -a
16-
podman run -i --user="$(id -u)" "$CNT" uname -a
17-
podman run -i --user="$(id -u)" "$CNT" bash -c 'set | grep PATH'
18-
podman run -i --user="$(id -u)" "$CNT" command -v ansible-lint
15+
podman run --arch="$(arch)" --rm -i --user="$(id -u)" -e EP_DEBUG=1 "$CNT" uname -a
16+
podman run --arch="$(arch)" --rm -i --user="$(id -u)" "$CNT" uname -a
17+
podman run --arch="$(arch)" --rm -i --user="$(id -u)" "$CNT" bash -c 'set | grep PATH'
18+
podman run --arch="$(arch)" --rm -i --user="$(id -u)" "$CNT" command -v ansible-lint
1919

2020
# ensure that git is configured to consider any directory safe:
21-
podman run -i --user="$(id -u)" "$CNT" bash -c '[[ $(git config safe.directory) == "/" ]]'
21+
podman run --arch="$(arch)" --rm -i --user="$(id -u)" "$CNT" bash -c '[[ $(git config safe.directory) == "/" ]]'
2222

2323
# Ensure some packages required are present
2424
# navigator requires the rpm db be intact as it runs rpm -qa
25-
podman run -i --user="$(id -u)" "$CNT" bash -c 'rpm -qa | grep python'
25+
podman run --arch="$(arch)" --rm -i --user="$(id -u)" "$CNT" bash -c 'rpm -qa | grep python'
2626
# ansible-runner is needed in all execution environment images
27-
podman run -i --user="$(id -u)" "$CNT" ansible-runner --version
27+
podman run --arch="$(arch)" --rm -i --user="$(id -u)" "$CNT" ansible-runner --version
2828

2929
# ensure that the image is build for both supported architectures and the manifest is correct
3030
podman manifest inspect "$CNT" | jq '.manifests | length' | grep -q "${EXPECTED_IMAGES:-2}"

base/Containerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ podman \
2525
python3 \
2626
python3-bcrypt \
2727
python3-cffi \
28+
# ansible-pylibssh needs:
29+
python3-devel \
2830
python3-markupsafe \
2931
# pypi has binaries with better security:
3032
# python3-cryptography \

0 commit comments

Comments
 (0)