From 3dbbd7d999f4c41b8e9df2d71852bf09eb505f0c Mon Sep 17 00:00:00 2001 From: Haroon Khel Date: Thu, 3 Aug 2023 13:20:29 +0100 Subject: [PATCH 1/3] run update script via dockerhost playbook --- .../roles/DockerStatic/scripts/updatepackages.sh | 14 ++++++++++---- .../roles/DockerStatic/tasks/main.yml | 12 +++++------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/DockerStatic/scripts/updatepackages.sh b/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/DockerStatic/scripts/updatepackages.sh index 6791ceb639..f83a280f5d 100644 --- a/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/DockerStatic/scripts/updatepackages.sh +++ b/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/DockerStatic/scripts/updatepackages.sh @@ -1,16 +1,22 @@ - #!/bin/bash +#!/bin/bash +set -u export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin containerIds=$(docker ps -q) +commonPackages= +fedoraPackages= +debianPackages= +alpinePackages= + for container in $containerIds do OS=$(docker exec -it $container sh -c "cat /etc/os-release" | head -n 1) - if [[ $OS =~ "CentOS" || $OS =~ "Fedora" || $OS=~ "Red Hat Enterprise Linux" ]]; then + if [[ "$OS" == *"CentOS"* ]] || [[ "$OS" == *"Fedora"* ]] || [[ "$OS" == *"Red Hat Enterprise Linux"* ]]; then installCommand="yum -y update" - elif [[ $OS =~ "Ubuntu" || $OS =~ "Debian" ]]; then + elif [[ "$OS" == *"Ubuntu"* ]] || [[ "$OS" == *"Debian"* ]]; then installCommand="apt-get update && apt-get -y upgrade" - elif [[ $OS =~ "Alpine" ]]; then + elif [[ "$OS" == *"Alpine"* ]]; then installCommand="apk update && apk upgrade" else echo "Unrecognised OS, skipping package update" diff --git a/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/DockerStatic/tasks/main.yml b/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/DockerStatic/tasks/main.yml index 1e83462c9a..29c793bb1b 100644 --- a/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/DockerStatic/tasks/main.yml +++ b/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/DockerStatic/tasks/main.yml @@ -245,10 +245,8 @@ regexp: kernel_core_pattern line: kernel.core_pattern=core.%p -- name: Copy updatepackages.sh script to remote cron.daily directory - copy: - src: scripts/updatepackages.sh - dest: /etc/cron.daily/updatepackages.sh - owner: root - group: root - mode: +x +- name: Run updatePackage.sh script + script: scripts/updatepackages.sh + args: + executable: bash + tags: updateContainers From 3823fc420c63927702d1ff7f29d1bfe4dc3937c7 Mon Sep 17 00:00:00 2001 From: Haroon Khel Date: Thu, 3 Aug 2023 13:23:56 +0100 Subject: [PATCH 2/3] add never tag to updatescript task --- .../roles/DockerStatic/tasks/main.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/DockerStatic/tasks/main.yml b/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/DockerStatic/tasks/main.yml index 29c793bb1b..a44b457739 100644 --- a/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/DockerStatic/tasks/main.yml +++ b/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/DockerStatic/tasks/main.yml @@ -249,4 +249,6 @@ script: scripts/updatepackages.sh args: executable: bash - tags: updateContainers + tags: + - updateContainers + - never From 7b2b509dfcd1044b3fc16de05ce73bb03955e86a Mon Sep 17 00:00:00 2001 From: Haroon Khel Date: Thu, 10 Aug 2023 15:31:01 +0100 Subject: [PATCH 3/3] add some common packages --- .../roles/DockerStatic/scripts/updatepackages.sh | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/DockerStatic/scripts/updatepackages.sh b/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/DockerStatic/scripts/updatepackages.sh index f83a280f5d..434a0adbee 100644 --- a/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/DockerStatic/scripts/updatepackages.sh +++ b/ansible/playbooks/AdoptOpenJDK_Unix_Playbook/roles/DockerStatic/scripts/updatepackages.sh @@ -4,25 +4,26 @@ set -u export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin containerIds=$(docker ps -q) -commonPackages= -fedoraPackages= -debianPackages= -alpinePackages= +commonPackages="gnupg fakeroot" +fedoraPackages="procps-ng hostname shared-mime-info" +debianPackages="" +alpinePackages="" for container in $containerIds do OS=$(docker exec -it $container sh -c "cat /etc/os-release" | head -n 1) if [[ "$OS" == *"CentOS"* ]] || [[ "$OS" == *"Fedora"* ]] || [[ "$OS" == *"Red Hat Enterprise Linux"* ]]; then - installCommand="yum -y update" + installCommand="yum -y update && yum -y install $commonPackages $fedoraPackages" elif [[ "$OS" == *"Ubuntu"* ]] || [[ "$OS" == *"Debian"* ]]; then - installCommand="apt-get update && apt-get -y upgrade" + installCommand="apt-get update && apt-get -y upgrade && apt-get -y install $commonPackages $debianPackages" elif [[ "$OS" == *"Alpine"* ]]; then - installCommand="apk update && apk upgrade" + installCommand="apk update && apk upgrade && apk --update add $commonPackages $alpinePackages" else echo "Unrecognised OS, skipping package update" continue fi echo "Updating packages for container $container" + echo "Running $installCommand" docker exec -it $container sh -c "$installCommand" echo "==============================================" done