From cab0b13f5c25e420a1c3d2c611741ff3aa7583fc Mon Sep 17 00:00:00 2001 From: Clark Boylan Date: Fri, 13 Dec 2024 08:06:47 -0800 Subject: [PATCH] Use docker-compose for container execs in gitea In preparation for a switch from docker-compose to docker compose (with a shim so that docker-compose is docker compose) we switch away from direct docker exec to using docker-compose exec because the two different compose implementations use different container names. This way we shouldn't need to lookup container names at runtime or have special casing depending on which system we want to use. Instead the compose runtime will find the correct container to exec in based on the human readable name in our config file. Change-Id: I5ffb0007997dfdf2da67df3ada5db4534dc383a7 --- playbooks/roles/gitea/tasks/main.yaml | 8 ++++++-- testinfra/test_gitea.py | 4 +++- testinfra/test_gitea_lb.py | 11 +++++++---- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/playbooks/roles/gitea/tasks/main.yaml b/playbooks/roles/gitea/tasks/main.yaml index 3965bccaab..940166ab6e 100644 --- a/playbooks/roles/gitea/tasks/main.yaml +++ b/playbooks/roles/gitea/tasks/main.yaml @@ -97,7 +97,9 @@ when: root_user_check.status==404 block: - name: Create root user - command: "docker exec -t gitea-docker_gitea-web_1 gitea admin user create --name root --password {{ gitea_root_password }} --email {{ gitea_root_email }} --admin" + command: > + /usr/local/bin/docker-compose -f /etc/gitea-docker/docker-compose.yaml exec -T gitea-web + gitea admin user create --name root --password {{ gitea_root_password }} --email {{ gitea_root_email }} --admin no_log: "{{ gitea_no_log }}" - name: Check if gerrit user exists uri: @@ -205,7 +207,9 @@ cron: name: pack-git-refs state: present - job: "docker exec -t gitea-docker_gitea-web_1 find /data/git/repositories/ -maxdepth 2 -name *.git -type d -execdir git --git-dir={} gc --quiet \\;" + job: > + /usr/local/bin/docker-compose -f /etc/gitea-docker/docker-compose.yaml exec -T gitea-web + find /data/git/repositories/ -maxdepth 2 -name *.git -type d -execdir git --git-dir={} gc --quiet \; minute: '{{ 59 | random(seed=inventory_hostname) }}' hour: '{{ 23 | random(seed=inventory_hostname) }}' weekday: '*/2' diff --git a/testinfra/test_gitea.py b/testinfra/test_gitea.py index 260d681ed1..42a6a6e7aa 100644 --- a/testinfra/test_gitea.py +++ b/testinfra/test_gitea.py @@ -28,7 +28,9 @@ def test_gitea_listening(host): assert gitea_proxy.is_listening def test_ulimit(host): - cmd = host.run("docker exec gitea-docker_gitea-web_1 prlimit") + cmd = host.run("/usr/local/bin/docker-compose " + "-f /etc/gitea-docker/docker-compose.yaml " + "exec -T gitea-web prlimit") expected = ("STACK max stack size " "16777216 9223372036854775807 bytes") assert expected in cmd.stdout.split('\n') diff --git a/testinfra/test_gitea_lb.py b/testinfra/test_gitea_lb.py index b44c388435..02d7c24334 100644 --- a/testinfra/test_gitea_lb.py +++ b/testinfra/test_gitea_lb.py @@ -25,10 +25,13 @@ def test_gitea_listening(host): assert gitea_http.is_listening def test_haproxy_statsd_running(host): - cmd = host.run("docker inspect haproxy-docker_haproxy-statsd_1") - out = json.loads(cmd.stdout) - assert out[0]["State"]["Status"] == "running" - assert out[0]["RestartCount"] == 0 + # TODO(clarkb) when everything is using docker compose we can use + # ps --format json and inspect the json document directly. Old + # docker-compose doesn't support this. + cmd = host.run("/usr/local/bin/docker-compose " + "-f /etc/haproxy-docker/docker-compose.yaml " + "ps haproxy-statsd") + assert ' Up ' in cmd.stdout def test_haproxy_gitea_connection(host): cmd = host.run('curl --resolve opendev.org:443:127.0.0.1 '