From 5ccfc7f32235b3108c073ef14f553e88c78f2049 Mon Sep 17 00:00:00 2001 From: Matteo Basile Date: Thu, 16 Jul 2026 08:58:32 +0200 Subject: [PATCH] fix --- group_vars/all.yml | 2 +- semaphore_dagster_config.example.yml | 2 +- splash/tasks/main.yml | 60 +++++++++++++++++++++------- undeploy.yml | 5 ++- 4 files changed, 51 insertions(+), 18 deletions(-) diff --git a/group_vars/all.yml b/group_vars/all.yml index de40390..bef8c4b 100644 --- a/group_vars/all.yml +++ b/group_vars/all.yml @@ -4,7 +4,7 @@ registry_url: gitea.dataprovider01.sandbox-cat-dat.simpl-europe.eu repository_name: j.r/application-consumption-demo-algorithm image_tag: optimized image_digest: "sha256:6cc8ab7c08f195cb65c689255418652fdf0094acaaa4ef63475d594039cda2ab" -image_platform: "linux/amd64" +image_platform: "auto" container_image: "{{ registry_url }}/{{ repository_name }}" container_image_ref: "{{ container_image ~ ('@' ~ image_digest if (image_digest | default('') | length > 0) else ':' ~ image_tag) }}" container_name: example-ml-app diff --git a/semaphore_dagster_config.example.yml b/semaphore_dagster_config.example.yml index d6c384a..1da5847 100644 --- a/semaphore_dagster_config.example.yml +++ b/semaphore_dagster_config.example.yml @@ -29,7 +29,7 @@ environment_variables: repository_name: "j.r/application-consumption-demo-algorithm" image_tag: "optimized" image_digest: "sha256:6cc8ab7c08f195cb65c689255418652fdf0094acaaa4ef63475d594039cda2ab" - image_platform: "linux/amd64" + image_platform: "auto" greeting_message: "Hello from SemaphoreUI Demo" enable_health_check: "true" diff --git a/splash/tasks/main.yml b/splash/tasks/main.yml index 5c17e56..653fd1f 100644 --- a/splash/tasks/main.yml +++ b/splash/tasks/main.yml @@ -16,26 +16,56 @@ name: "{{ container_name }}" state: absent -- name: Scarica immagine ML app (platform-aware) - block: - - name: Pull immagine Docker da registry - ansible.builtin.command: >- - docker pull{% if image_platform | default('') | length > 0 %} --platform {{ image_platform }}{% endif %} {{ container_image_ref }} - register: image_pull - changed_when: image_pull.rc == 0 +- name: Calcola platform effettiva + ansible.builtin.set_fact: + effective_image_platform: >- + {{ + (image_platform | default('')) + if (image_platform | default('')) != 'auto' + else + ('linux/amd64' if ansible_architecture in ['x86_64', 'amd64'] + else ('linux/arm64' if ansible_architecture in ['aarch64', 'arm64'] else '')) + }} - rescue: - - name: Errore pull immagine con suggerimenti - ansible.builtin.fail: - msg: >- - Pull fallito per {{ container_image_ref }} su platform {{ image_platform | default('default') }}. - Verifica che il registry pubblichi un manifest compatibile con l'architettura host - (esempio linux/amd64) oppure ricostruisci l'immagine come multi-arch. +- name: Pull immagine primaria (digest o tag) + ansible.builtin.command: >- + docker pull{% if effective_image_platform | length > 0 %} --platform {{ effective_image_platform }}{% endif %} {{ container_image_ref }} + register: primary_pull + changed_when: primary_pull.rc == 0 + failed_when: false + +- name: Fallback pull tramite tag se digest non compatibile + ansible.builtin.command: >- + docker pull{% if effective_image_platform | length > 0 %} --platform {{ effective_image_platform }}{% endif %} {{ container_image }}:{{ image_tag }} + register: fallback_pull + changed_when: fallback_pull.rc == 0 + failed_when: false + when: + - primary_pull.rc != 0 + - image_digest | default('') | length > 0 + +- name: Valida esito pull immagine + ansible.builtin.assert: + that: + - primary_pull.rc == 0 or (fallback_pull is defined and fallback_pull.rc == 0) + fail_msg: >- + Pull fallito sia per {{ container_image_ref }} sia per {{ container_image }}:{{ image_tag }} + su platform {{ effective_image_platform | default('default') }}. + Verifica manifest compatibile con l'architettura host oppure pubblica immagine multi-arch. + +- name: Seleziona riferimento immagine effettivo + ansible.builtin.set_fact: + pulled_image_ref: >- + {{ + container_image_ref + if primary_pull.rc == 0 + else (container_image ~ ':' ~ image_tag) + }} - name: Avvia container ML app community.docker.docker_container: name: "{{ container_name }}" - image: "{{ container_image_ref }}" + image: "{{ pulled_image_ref }}" state: started restart_policy: unless-stopped ports: diff --git a/undeploy.yml b/undeploy.yml index 80aa9d6..98085e0 100644 --- a/undeploy.yml +++ b/undeploy.yml @@ -14,8 +14,11 @@ - name: Rimuovi immagine (opzionale) community.docker.docker_image: - name: "{{ container_image_ref }}" + name: "{{ item }}" state: absent + loop: + - "{{ container_image_ref }}" + - "{{ container_image }}:{{ image_tag }}" when: remove_image | bool - name: Rimuovi directory applicazione