From 008953463f1de9f6e7f71bb76c883580ad4a6b1c Mon Sep 17 00:00:00 2001 From: yohan <783b8c87@scimetis.net> Date: Sun, 9 Jun 2024 10:21:35 +0200 Subject: [PATCH] Use Git commit as tag instead of latest. Remove commit annotation. Reason is Podman cannot be forced to change the annotation to a new Git commit if no image layer changed due to the new commit, even when setting a different image tag for the new build. Prune all unused images. --- tasks/deploy_sensors-polling.yml | 27 ++------------------------- tasks/deploy_thermostat.yml | 27 ++------------------------- 2 files changed, 4 insertions(+), 50 deletions(-) diff --git a/tasks/deploy_sensors-polling.yml b/tasks/deploy_sensors-polling.yml index 5525610..93b77d3 100644 --- a/tasks/deploy_sensors-polling.yml +++ b/tasks/deploy_sensors-polling.yml @@ -25,33 +25,10 @@ - debug: var=build_result when: build_result.changed -- name: Gather facts on sensors-polling container - containers.podman.podman_container_info: - name: sensors-polling - register: container_info - become: true - -- debug: var=container_info.containers[0].Config.Annotations.git_commit - when: container_info.containers | length == 1 - -- name: Set fact bool_recreate to true - set_fact: - bool_recreate: true - when: - - container_info.containers | length == 1 - - container_info.containers[0].Config.Annotations.git_commit != commit - -- name: Delete sensors-polling container - containers.podman.podman_container: - name: sensors-polling - state: absent - become: true - when: bool_recreate | default(false) - - name: Create sensors-polling container containers.podman.podman_container: name: sensors-polling - image: localhost/sensors-polling:latest + image: "localhost/sensors-polling:{{ commit }}" network: - host env: @@ -62,9 +39,9 @@ - /usr/local/docker-mounted-files/docker-sensors-polling/conf.yml:/root/conf.yml - /run/udev:/run/udev become: true - when: bool_recreate | default(false) or container_info.containers | length == 0 - name: Prune images containers.podman.podman_prune: image: true + dangling_only: false become: true diff --git a/tasks/deploy_thermostat.yml b/tasks/deploy_thermostat.yml index cac9cae..62ab01e 100644 --- a/tasks/deploy_thermostat.yml +++ b/tasks/deploy_thermostat.yml @@ -25,39 +25,16 @@ - debug: var=build_result when: build_result.changed -- name: Gather facts on thermostat container - containers.podman.podman_container_info: - name: thermostat - register: container_info - become: true - -- debug: var=container_info.containers[0].Config.Annotations.git_commit - when: container_info.containers | length == 1 - -- name: Set fact bool_recreate to true - set_fact: - bool_recreate: true - when: - - container_info.containers | length == 1 - - container_info.containers[0].Config.Annotations.git_commit != commit - - name: create thermostat volume ansible.builtin.file: path: "/mnt/apps/volumes/thermostat" state: directory become: true -- name: Delete thermostat container - containers.podman.podman_container: - name: thermostat - state: absent - become: true - when: bool_recreate | default(false) - - name: Create thermostat container containers.podman.podman_container: name: thermostat - image: localhost/thermostat:latest + image: "localhost/thermostat:{{ commit }}" network: - host env: @@ -70,9 +47,9 @@ - /mnt/apps/volumes/thermostat:/root/instance - /run/udev:/run/udev become: true - when: bool_recreate | default(false) or container_info.containers | length == 0 - name: Prune images containers.podman.podman_prune: image: true + dangling_only: false become: true