From 1ee213ce3f0be005122ddfc379ac60c46a31f973 Mon Sep 17 00:00:00 2001 From: Pietro Bertera Date: Wed, 2 Mar 2022 20:09:31 +0100 Subject: [PATCH] MOD: manage the quay-pod via systemd (#50) --- .../roles/mirror_appliance/defaults/main.yml | 3 ++- .../tasks/create-podman-pod.yaml | 6 ----- .../tasks/install-pod-service.yaml | 23 ++++++++++++++++ .../roles/mirror_appliance/tasks/main.yaml | 4 +-- .../mirror_appliance/templates/pod.service.j2 | 27 +++++++++++++++++++ .../templates/postgres.service.j2 | 3 ++- .../templates/quay.service.j2 | 4 +-- .../templates/redis.service.j2 | 3 ++- .../project/uninstall_mirror_appliance.yml | 8 ++++++ cmd/install.go | 2 +- 10 files changed, 69 insertions(+), 14 deletions(-) delete mode 100755 ansible-runner/context/app/project/roles/mirror_appliance/tasks/create-podman-pod.yaml create mode 100755 ansible-runner/context/app/project/roles/mirror_appliance/tasks/install-pod-service.yaml create mode 100755 ansible-runner/context/app/project/roles/mirror_appliance/templates/pod.service.j2 diff --git a/ansible-runner/context/app/project/roles/mirror_appliance/defaults/main.yml b/ansible-runner/context/app/project/roles/mirror_appliance/defaults/main.yml index 5146fe98..51e97521 100755 --- a/ansible-runner/context/app/project/roles/mirror_appliance/defaults/main.yml +++ b/ansible-runner/context/app/project/roles/mirror_appliance/defaults/main.yml @@ -2,6 +2,7 @@ redis_image: "registry.redhat.io/rhel8/redis-6:1-25" postgres_image: "registry.redhat.io/rhel8/postgresql-10:1-161" quay_image: "registry.redhat.io/quay/quay-rhel8:v3.6.1" +pause_image: "registry.access.redhat.com/ubi8/pause:latest" quay_hostname: "quay:8443" quay_root: "/etc/quay-install" -auto_approve: "false" \ No newline at end of file +auto_approve: "false" diff --git a/ansible-runner/context/app/project/roles/mirror_appliance/tasks/create-podman-pod.yaml b/ansible-runner/context/app/project/roles/mirror_appliance/tasks/create-podman-pod.yaml deleted file mode 100755 index 220a009b..00000000 --- a/ansible-runner/context/app/project/roles/mirror_appliance/tasks/create-podman-pod.yaml +++ /dev/null @@ -1,6 +0,0 @@ -- name: Starting Pod with ports 80 and 443 exposed - containers.podman.podman_pod: - name: quay-pod - state: started - ports: - - '{{ quay_hostname.split(":")[1] if (":" in quay_hostname) else "8443" }}:8443' diff --git a/ansible-runner/context/app/project/roles/mirror_appliance/tasks/install-pod-service.yaml b/ansible-runner/context/app/project/roles/mirror_appliance/tasks/install-pod-service.yaml new file mode 100755 index 00000000..0c05ad14 --- /dev/null +++ b/ansible-runner/context/app/project/roles/mirror_appliance/tasks/install-pod-service.yaml @@ -0,0 +1,23 @@ +- name: Copy Quay Pod systemd service file + template: + src: ../templates/pod.service.j2 + dest: /etc/systemd/system/quay-pod.service + +- name: Check if pod pause image is loaded + command: podman inspect --type=image {{ pause_image }} + register: r + ignore_errors: yes + +- name: Pull Infra image + containers.podman.podman_image: + name: "{{ pause_image }}" + when: r.rc != 0 + retries: 5 + delay: 5 + +- name: Start Quay Pod service + systemd: + name: quay-pod.service + enabled: yes + daemon_reload: yes + state: started diff --git a/ansible-runner/context/app/project/roles/mirror_appliance/tasks/main.yaml b/ansible-runner/context/app/project/roles/mirror_appliance/tasks/main.yaml index 39e1e4c9..69ec98b0 100755 --- a/ansible-runner/context/app/project/roles/mirror_appliance/tasks/main.yaml +++ b/ansible-runner/context/app/project/roles/mirror_appliance/tasks/main.yaml @@ -4,8 +4,8 @@ - name: Set SELinux Rules include_tasks: set-selinux-rules.yaml -- name: Create Podman Pod - include_tasks: create-podman-pod.yaml +- name: Install Quay Pod Service + include_tasks: install-pod-service.yaml - name: Autodetect Image Archive include_tasks: autodetect-image-archive.yaml diff --git a/ansible-runner/context/app/project/roles/mirror_appliance/templates/pod.service.j2 b/ansible-runner/context/app/project/roles/mirror_appliance/templates/pod.service.j2 new file mode 100755 index 00000000..22cc223b --- /dev/null +++ b/ansible-runner/context/app/project/roles/mirror_appliance/templates/pod.service.j2 @@ -0,0 +1,27 @@ +[Unit] +Description=Infra Container for Quay +Wants=network.target +After=network-online.target +Before=quay-postgres.service quay-redis.service + +[Service] +Type=simple +RemainAfterExit=yes +TimeoutStartSec=5m +ExecStartPre=-/bin/rm -f %t/%n-pid %t/%n-pod-id +ExecStart=/usr/bin/podman pod create \ + --name quay-pod \ + --infra-image {{ pause_image }} \ + --publish {{ quay_hostname.split(":")[1] if (":" in quay_hostname) else "8443" }}:8443 \ + --pod-id-file %t/%n-pod-id \ + --replace +ExecStop=-/usr/bin/podman pod stop --ignore --pod-id-file %t/%n-pod-id -t 10 +ExecStopPost=-/usr/bin/podman pod rm --ignore -f --pod-id-file %t/%n-pod-id +PIDFile=%t/%n-pid +KillMode=none +Restart=always +RestartSec=30 + +[Install] +WantedBy=multi-user.target default.target + diff --git a/ansible-runner/context/app/project/roles/mirror_appliance/templates/postgres.service.j2 b/ansible-runner/context/app/project/roles/mirror_appliance/templates/postgres.service.j2 index 3fb9d943..442c162a 100755 --- a/ansible-runner/context/app/project/roles/mirror_appliance/templates/postgres.service.j2 +++ b/ansible-runner/context/app/project/roles/mirror_appliance/templates/postgres.service.j2 @@ -1,7 +1,8 @@ [Unit] Description=PostgreSQL Podman Container for Quay Wants=network.target -After=network-online.target +After=network-online.target quay-pod.service +Requires=quay-pod.service [Service] Type=simple diff --git a/ansible-runner/context/app/project/roles/mirror_appliance/templates/quay.service.j2 b/ansible-runner/context/app/project/roles/mirror_appliance/templates/quay.service.j2 index eae59a91..42f0d0ca 100755 --- a/ansible-runner/context/app/project/roles/mirror_appliance/templates/quay.service.j2 +++ b/ansible-runner/context/app/project/roles/mirror_appliance/templates/quay.service.j2 @@ -1,8 +1,8 @@ [Unit] Description=Quay Container Wants=network.target -After=network-online.target -Requires=quay-postgres.service quay-redis.service +After=network-online.target quay-pod.service quay-postgres.service quay-redis.service +Requires=quay-pod.service quay-postgres.service quay-redis.service [Service] Type=simple diff --git a/ansible-runner/context/app/project/roles/mirror_appliance/templates/redis.service.j2 b/ansible-runner/context/app/project/roles/mirror_appliance/templates/redis.service.j2 index 425d778e..7d934295 100755 --- a/ansible-runner/context/app/project/roles/mirror_appliance/templates/redis.service.j2 +++ b/ansible-runner/context/app/project/roles/mirror_appliance/templates/redis.service.j2 @@ -1,7 +1,8 @@ [Unit] Description=Redis Podman Container for Quay Wants=network.target -After=network-online.target +After=network-online.target quay-pod.service +Requires=quay-pod.service [Service] Type=simple diff --git a/ansible-runner/context/app/project/uninstall_mirror_appliance.yml b/ansible-runner/context/app/project/uninstall_mirror_appliance.yml index 4fb91fc2..6723d389 100755 --- a/ansible-runner/context/app/project/uninstall_mirror_appliance.yml +++ b/ansible-runner/context/app/project/uninstall_mirror_appliance.yml @@ -39,6 +39,14 @@ state: stopped force: yes + - name: Stop Quay Pod service + systemd: + name: quay-pod.service + enabled: no + daemon_reload: yes + state: stopped + force: yes + - name: Delete pod containers.podman.podman_pod: name: quay-pod diff --git a/cmd/install.go b/cmd/install.go index 8e326ae8..3c5261d6 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -103,7 +103,7 @@ func install() { log.Printf("Install has begun") log.Debug("Ansible Execution Environment Image: " + eeImage) - log.Debug("Redis Image: " + pauseImage) + log.Debug("Pause Image: " + pauseImage) log.Debug("Quay Image: " + quayImage) log.Debug("Redis Image: " + redisImage) log.Debug("Postgres Image: " + postgresImage)