diff --git a/build/Makefile b/build/Makefile index 2a4f47535b..667eb33d7d 100644 --- a/build/Makefile +++ b/build/Makefile @@ -2,6 +2,7 @@ export PACKER_CACHE_DIR := .cache export PACKER_VERSION := 1.9.4 export BOX_VERSION := 202407.23.0 export PMM_SERVER_IMAGE ?= docker.io/perconalab/pmm-server:3-dev-latest +export WATCHTOWER_IMAGE ?= docker.io/perconalab/watchtower:dev-latest export CENTOS_ISO := 2004.01 ## ----------------- PACKER ------------------ @@ -25,7 +26,10 @@ deps: unzip -o ${PACKER_CACHE_DIR}/packer.zip -d ~/bin pmm-ovf: fetch - /usr/bin/packer build -var 'pmm_server_image_name=${PMM_SERVER_IMAGE}' -only virtualbox-ovf -color=false packer/pmm.json | tee build.log + /usr/bin/packer build \ + -var 'pmm_server_image_name=${PMM_SERVER_IMAGE}' \ + -var 'watchtower_image_name=${WATCHTOWER_IMAGE}' \ + -only virtualbox-ovf -color=false packer/pmm.json | tee build.log pmm-digitalocean: packer build -only digitalocean -var 'single_disk=true' packer/pmm.json @@ -35,7 +39,9 @@ pmm-azure: pmm-ami: docker run --rm -v ${HOME}/.aws:/root/.aws -v `pwd`:/build -w /build \hashicorp/packer:${PACKER_VERSION} \ - build -var 'pmm_server_image_name=${PMM_SERVER_IMAGE}' -only amazon-ebs -color=false packer/pmm.json | tee build.log + build -var 'pmm_server_image_name=${PMM_SERVER_IMAGE}' \ + -var 'watchtower_image_name=${WATCHTOWER_IMAGE}' \ + -only amazon-ebs -color=false packer/pmm.json | tee build.log ## ----------------- PACKER ------------------ check: diff --git a/build/packages/rpm/client/pmm-client.spec b/build/packages/rpm/client/pmm-client.spec index dea85fd042..bc77f78eef 100644 --- a/build/packages/rpm/client/pmm-client.spec +++ b/build/packages/rpm/client/pmm-client.spec @@ -52,13 +52,22 @@ if [ -f /usr/local/percona/pmm2/config/pmm-agent.yaml.bak ]; then /^[^[:space:]]/!d }' "/usr/local/percona/pmm/config/pmm-agent.yaml" > "/usr/local/percona/pmm/config/pmm-agent.yaml.tmp" && mv "/usr/local/percona/pmm/config/pmm-agent.yaml.tmp" "/usr/local/percona/pmm/config/pmm-agent.yaml" - if [ -d /usr/local/percona/pmm2/config ] && [ ! "$(ls -A /usr/local/percona/pmm2/config)" ]; then + if [ -d /usr/local/percona/pmm2/config ] && [ -z "$(ls -A /usr/local/percona/pmm2/config)" ]; then rmdir /usr/local/percona/pmm2/config fi - if [ -d /usr/local/percona/pmm2 ] && [ ! "$(ls -A /usr/local/percona/pmm2)" ]; then + if [ -d /usr/local/percona/pmm2 ] && [ -z "$(ls -A /usr/local/percona/pmm2)" ]; then rmdir /usr/local/percona/pmm2 fi + + if ! getent passwd pmm-agent > /dev/null 2>&1; then + /usr/sbin/groupadd -r pmm-agent + /usr/sbin/useradd -M -r -g pmm-agent -d /usr/local/percona/ -s /bin/false -c "PMM Agent User" pmm-agent + chown -R pmm-agent:pmm-agent /usr/local/percona/pmm + fi + /usr/bin/systemctl enable pmm-agent >/dev/null 2>&1 || : + /usr/bin/systemctl daemon-reload + /usr/bin/systemctl start pmm-agent.service fi %build @@ -122,7 +131,7 @@ install -m 0644 config/pmm-agent.service %{buildroot}/%{_unitdir}/pmm-agent.serv rm -rf $RPM_BUILD_ROOT %pre -if [ $1 == 1 ]; then +if [ $1 -eq 1 ]; then if ! getent passwd pmm-agent > /dev/null 2>&1; then /usr/sbin/groupadd -r pmm-agent /usr/sbin/useradd -M -r -g pmm-agent -d /usr/local/percona/ -s /bin/false -c pmm-agent pmm-agent > /dev/null 2>&1 @@ -132,7 +141,6 @@ if [ $1 -eq 2 ]; then /usr/bin/systemctl stop pmm-agent.service >/dev/null 2>&1 ||: fi - %post for file in pmm-admin pmm-agent do @@ -140,7 +148,7 @@ do %{__ln_s} -f /usr/local/percona/pmm/bin/$file /usr/sbin/$file done %systemd_post pmm-agent.service -if [ $1 == 1 ]; then +if [ $1 -eq 1 ]; then if [ ! -f /usr/local/percona/pmm/config/pmm-agent.yaml ]; then install -d -m 0755 /usr/local/percona/pmm/config install -m 0660 -o pmm-agent -g pmm-agent /dev/null /usr/local/percona/pmm/config/pmm-agent.yaml @@ -164,21 +172,29 @@ fi %postun case "$1" in - 0) # This is a yum remove. - /usr/sbin/userdel pmm-agent - %systemd_postun_with_restart pmm-agent.service - ;; 1) # This is a yum upgrade. %systemd_postun_with_restart pmm-agent.service ;; esac -if [ $1 == 0 ]; then +if [ $1 -eq 0 ]; then + %systemd_postun_with_restart pmm-agent.service if /usr/bin/id -g pmm-agent > /dev/null 2>&1; then /usr/sbin/userdel pmm-agent > /dev/null 2>&1 /usr/sbin/groupdel pmm-agent > /dev/null 2>&1 || true if [ -f /usr/local/percona/pmm/config/pmm-agent.yaml ]; then rm -r /usr/local/percona/pmm/config/pmm-agent.yaml fi + if [ -f /usr/local/percona/pmm/config/pmm-agent.yaml.bak ]; then + rm -r /usr/local/percona/pmm/config/pmm-agent.yaml.bak + fi + if [ -d /usr/local/percona/pmm/config ] && [ -z "$(ls -A /usr/local/percona/pmm/config)" ]; then + rmdir /usr/local/percona/pmm/config + fi + + if [ -d /usr/local/percona/pmm ] && [ -z "$(ls -A /usr/local/percona/pmm)" ]; then + rmdir /usr/local/percona/pmm + fi + for file in pmm-admin pmm-agent do if [ -L /usr/sbin/$file ]; then @@ -191,7 +207,6 @@ if [ $1 == 0 ]; then fi fi - %files %config %{_unitdir}/pmm-agent.service %attr(0660,pmm-agent,pmm-agent) %ghost /usr/local/percona/pmm/config/pmm-agent.yaml diff --git a/build/packer/ansible/roles/podman-setup/templates/watchtower.env b/build/packer/ansible/roles/podman-setup/templates/watchtower.env index 727aa953fe..44ad59f48a 100644 --- a/build/packer/ansible/roles/podman-setup/templates/watchtower.env +++ b/build/packer/ansible/roles/podman-setup/templates/watchtower.env @@ -1,3 +1,4 @@ +WATCHTOWER_IMAGE={{ watchtower_image_name }} WATCHTOWER_HTTP_API_UPDATE=1 WATCHTOWER_HTTP_API_TOKEN=123 WATCHTOWER_NO_RESTART=1 diff --git a/build/packer/ansible/roles/podman-setup/templates/watchtower.service b/build/packer/ansible/roles/podman-setup/templates/watchtower.service index 7fc366d86b..017167a230 100644 --- a/build/packer/ansible/roles/podman-setup/templates/watchtower.service +++ b/build/packer/ansible/roles/podman-setup/templates/watchtower.service @@ -15,7 +15,7 @@ ExecStart=/usr/bin/podman run --rm --replace=true --name %N \ --env-file=/home/admin/.config/systemd/user/watchtower.env \ --net pmm_default \ --cap-add=net_admin,net_raw \ - docker.io/perconalab/watchtower + ${WATCHTOWER_IMAGE} ExecStop=/usr/bin/podman stop -t 10 %N diff --git a/build/packer/pmm.json b/build/packer/pmm.json index 5fd2f79a43..c0c88de4ab 100644 --- a/build/packer/pmm.json +++ b/build/packer/pmm.json @@ -1,7 +1,8 @@ { "variables": { "single_disk": "false", - "pmm_server_image_name": "docker.io/perconalab/pmm-server:3-dev-latest" + "pmm_server_image_name": "docker.io/perconalab/pmm-server:3-dev-latest", + "watchtower_image_name": "docker.io/perconalab/watchtower:dev-latest" }, "builders": [ { @@ -124,7 +125,7 @@ "-vvv", "-u root", "--extra-vars", - "\"pmm_server_image_name='{{ user `pmm_server_image_name`}}'\"" + "\"pmm_server_image_name='{{ user `pmm_server_image_name` }}' watchtower_image_name='{{ user `watchtower_image_name` }}'\"" ], "role_paths": [ "packer/ansible/roles/lvm-init",