From 34a88236f3d0c1f957d1b0b90c735e10b6e26510 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6rz=2C=20Friedrich?= Date: Wed, 5 Jan 2022 15:02:02 +0000 Subject: [PATCH] DEV-298: added hacky shell script to make harbor upgrade a little bit easier --- ansible.cfg | 2 +- roles/harbor/defaults/main.yml | 2 +- roles/harbor/tasks/main.yml | 10 ++++ .../templates/hacky_harbor_upgrade.sh.j2 | 46 +++++++++++++++++++ roles/hcloud/tasks/configure-network.yml | 2 +- 5 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 roles/harbor/templates/hacky_harbor_upgrade.sh.j2 diff --git a/ansible.cfg b/ansible.cfg index 5b25851..2fb444f 100644 --- a/ansible.cfg +++ b/ansible.cfg @@ -1,3 +1,3 @@ [defaults] inventory_plugins = ./inventory_plugins -callbacks_enabled = timer \ No newline at end of file +callbacks_enabled = timer diff --git a/roles/harbor/defaults/main.yml b/roles/harbor/defaults/main.yml index f2f0d02..89d1030 100644 --- a/roles/harbor/defaults/main.yml +++ b/roles/harbor/defaults/main.yml @@ -1,3 +1,3 @@ --- -harbor_version: v2.3.0 +harbor_version: v2.4.1 diff --git a/roles/harbor/tasks/main.yml b/roles/harbor/tasks/main.yml index 7589e3c..7f9804e 100644 --- a/roles/harbor/tasks/main.yml +++ b/roles/harbor/tasks/main.yml @@ -30,6 +30,16 @@ tags: - update_config +- name: 'Copy hacky upgrade script' + template: + src: 'hacky_harbor_upgrade.sh.j2' + dest: '/root/hacky_harbor_upgrade.sh' + owner: 'root' + group: 'root' + mode: '0744' + tags: + - upgrade-helper + - name: Ensure config template files are populated from templates/harbor template: src: "{{ item.src }}" diff --git a/roles/harbor/templates/hacky_harbor_upgrade.sh.j2 b/roles/harbor/templates/hacky_harbor_upgrade.sh.j2 new file mode 100644 index 0000000..20fd4fa --- /dev/null +++ b/roles/harbor/templates/hacky_harbor_upgrade.sh.j2 @@ -0,0 +1,46 @@ +#!/bin/bash +# +# +# + +# plz be careful when comment exit-statement!!!! +exit + +NEW_HARBOR_VERSION='v2.4.1' +DOWNLOAD_DEST_DIR='/tmp' +DOWNLOAD_DEST_FILE="${DOWNLOAD_DEST_DIR}/harbor-online-installer-${NEW_HARBOR_VERSION}.tgz" +SMARDIGO_HOME="{{ service_base_path }}/{{ inventory_hostname }}" +HARBOR_BACKUP_DIR="/opt/harbor_bkp_dir" + +echo "downloading trabll with new harbor version" +wget https://github.com/goharbor/harbor/releases/download/${NEW_HARBOR_VERSION}/harbor-online-installer-${NEW_HARBOR_VERSION}.tgz -O ${DOWNLOAD_DEST_FILE} + +echo "docker pull harbor-migration image" +docker pull goharbor/prepare:${NEW_HARBOR_VERSION} + +echo "Stopping harbor..." +cd ${SMARDIGO_HOME}/harbor +docker-compose down + +if [ ! -d ${HARBOR_BACKUP_DIR} ]; then + echo "saving old install dir + pg-data-dir" + cd ${SMARDIGO_HOME} + mkdir -p ${HARBOR_BACKUP_DIR} + mv "${SMARDIGO_HOME}/harbor" ${HARBOR_BACKUP_DIR}/ + cp -r /data/database ${HARBOR_BACKUP_DIR}/ +else + echo "backup dir << ${HARBOR_BACKUP_DIR} >> for old harbor installtion detected. ply removed before proceeding" + exit +fi + +echo "unpacking tarball new harbor version..." +tar -xzf ${DOWNLOAD_DEST_FILE} -C ${SMARDIGO_HOME} + +echo "copy harbor.yml for upgrade-prepare step" +cp ${HARBOR_BACKUP_DIR}/harbor/harbor.yml ${SMARDIGO_HOME}/harbor/harbor.yml + +echo "running docker container for harbor-migration to version: $NEW_HARBOR_VERSION ..." +docker run -it --rm -v /:/hostfs goharbor/prepare:${NEW_HARBOR_VERSION} migrate -i ${SMARDIGO_HOME}/harbor/harbor.yml + +echo "starting harbor installation ..." +${SMARDIGO_HOME}/harbor/install.sh --with-trivy --with-chartmuseum diff --git a/roles/hcloud/tasks/configure-network.yml b/roles/hcloud/tasks/configure-network.yml index d97fbf6..dc3a6be 100644 --- a/roles/hcloud/tasks/configure-network.yml +++ b/roles/hcloud/tasks/configure-network.yml @@ -33,7 +33,7 @@ state: present delegate_to: 127.0.0.1 become: false - retries: 5 + retries: 15 delay: 10 tags: - update_networks