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.

This commit is contained in:
yohan 2024-06-09 10:21:35 +02:00
parent 3c94e45601
commit 008953463f
2 changed files with 4 additions and 50 deletions

View File

@ -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

View File

@ -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