From 1c1cc12ab51ca6286b8efd5663698f22470e4094 Mon Sep 17 00:00:00 2001 From: Clark Boylan Date: Thu, 12 Dec 2024 14:10:45 -0800 Subject: [PATCH] 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 --- playbooks/roles/gitea/tasks/main.yaml | 13 +++++++++++-- playbooks/roles/jitsi-meet/tasks/main.yaml | 14 ++++++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/playbooks/roles/gitea/tasks/main.yaml b/playbooks/roles/gitea/tasks/main.yaml index 3965bccaab..0d8f75221c 100644 --- a/playbooks/roles/gitea/tasks/main.yaml +++ b/playbooks/roles/gitea/tasks/main.yaml @@ -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: diff --git a/playbooks/roles/jitsi-meet/tasks/main.yaml b/playbooks/roles/jitsi-meet/tasks/main.yaml index 05a88b1fec..6b3a6b0dd4 100644 --- a/playbooks/roles/jitsi-meet/tasks/main.yaml +++ b/playbooks/roles/jitsi-meet/tasks/main.yaml @@ -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: