feat(traefik): add traefik_release_url for a release mirror
The archive and checksums URLs were hardcoded to the GitHub releases. traefik_release_url (default: the GitHub release directory of traefik_version, as before) lets a host download from a mirror. The Molecule scenario uses it: verify's update path now downloads stand-in releases that prepare.yml builds under /opt/molecule-download (a stub binary answering `version`, its archive and a sha256sum checksums file), so it no longer fetches two more real releases per host. The converge still downloads the real release from GitHub, which keeps the default URL proven. traefik_verify_other_version moves to the scenario's group vars so prepare and verify share it. The update path leaves the stub installed, which the README and verify now state. Verify replaces the fixed 15 s pause with a poll (30 x 2 s) for an "Unable to obtain ACME certificate" log line stamped at or after the running process's ExecMainStartTimestamp, so a line left by the process converge restarted does not count. It fails closed on a missing start time, a missing line or an unparseable stamp. It then asserts NRestarts is 0, since Restart=always would hide a crash. Assisted-by: Claude Code:claude-opus-5-5
This commit is contained in:
1 parent
6e3ea4521b
commit
ab0ce421cc
9 files changed
+117
-17
No files matched your search
@@ -2,8 +2,9 @@
|
||||
# Runs on the repository's own runner (label kamino-molecule), in the molecule-ubuntu2404
|
||||
# (MOLECULE_IMAGE) and molecule-ubuntu2604 (MOLECULE_IMAGE_2604) images, pinned in
|
||||
# .gitea/workflows/molecule.yml. Needs outbound network, unlike most scenarios: the role installs
|
||||
# packages with apt and downloads Traefik releases from GitHub. No privileged mode: systemd needs a
|
||||
# writable cgroup and the firewall tools need NET_ADMIN.
|
||||
# packages with apt and the converge downloads the Traefik release from GitHub (verify's update
|
||||
# path uses file:// stand-ins built by prepare.yml). No privileged mode: systemd needs a writable
|
||||
# cgroup and the firewall tools need NET_ADMIN.
|
||||
driver:
|
||||
name: docker
|
||||
platforms:
|
||||
@@ -54,6 +55,9 @@ provisioner:
|
||||
traefik_cloudflare_email: [email protected]
|
||||
traefik_cloudflare_api_token: molecule-not-a-token
|
||||
traefik_domain: example.test
|
||||
# Any release other than the role default: verify's update path goes there and back,
|
||||
# from the stand-ins prepare.yml builds.
|
||||
traefik_verify_other_version: v3.7.18
|
||||
ufw_rules:
|
||||
- {rule: allow, port: 22, proto: tcp, comment: ssh}
|
||||
# TEST-NET-1 address: nothing answers, the value only has to render
|
||||
|
||||
@@ -40,3 +40,55 @@
|
||||
ProtectKernelTunables=no
|
||||
ReadWritePaths=
|
||||
User=
|
||||
|
||||
# Stand-in releases for verify's update path, behind file:// URLs: the role's download, checksum
|
||||
# check and swap run unchanged, without fetching two more real releases per host. The converge
|
||||
# still downloads the real role default from GitHub.
|
||||
- name: Prepare the stand-in releases
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
vars_files:
|
||||
- ../../defaults/main.yml
|
||||
tasks:
|
||||
- name: Create a directory per stand-in release
|
||||
ansible.builtin.file:
|
||||
path: "/opt/molecule-download/{{ traefik_test_release }}"
|
||||
state: directory
|
||||
mode: "0755"
|
||||
loop: ["{{ traefik_verify_other_version }}", "{{ traefik_version }}"]
|
||||
loop_control:
|
||||
loop_var: traefik_test_release
|
||||
|
||||
# Answers `version` like Traefik and otherwise stays up like the service.
|
||||
- name: Write the stand-in binaries
|
||||
ansible.builtin.copy:
|
||||
dest: "/opt/molecule-download/{{ traefik_test_release }}/traefik"
|
||||
mode: "0755"
|
||||
content: |
|
||||
#!/bin/sh
|
||||
case "$1" in
|
||||
version) echo "Version: {{ traefik_test_release | regex_replace('^v', '') }}" ;;
|
||||
*) exec sleep infinity ;;
|
||||
esac
|
||||
loop: ["{{ traefik_verify_other_version }}", "{{ traefik_version }}"]
|
||||
loop_control:
|
||||
loop_var: traefik_test_release
|
||||
|
||||
- name: Pack the stand-in archives
|
||||
ansible.builtin.command:
|
||||
argv: [tar, -czf, "{{ traefik_test_archive }}", -C, "/opt/molecule-download/{{ traefik_test_release }}", traefik]
|
||||
creates: "{{ traefik_test_archive }}"
|
||||
vars:
|
||||
traefik_test_archive: "/opt/molecule-download/{{ traefik_test_release }}/traefik_{{ traefik_test_release }}_{{ traefik_os }}_{{ traefik_arch }}.tar.gz"
|
||||
loop: ["{{ traefik_verify_other_version }}", "{{ traefik_version }}"]
|
||||
loop_control:
|
||||
loop_var: traefik_test_release
|
||||
|
||||
- name: Write the checksums files in the release format
|
||||
ansible.builtin.shell:
|
||||
cmd: sha256sum traefik_*.tar.gz > traefik_{{ traefik_test_release }}_checksums.txt
|
||||
chdir: "/opt/molecule-download/{{ traefik_test_release }}"
|
||||
creates: "traefik_{{ traefik_test_release }}_checksums.txt"
|
||||
loop: ["{{ traefik_verify_other_version }}", "{{ traefik_version }}"]
|
||||
loop_control:
|
||||
loop_var: traefik_test_release
|
||||
@@ -5,6 +5,7 @@
|
||||
vars:
|
||||
traefik_update: true
|
||||
traefik_version: "{{ traefik_verify_target }}"
|
||||
traefik_release_url: "file:///opt/molecule-download/{{ traefik_verify_target }}"
|
||||
|
||||
- name: Read the Traefik version after the update to {{ traefik_verify_target }}
|
||||
ansible.builtin.command: /usr/local/bin/traefik version
|
||||
|
||||
@@ -107,13 +107,40 @@
|
||||
name: traefik
|
||||
register: traefik_unit
|
||||
|
||||
- name: Let the ACME failures against the dummy credentials play out
|
||||
ansible.builtin.pause:
|
||||
seconds: 15
|
||||
# The dummy credentials make the ACME request fail, logged as "Unable to obtain ACME certificate
|
||||
# for domain(s)". The log keeps the lines of the process converge restarted, so only a line
|
||||
# stamped (RFC 3339, first field) since the running process started counts.
|
||||
- name: Wait until the running Traefik has logged the ACME failure
|
||||
ansible.builtin.shell:
|
||||
executable: /bin/bash
|
||||
cmd: |
|
||||
set -euo pipefail
|
||||
started=$(systemctl show --timestamp=unix -P ExecMainStartTimestamp traefik)
|
||||
if [[ ! $started =~ ^@[0-9]+$ ]]; then
|
||||
echo "no start time for traefik: '${started}'" >&2
|
||||
exit 1
|
||||
fi
|
||||
last=$(grep 'Unable to obtain ACME certificate' /etc/traefik/logs/traefik.log | tail -n 1 | cut -d ' ' -f 1) || true
|
||||
# Fails closed: a missing line, an unparseable stamp or an older one all end in exit 1.
|
||||
if [ -n "$last" ] && stamp=$(date -d "$last" +%s) && [ "$stamp" -ge "${started#@}" ]; then
|
||||
exit 0
|
||||
fi
|
||||
echo "no ACME failure logged since Traefik started at ${started} (last: ${last:-none})" >&2
|
||||
exit 1
|
||||
register: traefik_acme_failure
|
||||
changed_when: false
|
||||
until: traefik_acme_failure.rc == 0
|
||||
retries: 30
|
||||
delay: 2
|
||||
|
||||
- name: Read the service state after the wait
|
||||
- name: Read the service state after the ACME failure
|
||||
ansible.builtin.service_facts:
|
||||
|
||||
- name: Read the restart count after the ACME failure
|
||||
ansible.builtin.systemd:
|
||||
name: traefik
|
||||
register: traefik_unit_after_acme
|
||||
|
||||
- name: The pinned version is installed
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
@@ -224,6 +251,8 @@
|
||||
that:
|
||||
- ansible_facts.services['traefik.service'].state == 'running'
|
||||
- ansible_facts.services['traefik.service'].status == 'enabled'
|
||||
# Restart=always would hide a crash on the ACME failure from the state above.
|
||||
- traefik_unit_after_acme.status.NRestarts == '0'
|
||||
- traefik_unit.status.NoNewPrivileges == 'yes'
|
||||
- traefik_unit.status.MemoryDenyWriteExecute == 'yes'
|
||||
- "'cap_net_bind_service' in traefik_unit.status.AmbientCapabilities | lower"
|
||||
@@ -264,17 +293,15 @@
|
||||
traefik_ufw_key_443: "{{ ('allow|443|||||in' | hash('sha1'))[:10] }}"
|
||||
traefik_ufw_tagged: "{{ traefik_ufw_added.stdout_lines | select('match', '^ufw ') | select('search', 'ansible-ufw') | list }}"
|
||||
|
||||
# A real version bump through the update path and mortis.kamino._binary_update: down to another
|
||||
# release and back to the role default, both with traefik_update. After the idempotence step,
|
||||
# because each run changes the binary, and before the remove path, which deletes it.
|
||||
- name: Verify the update path with real Traefik releases
|
||||
# A version bump through the update path and mortis.kamino._binary_update: down to another
|
||||
# release and back to the role default, both with traefik_update, from prepare.yml's stand-ins.
|
||||
# After the idempotence step, because each run changes the binary, and before the remove path.
|
||||
# It leaves the stand-in stub installed, so nothing after it may assert real Traefik behaviour.
|
||||
- name: Verify the update path with stand-in releases
|
||||
hosts: all
|
||||
gather_facts: false
|
||||
vars_files:
|
||||
- ../../defaults/main.yml
|
||||
vars:
|
||||
# Any published release other than the role default, with a checksum file.
|
||||
traefik_verify_other_version: v3.7.18
|
||||
tasks:
|
||||
- name: The other release differs from the role default
|
||||
ansible.builtin.assert:
|
||||
|
||||
Reference in new issue
Block a user