diff --git a/auto_upgrade_container.sh b/auto_upgrade_container.sh index d16edef..1fa4b2b 100755 --- a/auto_upgrade_container.sh +++ b/auto_upgrade_container.sh @@ -9,7 +9,7 @@ do do for snapshot in "before-install" "after-install" do - update_container $debian_version $ynh_version $snapshot + update_container "$debian_version" "$ynh_version" "$snapshot" done done done @@ -20,8 +20,8 @@ do do for snapshot in "before-install" "after-install" do - update_container $debian_version $ynh_version $snapshot + update_container "$debian_version" "$ynh_version" "$snapshot" done - lxc delete -f $(lxc list yunohost-$debian_version-$ynh_version-r -c n -f csv) + lxc delete -f $(lxc list yunohost-$debian_version-r -c n -f csv) done done diff --git a/cleanup.sh b/cleanup.sh index 96bceb9..1dbfc16 100755 --- a/cleanup.sh +++ b/cleanup.sh @@ -4,6 +4,6 @@ current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" source $current_dir/prints.sh source $current_dir/variables.sh # Get variables from variables. -#info "Deleting container $CONTAINER_ID" +info "Stopping container $CONTAINER_ID" -#lxc delete -f "$CONTAINER_ID" \ No newline at end of file +lxc stop "$CONTAINER_ID" \ No newline at end of file diff --git a/prepare.sh b/prepare.sh index 6f45fa8..549d67d 100755 --- a/prepare.sh +++ b/prepare.sh @@ -24,7 +24,7 @@ start_container () { info "Debian version: $DEBIAN_VERSION, YunoHost version: $CURRENT_VERSION, Image used: $BASE_IMAGE, Snapshot: $SNAPSHOT_NAME" - lxc restore $CONTAINER_IMAGE $SNAPSHOT_NAME + restore_snapshot "$CONTAINER_IMAGE" "$CURRENT_VERSION" "$SNAPSHOT_NAME" lxc start $CONTAINER_IMAGE diff --git a/rebuild_all.sh b/rebuild_all.sh index 4e3a029..33df0ad 100755 --- a/rebuild_all.sh +++ b/rebuild_all.sh @@ -3,9 +3,6 @@ current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" source $current_dir/utils.sh # Get utils functions. -mkdir -p $current_dir/cache -chmod 777 $current_dir/cache - for debian_version in "bullseye" do rebuild_base_containers $debian_version "stable" "amd64" @@ -14,7 +11,7 @@ do do for snapshot in "before-install" "after-install" do - lxc launch "yunohost-$debian_version-stable-$snapshot" "yunohost-$debian_version-$ynh_version-$snapshot-tmp" + restore_snapshot "yunohost-$debian_version" "stable" "$snapshot" if [[ "$ynh_version" == "testing" ]] then @@ -24,16 +21,12 @@ do repo_version="testing unstable" fi - lxc exec "yunohost-$debian_version-$ynh_version-$snapshot-tmp" -- /bin/bash -c "for FILE in \`ls /etc/apt/sources.list /etc/apt/sources.list.d/*\`; + lxc exec "yunohost-$debian_version" -- /bin/bash -c "for FILE in \`ls /etc/apt/sources.list /etc/apt/sources.list.d/*\`; do sed -i 's@^deb http://forge.yunohost.org.*@& $repo_version@' \$FILE done" - rotate_image "yunohost-$debian_version-$ynh_version-$snapshot-tmp" "yunohost-$debian_version-$ynh_version-$snapshot" - - lxc delete -f "yunohost-$debian_version-$ynh_version-$snapshot-tmp" - - update_container $debian_version $ynh_version $snapshot + update_container "$debian_version" "$ynh_version" "$snapshot" done done done diff --git a/utils.sh b/utils.sh index e70e5c3..7813494 100755 --- a/utils.sh +++ b/utils.sh @@ -95,13 +95,20 @@ wait_container() create_snapshot() { local instance_to_publish=$1 - local snapshot=$2 - - # Unset the mac address to ensure the copy will get a new one and will be able to get new IP - lxc config unset "$instance_to_publish" volatile.eth0.hwaddr + local ynh_version=$2 + local snapshot=$3 # Create snapshot - lxc snapshot "$instance_to_publish" "$snapshot" --reuse + lxc snapshot "$instance_to_publish" "$ynh_version-$snapshot" --reuse +} + +restore_snapshot() +{ + local instance_to_publish=$1 + local ynh_version=$2 + local snapshot=$3 + + lxc restore "$instance_to_publish" "$ynh_version-$snapshot" } # These lines are used to extract the dependencies/recommendations from the debian/control file. @@ -118,18 +125,17 @@ get_dependencies() # To extract the dependencies, we want to retrieve the lines between "^Dependencies:" and the new line that doesn't start with a space (exclusively) . Then, we remove ",", then we remove the version specifiers "(>= X.Y)", then we add simple quotes to packages when there is a pipe (or) 'php-mysql|php-mysqlnd'. YUNOHOST_DEPENDENCIES=$(curl https://raw.githubusercontent.com/YunoHost/yunohost/$branch/debian/control 2> /dev/null | sed -n '/^Depends:/,/^\w/{//!p}' | sed -e "s/,//g" -e "s/[(][^)]*[)]//g" -e "s/ | \S\+//g" | grep -v moulinette | grep -v ssowat | tr "\n" " ") - - # We add php8.2-cli and mariadb-client to the dependencies for test_app_resources - YUNOHOST_DEPENDENCIES="$YUNOHOST_DEPENDENCIES php8.2-cli mariadb-client" - YUNOHOST_RECOMMENDS=$(curl https://raw.githubusercontent.com/YunoHost/yunohost/$branch/debian/control 2> /dev/null | sed -n '/^Recommends:/,/^\w/{//!p}' | sed -e "s/,//g" -e "s/[(][^)]*[)]//g" -e "s/ | \S\+//g" | tr "\n" " ") MOULINETTE_DEPENDENCIES=$(curl https://raw.githubusercontent.com/YunoHost/moulinette/$branch/debian/control 2> /dev/null | sed -n '/^Depends:/,/^\w/{//!p}' | sed -e "s/,//g" -e "s/[(][^)]*[)]//g" -e "s/ | \S\+//g" | tr "\n" " ") # Same as above, except that all dependencies are in the same line SSOWAT_DEPENDENCIES=$(curl https://raw.githubusercontent.com/YunoHost/ssowat/$branch/debian/control 2> /dev/null | grep '^Depends:' | sed 's/Depends://' | sed -e "s/,//g" -e "s/[(][^)]*[)]//g" -e "s/ | \S\+//g" | tr "\n" " ") BUILD_DEPENDENCIES="git-buildpackage postfix python3-setuptools python3-pip devscripts" PIP3_PKG='mock pip pyOpenSSL pytest pytest-cov pytest-mock pytest-sugar requests-mock tox ansi2html black jinja2 types-ipaddress types-enum34 types-cryptography types-toml types-requests types-PyYAML types-pyOpenSSL types-mock "packaging<22"' + if [[ "$debian_version" == "bookworm" ]] then + # We add php8.2-cli and mariadb-client to the dependencies for test_app_resources + YUNOHOST_DEPENDENCIES="$YUNOHOST_DEPENDENCIES php8.2-cli mariadb-client" PIP3_PKG="$PIP3_PKG --break-system-packages" fi } @@ -139,7 +145,12 @@ rebuild_base_containers() local debian_version=$1 local ynh_version=$2 local arch=$3 - local base_image_to_rebuild="yunohost-$debian_version-$ynh_version" + local base_image_to_rebuild="yunohost-$debian_version" + + if lxc info "$base_image_to_rebuild" &>/dev/null + then + lxc delete -f "$base_image_to_rebuild" + fi lxc launch images:debian/$debian_version/$arch "$base_image_to_rebuild" -c security.nesting=true @@ -154,11 +165,11 @@ rebuild_base_containers() # Install gitlab-runner binary since we need for cache/artifacts. if [[ $debian_version == "bullseye" ]] then - lxc exec "$base_image_to_rebuild" -- /bin/bash -c "wget https://gitlab-runner-downloads.s3.amazonaws.com/latest/deb/gitlab-runner_amd64.deb" - lxc exec "$base_image_to_rebuild" -- /bin/bash -c "dpkg -i gitlab-runner_amd64.deb" + lxc exec "$base_image_to_rebuild" -- /bin/bash -c "wget https://gitlab-runner-downloads.s3.amazonaws.com/latest/deb/gitlab-runner_amd64.deb" + lxc exec "$base_image_to_rebuild" -- /bin/bash -c "dpkg -i gitlab-runner_amd64.deb" else - lxc exec "$base_image_to_rebuild" -- /bin/bash -c "curl -s https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh | os=debian dist=$debian_version bash" - lxc exec "$base_image_to_rebuild" -- /bin/bash -c "apt-get install --assume-yes gitlab-runner" + lxc exec "$base_image_to_rebuild" -- /bin/bash -c "curl -s https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh | os=debian dist=$debian_version bash" + lxc exec "$base_image_to_rebuild" -- /bin/bash -c "apt-get install --assume-yes gitlab-runner" fi INSTALL_SCRIPT="https://raw.githubusercontent.com/YunoHost/install_script/main/$debian_version" @@ -189,9 +200,15 @@ rebuild_base_containers() lxc exec "$base_image_to_rebuild" -- /bin/bash -c "systemctl -q disable apt-daily.service" lxc exec "$base_image_to_rebuild" -- /bin/bash -c "systemctl -q disable apt-daily-upgrade.service" + + mkdir -p $current_dir/cache + chmod 777 $current_dir/cache lxc config device add "$base_image_to_rebuild" cache-folder disk path=/cache source="$current_dir/cache" - create_snapshot "$base_image_to_rebuild" "before-install" + # Unset the mac address to ensure the copy will get a new one and will be able to get new IP + lxc config unset "$instance_to_publish" volatile.eth0.hwaddr + + create_snapshot "$base_image_to_rebuild" "$ynh_version" "before-install" # Install YunoHost lxc exec "$base_image_to_rebuild" -- /bin/bash -c "curl $INSTALL_SCRIPT | bash -s -- -a -d $ynh_version" @@ -199,7 +216,7 @@ rebuild_base_containers() # Run postinstall lxc exec "$base_image_to_rebuild" -- /bin/bash -c "yunohost tools postinstall -d domain.tld -u syssa -F 'Syssa Mine' -p the_password --ignore-dyndns --force-diskspace" - create_snapshot "$base_image_to_rebuild" "after-install" + create_snapshot "$base_image_to_rebuild" "$ynh_version" "after-install" lxc stop "$base_image_to_rebuild" } @@ -208,7 +225,7 @@ update_container() { local debian_version=$1 local ynh_version=$2 local snapshot=$3 - local image_to_update="yunohost-$debian_version-$ynh_version" + local image_to_update="yunohost-$debian_version" if ! lxc info "$image_to_update" &>/dev/null then @@ -217,8 +234,10 @@ update_container() { fi # Start and run upgrade - lxc restore "$image_to_update" "$snapshot" + restore_snapshot "$image_to_update" "$ynh_version" "$snapshot" + lxc start "$image_to_update" 2>&1 || true + wait_container "$image_to_update" lxc exec "$image_to_update" -- /bin/bash -c "apt-get update" @@ -229,7 +248,7 @@ update_container() { lxc exec "$image_to_update" -- /bin/bash -c "DEBIAN_FRONTEND=noninteractive SUDO_FORCE_REMOVE=yes apt-get --assume-yes -o Dpkg::Options::=\"--force-confold\" install --assume-yes $YUNOHOST_DEPENDENCIES $YUNOHOST_RECOMMENDS $MOULINETTE_DEPENDENCIES $SSOWAT_DEPENDENCIES $BUILD_DEPENDENCIES" lxc exec "$image_to_update" -- /bin/bash -c "python3 -m pip install -U $PIP3_PKG" - create_snapshot "$image_to_update" "$snapshot" + create_snapshot "$image_to_update" "$ynh_version" "$snapshot" lxc stop "$image_to_update" } diff --git a/variables.sh b/variables.sh index 872c7e3..1a1efd9 100755 --- a/variables.sh +++ b/variables.sh @@ -27,7 +27,7 @@ fi PROJECT_DIR="$CUSTOM_ENV_CI_PROJECT_DIR" PROJECT_NAME="$CUSTOM_ENV_CI_PROJECT_NAME" -# For example yunohost-buster-unstable -BASE_IMAGE="yunohost-$DEBIAN_VERSION-$CURRENT_VERSION" +# For example yunohost-buster +BASE_IMAGE="yunohost-$DEBIAN_VERSION" CONTAINER_IMAGE="$BASE_IMAGE-r-$CUSTOM_ENV_CI_RUNNER_ID-p-$CUSTOM_ENV_CI_PROJECT_ID-c-$CUSTOM_ENV_CI_CONCURRENT_PROJECT_ID" \ No newline at end of file