From a71508b2a5862c5c2564b8fc617d13e4eae46a24 Mon Sep 17 00:00:00 2001 From: Corentin LABBE Date: Wed, 8 Jan 2025 12:07:41 +0100 Subject: [PATCH] Let backup handle docker name different than master Signed-off-by: Corentin LABBE --- .github/workflows/basic.yml | 24 +++++++++++++++++++++ .github/workflows/wait-for-docker.sh | 11 ++++++++-- backup.sh | 31 +++++++++++++++++++++++++++- boards-ci-testbackup.yaml | 26 +++++++++++++++++++++++ 4 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 boards-ci-testbackup.yaml diff --git a/.github/workflows/basic.yml b/.github/workflows/basic.yml index 176bab0..9febdd2 100644 --- a/.github/workflows/basic.yml +++ b/.github/workflows/basic.yml @@ -139,3 +139,27 @@ jobs: run: cd output/local && docker compose up -d - name: Wait for LAVA 2023.10 to be started run: sh .github/workflows/wait-for-docker.sh + test-backup: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: install lavacli + run: sudo apt-get -y install lavacli + - name: test valid and invalid usage of backup.sh + run: | + ./backup.sh -n && exit 1 + ./backup.sh -h || exit 1 + ./backup.sh --help || exit 1 + - run: ./lavalab-gen.py boards-ci-testbackup.yaml + - name: Build lava-docker + run: cd output/local && docker compose build + - name: Launch lava-docker + run: cd output/local && docker compose up -d + - name: Wait for LAVA to be started + run: sh .github/workflows/wait-for-docker.sh central + - name: Run backup + run: ./backup.sh -n central + - name: Check backup + run: | + pwd + ls -l backup-latest diff --git a/.github/workflows/wait-for-docker.sh b/.github/workflows/wait-for-docker.sh index dd621da..c28c763 100644 --- a/.github/workflows/wait-for-docker.sh +++ b/.github/workflows/wait-for-docker.sh @@ -1,5 +1,11 @@ #!/bin/sh +DOCKERNAME=master +if [ ! -z "$1" ];then + DOCKERNAME=$1 + echo "DEBUG: master name is $DOCKERNAME" +fi + cd output/local TIMEOUT=0 @@ -24,12 +30,13 @@ do fi docker compose logs --tail=60 docker ps > /tmp/alldocker - grep -q master /tmp/alldocker + grep -q $DOCKERNAME /tmp/alldocker if [ $? -ne 0 ];then echo "==========================================" echo "==========================================" echo "==========================================" - echo "ERROR: master died" + echo "ERROR: master $DOCKERNAME died" + docker ps docker compose logs exit 1 fi diff --git a/backup.sh b/backup.sh index 2f5f748..685baa1 100755 --- a/backup.sh +++ b/backup.sh @@ -1,17 +1,46 @@ #!/bin/sh +DOCKERNAME=master BACKUP_DIR="backup-$(date +%Y%m%d_%H%M)" # use /tmp by default on host (this is used by tar) TMPDIR=${TMPDIR:-/tmp} export TMPDIR +usage() { + echo "$0 [-h|--help] [-n dockername]" +} + +while [ $# -ge 1 ] +do + case $1 in + -h) + usage + exit 0 + ;; + --help) + usage + exit 0 + ;; + -n) + shift + DOCKERNAME=$1 + shift + ;; + *) + usage + exit 1 + ;; + esac +done + mkdir -p $TMPDIR mkdir $BACKUP_DIR cp boards.yaml $BACKUP_DIR -DOCKERID=$(docker ps |grep master | cut -d' ' -f1) +DOCKERID=$(docker ps |grep "$DOCKERNAME" | cut -d' ' -f1) if [ -z "$DOCKERID" ];then + echo "ERROR: unable to find docker named $DOCKERNAME" exit 1 fi diff --git a/boards-ci-testbackup.yaml b/boards-ci-testbackup.yaml new file mode 100644 index 0000000..1f0b6b0 --- /dev/null +++ b/boards-ci-testbackup.yaml @@ -0,0 +1,26 @@ +--- +masters: + - name: central + host: local + users: + - name: admin + token: tokenforci + password: passwordforci + superuser: true + staff: true + tokens: + - username: admin + token: dfjdfkfkdjfkdsjfslforci + description: no description + +slaves: + - name: lab-ci-0 + host: local + remote_master: central + remote_user: admin + use_overlay_server: false + use_tftp: false + +boards: + - name: qemu-01 + type: qemu