Refactor check for new container images

Two of our services (gitea and jitsi meet) need to take special action
when docker-compose pull updates images and cannot rely on a basic up -d
after a pull. Previously we checked the stderr output of docker-compose
for a string indicating at least one image was updated to determine if
any images updated. The problem with this approach is docker compose is
less verbose than docker-compose and does not give us this information.

In preparation for our slow but eventual migration to docker compose for
these services update the new image check process. Now we perform a
docker image listing before and after the pull and compare the emitted
image ID lists. Image ids should change when we pull new images and
their sort order should be stable command to command (they are sorted by
image age).

Change-Id: I7e9ca8cc7bc0454dcca82c02b6913d81aa4927b3
This commit is contained in:
Clark Boylan 2024-12-12 14:10:45 -08:00
parent 91d823fd97
commit 1c1cc12ab5
2 changed files with 23 additions and 4 deletions

View File

@ -41,14 +41,23 @@
- name: Install reverse proxy
include_tasks: proxy.yaml
- name: Get list of image IDs pre pull
# The --quiet flag prints out only image IDs
command: docker image list --quiet
register: pre_pull_image_ids
- name: Run docker-compose pull
shell:
cmd: docker-compose pull
chdir: /etc/gitea-docker/
register: docker_compose_pull
- name: Get list of image IDs post pull
# The --quiet flag prints out only image IDs
command: docker image list --quiet
register: post_pull_image_ids
- name: Stop/Start gitea safely for Gerrit replication
when: "'downloaded newer image' in docker_compose_pull.stderr"
when: pre_pull_image_ids.stdout_lines|sort != post_pull_image_ids.stdout_lines|sort
block:
- name: Run docker-compose stop
shell:

View File

@ -80,13 +80,23 @@
yes
creates: /var/jitsi-meet/jvb/jvb-keystore.store
- name: Get list of image IDs pre pull
# The --quiet flag prints out only image IDs
command: docker image list --quiet
register: pre_pull_image_ids
- name: Run docker-compose pull
shell:
cmd: docker-compose pull
chdir: /etc/jitsi-meet-docker/
register: docker_compose_pull
- name: Get list of image IDs post pull
# The --quiet flag prints out only image IDs
command: docker image list --quiet
register: post_pull_image_ids
- name: Stop/Start containers if needed
when: "'downloaded newer image' in docker_compose_pull.stderr"
when: pre_pull_image_ids.stdout_lines|sort != post_pull_image_ids.stdout_lines|sort
block:
- name: Run docker-compose down
shell: