ci(molecule): run the in-image step from a tested script and list the fifth pin file
Assisted-by: Claude Code
This commit is contained in:
1 parent
2e32016c43
commit
8c52c91dfd
8 files changed
+215
-46
No files matched your search
@@ -11,12 +11,11 @@ name: Molecule
|
||||
# own workflow file. So the repository does not accept fork pull requests; the real
|
||||
# condition is that only trusted people can push branches or open pull requests here.
|
||||
#
|
||||
# molecule runs in the pinned ci image, started with `docker run` and the runner's Docker socket,
|
||||
# so the scenario containers it creates run beside it on the runner's daemon; the job tree is
|
||||
# mounted at the same path, so paths molecule hands the daemon resolve. Like Lint and Build, the
|
||||
# job compares the pin files with the image and installs the pull request's pins when they differ.
|
||||
# The test images are pulled by tag and digest (the digest is what is enforced). Bump both here
|
||||
# when image.yml publishes a new ci, molecule-ubuntu2404 or molecule-ubuntu2604 version.
|
||||
# molecule runs in the pinned ci image via `docker run` with the runner's Docker socket, so the
|
||||
# scenario containers start beside it on the runner's daemon; the job tree is mounted at the same
|
||||
# path, so the paths molecule hands the daemon resolve. Like Lint and Build, it installs the pull
|
||||
# request's pins when they differ from the image's. The images are pinned by tag and digest: bump
|
||||
# them here when image.yml publishes a new ci, molecule-ubuntu2404 or molecule-ubuntu2604 version.
|
||||
on: # yamllint disable-line rule:truthy
|
||||
pull_request:
|
||||
branches:
|
||||
@@ -77,7 +76,7 @@ jobs:
|
||||
# `image: ${MOLECULE_IMAGE_2604}` in extensions/molecule/image-smoke-2604.
|
||||
MOLECULE_IMAGE_2604: >-
|
||||
git.rkdr.net/mortis/molecule-ubuntu2604:0.1.6@sha256:d7c216b33d18fa8f1ecbfee8795eb4adc867fe5ad8e7a73b7c67effe301cf771
|
||||
# The container molecule runs in, named by the run so the cleanup step finds it.
|
||||
# The container molecule runs in, named and labelled by the run so the cleanup step finds it.
|
||||
RUN_CONTAINER: kamino-molecule-${{ github.run_id }}-${{ github.run_attempt }}
|
||||
steps:
|
||||
- name: Check the Docker daemon
|
||||
@@ -141,39 +140,12 @@ jobs:
|
||||
sock_gid="$(stat -c %g /var/run/docker.sock)"
|
||||
mkdir -p "$ac_root/home"
|
||||
docker run --rm -i --init --name "$RUN_CONTAINER" \
|
||||
--label "net.rkdr.mortis.molecule-run=$RUN_CONTAINER" \
|
||||
--user "$(id -u):$(id -g)" --group-add "$sock_gid" \
|
||||
-v /var/run/docker.sock:/var/run/docker.sock -v "$ac_root:$ac_root" -w "$PWD" \
|
||||
-e "AC_ROOT=$ac_root" -e "HOME=$ac_root/home" -e "USER=$(id -un)" \
|
||||
-e MOLECULE_IMAGE -e MOLECULE_IMAGE_2604 \
|
||||
"$CI_IMAGE" bash -c "$(cat <<'EOF'
|
||||
set -euo pipefail
|
||||
selected="$(cat)"
|
||||
# The pull request's own pins when they differ from the image's. /opt is not writable for
|
||||
# this user, so they go to the job tree, first on the paths.
|
||||
pins="$AC_ROOT/pins"
|
||||
collections=""
|
||||
if sha256sum --quiet -c /opt/ci-pins.sha256; then
|
||||
echo "The pin files match the ci image; using the baked tools."
|
||||
else
|
||||
echo "::warning::a pin file differs from the ci image; installing the pinned tools and collections for this run."
|
||||
/opt/venv/bin/python -m venv "$pins/venv"
|
||||
"$pins/venv/bin/pip" install --quiet --require-hashes -r requirements-dev.lock -r requirements-dev.txt
|
||||
export PATH="$pins/venv/bin:$PATH"
|
||||
# The target alone on the path, so a baked copy is not taken as already installed.
|
||||
for req in requirements.yml extensions/molecule/requirements.yml; do
|
||||
ANSIBLE_COLLECTIONS_PATH="$pins/collections" \
|
||||
ansible-galaxy collection install --force -r "$req" -p "$pins/collections"
|
||||
done
|
||||
collections="$pins/collections:"
|
||||
fi
|
||||
ansible --version
|
||||
molecule --version
|
||||
# The collection under test first; molecule also installs it into each scenario's
|
||||
# ANSIBLE_HOME, which the run script keeps in the job tree.
|
||||
export ANSIBLE_COLLECTIONS_PATH="$AC_ROOT:$collections/opt/collections"
|
||||
exec scripts/run_molecule_scenarios.sh "$AC_ROOT/molecule-runs" <<< "$selected"
|
||||
EOF
|
||||
)" <<< "$selected"
|
||||
"$CI_IMAGE" scripts/run_molecule_in_ci_image.sh <<< "$selected"
|
||||
|
||||
# A cancelled run can leave the container running when the docker client is killed.
|
||||
- name: Remove the molecule container
|
||||
|
||||
Reference in new issue
Block a user