Ansible: deliver validator-agent from the artreg registry instead of building on each host
The role resolves image_tag to a digest once per run and pulls that image on every validator before replacing the container; the git and build steps are gone. scripts/publish-agent-image.sh builds and pushes the agent image (<rev12> and latest tags). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
65c6975a24
commit
d0ab6b94f9
16 files changed
+323
-238
No files matched your search
@@ -74,29 +74,57 @@
|
||||
when: (env_missing_vars | from_json) | length > 0
|
||||
run_once: true
|
||||
|
||||
# Тег переводится в digest один раз за весь прогон (не на каждую волну):
|
||||
# результат хранится в фактах localhost. Задать вручную: -e image_digest=sha256:...
|
||||
# GET безопасен и в --check, поэтому check_mode отключён.
|
||||
- name: Look up the image manifest in the registry
|
||||
ansible.builtin.uri:
|
||||
url: "https://{{ registry }}/v2/{{ image_repo }}/manifests/{{ image_tag }}"
|
||||
method: GET
|
||||
headers:
|
||||
Accept: "application/vnd.docker.distribution.manifest.v2+json, application/vnd.oci.image.manifest.v1+json, application/vnd.docker.distribution.manifest.list.v2+json, application/vnd.oci.image.index.v1+json"
|
||||
status_code: 200
|
||||
return_content: false
|
||||
delegate_to: localhost
|
||||
become: false
|
||||
run_once: true
|
||||
check_mode: false
|
||||
register: manifest
|
||||
when:
|
||||
- image_digest is not defined
|
||||
- hostvars['localhost'].image_digest is not defined
|
||||
|
||||
- name: Remember the image digest
|
||||
ansible.builtin.set_fact:
|
||||
image_digest: "{{ manifest.docker_content_digest | default('') }}"
|
||||
delegate_to: localhost
|
||||
delegate_facts: true
|
||||
become: false
|
||||
run_once: true
|
||||
when:
|
||||
- image_digest is not defined
|
||||
- hostvars['localhost'].image_digest is not defined
|
||||
|
||||
- name: Check the image digest
|
||||
ansible.builtin.assert:
|
||||
that: resolved_digest is match('^sha256:[0-9a-f]{64}$')
|
||||
fail_msg: >-
|
||||
Не удалось получить digest для {{ registry }}/{{ image_repo }}:{{ image_tag }}.
|
||||
Проверьте, что тег опубликован (scripts/publish-agent-image.sh).
|
||||
quiet: true
|
||||
run_once: true
|
||||
|
||||
- name: Report the image to deploy
|
||||
ansible.builtin.debug:
|
||||
msg: "Образ: {{ registry }}/{{ image_repo }}:{{ image_tag }} -> {{ resolved_digest }}"
|
||||
run_once: true
|
||||
|
||||
# --- на каждом валидаторе -----------------------------------------------
|
||||
- name: Check that Docker answers
|
||||
ansible.builtin.command: docker version --format {% raw %}'{{.Server.Version}}'{% endraw %}
|
||||
changed_when: false
|
||||
check_mode: false
|
||||
|
||||
- name: Check that git is installed
|
||||
ansible.builtin.command: git --version
|
||||
changed_when: false
|
||||
check_mode: false
|
||||
|
||||
- name: Check that the git clone exists
|
||||
ansible.builtin.stat:
|
||||
path: "{{ repo_dir }}/.git"
|
||||
check_mode: false
|
||||
register: clone_stat
|
||||
|
||||
- name: Fail without a clone
|
||||
ansible.builtin.assert:
|
||||
that: clone_stat.stat.exists
|
||||
fail_msg: "Нет git-клона {{ repo_dir }} на {{ inventory_hostname }}."
|
||||
quiet: true
|
||||
|
||||
- name: Read the CPU architecture
|
||||
ansible.builtin.command: uname -m
|
||||
changed_when: false
|
||||
@@ -141,7 +169,7 @@
|
||||
{%- set found = [] -%}
|
||||
{%- for line in all_containers.stdout_lines -%}
|
||||
{%- set row = line.split('|') -%}
|
||||
{%- if row[0] != container_name and ('validator-agent' in row[0] or row[1] == image_name or row[1].startswith(image_name ~ ':')) -%}
|
||||
{%- if row[0] != container_name and ('validator-agent' in row[0] or row[1] == legacy_image_name or row[1].startswith(legacy_image_name ~ ':') or row[1].startswith(registry ~ '/' ~ image_repo)) -%}
|
||||
{%- set _ = found.append(row[0] ~ ' (' ~ row[1] ~ ')') -%}
|
||||
{%- endif -%}
|
||||
{%- endfor -%}
|
||||
|
||||
Reference in new issue
Block a user