feat(docker): add the docker role (#522)
Extracted from the environment repository, wave 1. Scrubbed of private references: namespace mortis, no repository paths or issue numbers in comments and docs, the removed docker_ufw_rules guard dropped, the molecule scenario uses the FQCN and no provisioner environment overrides. ansible-lint mocks the role's FQCN because CI checks the Collection out outside an ansible_collections path. Verified: the commit hooks. Not verified: the molecule scenario (CI only). Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MmzvM9skAvYcph2c9EiPcm
This commit is contained in:
1 parent
903a1a2e5a
commit
aad59fc339
17 files changed
+774
No files matched your search
+101
@@ -0,0 +1,101 @@
|
||||
#!/bin/bash
|
||||
# Builds the signed APT repository the docker scenario installs from, so the role's own key,
|
||||
# source-line and package tasks run for real without the real Docker Engine.
|
||||
#
|
||||
# build-stub-repo.sh <repo-root> <codename> <work-dir>
|
||||
#
|
||||
# The repository holds empty stand-ins for docker-ce, docker-ce-cli and containerd.io (the
|
||||
# default docker_packages). docker-ce ships a stub docker.service and a postinst that creates
|
||||
# the docker group, as the real package does. The Release file is signed with a throwaway key
|
||||
# generated here; the matching public key is exported to <repo-root>/docker.asc, which is what
|
||||
# the role fetches as its keyring. The secret key stays in <work-dir> and is never installed.
|
||||
set -euo pipefail
|
||||
|
||||
repo=${1:?usage: build-stub-repo.sh <repo-root> <codename> <work-dir>}
|
||||
codename=${2:?usage: build-stub-repo.sh <repo-root> <codename> <work-dir>}
|
||||
work=${3:?usage: build-stub-repo.sh <repo-root> <codename> <work-dir>}
|
||||
version=0.0.1~molecule
|
||||
|
||||
rm -rf "$repo" "$work"
|
||||
mkdir -p "$repo/pool" "$repo/dists/$codename/stable/binary-amd64" "$work/gnupg" "$work/pkg"
|
||||
chmod 0700 "$work/gnupg"
|
||||
|
||||
build_deb() {
|
||||
local name=$1 tree="$work/pkg/$1"
|
||||
mkdir -p "$tree/DEBIAN"
|
||||
cat > "$tree/DEBIAN/control" <<CONTROL
|
||||
Package: $name
|
||||
Version: $version
|
||||
Architecture: all
|
||||
Maintainer: Molecule <molecule@invalid>
|
||||
Description: stand-in for $name in the docker role's molecule scenario
|
||||
Empty package. It installs nothing from Docker.
|
||||
CONTROL
|
||||
if [ "$name" = docker-ce ]; then
|
||||
mkdir -p "$tree/usr/lib/systemd/system"
|
||||
cat > "$tree/usr/lib/systemd/system/docker.service" <<'UNIT'
|
||||
[Unit]
|
||||
Description=Stand-in for the Docker Engine (molecule)
|
||||
|
||||
[Service]
|
||||
ExecStart=/bin/sleep infinity
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
UNIT
|
||||
cat > "$tree/DEBIAN/postinst" <<'POSTINST'
|
||||
#!/bin/sh
|
||||
set -e
|
||||
if [ "$1" = configure ]; then
|
||||
getent group docker > /dev/null || groupadd --system docker
|
||||
systemctl daemon-reload || true
|
||||
fi
|
||||
POSTINST
|
||||
chmod 0755 "$tree/DEBIAN/postinst"
|
||||
fi
|
||||
dpkg-deb --root-owner-group --build "$tree" "$repo/pool/${name}_${version}_all.deb" > /dev/null
|
||||
}
|
||||
|
||||
for name in docker-ce docker-ce-cli containerd.io; do
|
||||
build_deb "$name"
|
||||
done
|
||||
|
||||
index="$repo/dists/$codename/stable/binary-amd64/Packages"
|
||||
: > "$index"
|
||||
for deb in "$repo"/pool/*.deb; do
|
||||
{
|
||||
dpkg-deb --field "$deb"
|
||||
echo "Filename: pool/$(basename "$deb")"
|
||||
echo "Size: $(stat --format %s "$deb")"
|
||||
echo "SHA256: $(sha256sum "$deb" | cut -d' ' -f1)"
|
||||
echo
|
||||
} >> "$index"
|
||||
done
|
||||
|
||||
release="$repo/dists/$codename/Release"
|
||||
{
|
||||
echo "Origin: molecule-stub"
|
||||
echo "Label: molecule-stub"
|
||||
echo "Suite: $codename"
|
||||
echo "Codename: $codename"
|
||||
echo "Date: $(LC_ALL=C date -u '+%a, %d %b %Y %H:%M:%S UTC')"
|
||||
echo "Architectures: amd64"
|
||||
echo "Components: stable"
|
||||
echo "SHA256:"
|
||||
echo " $(sha256sum "$index" | cut -d' ' -f1) $(stat --format %s "$index") stable/binary-amd64/Packages"
|
||||
} > "$release"
|
||||
|
||||
export GNUPGHOME="$work/gnupg"
|
||||
gpg --batch --quiet --pinentry-mode loopback --passphrase '' \
|
||||
--quick-generate-key 'molecule stub repository <molecule@invalid>' rsa2048 sign never
|
||||
gpg --batch --quiet --yes --armor --export > "$repo/docker.asc"
|
||||
gpg --batch --quiet --yes --pinentry-mode loopback --passphrase '' --clearsign \
|
||||
--output "$repo/dists/$codename/InRelease" "$release"
|
||||
gpg --batch --quiet --yes --pinentry-mode loopback --passphrase '' --armor --detach-sign \
|
||||
--output "$repo/dists/$codename/Release.gpg" "$release"
|
||||
|
||||
# The _apt user reads the repository during apt update.
|
||||
chmod -R a+rX "$repo"
|
||||
|
||||
# Stop the gpg-agent that gpg started, so it does not outlive the script.
|
||||
gpgconf --kill gpg-agent || true
|
||||
Reference in new issue
Block a user