Yoloattempt to try to keep the build-and-lint up and running and share it between the corresponding jobs

This commit is contained in:
Alexandre Aubin 2024-08-08 17:06:22 +02:00
parent bc9eec167d
commit ac155d19cb
3 changed files with 30 additions and 23 deletions

View file

@ -3,6 +3,13 @@
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
source $current_dir/common.sh
if [[ $IMAGE == "build-and-lint" ]]
then
echo "Should cleanup $CUSTOM_ENV_CI_GIT_CLONE_PATH ?"
exit 0
fi
info "Stopping container $CONTAINER_NAME"
incus stop "$CONTAINER_NAME"

View file

@ -19,21 +19,21 @@ CURRENT_BRANCH="${CUSTOM_ENV_CI_COMMIT_REF_NAME:-$DEFAULT_BRANCH}" # CUSTOM_ENV_
IMAGE="${CUSTOM_ENV_CI_JOB_IMAGE:-after-install}"
LAST_CHANGELOG_ENTRY=$(curl $CUSTOM_ENV_CI_PROJECT_URL/-/raw/$CURRENT_BRANCH/debian/changelog --silent | head -n 1) # yunohost (4.2) unstable; urgency=low
DEBIAN_VERSION_NUMBER=$(echo $LAST_CHANGELOG_ENTRY | cut -d' ' -f2 | tr -d '(' | tr -d ')' | cut -d'.' -f1) # 11, 12
if [[ "$DEBIAN_VERSION_NUMBER" == "11" ]]
[[ -n "$CUSTOM_ENV_CI_YNH_DEBIAN" ]] || { echo "Undefined ynh debian var?"; exit 1; }
DEBIAN=$CUSTOM_ENV_CI_YNH_DEBIAN
if [[ "$DEBIAN" == "bullseye" ]]
then
BASE_IMAGE="ynh-$IMAGE-bullseye-amd64-stable-base"
elif [[ "$DEBIAN_VERSION_NUMBER" == "12" ]]
then
BASE_IMAGE="ynh-$IMAGE-bookworm-amd64-testing-base"
elif [[ "$DEBIAN_VERSION_NUMBER" == "13" ]]
then
# Upcoming someday™
BASE_IMAGE="ynh-$IMAGE-trixie-amd64-unstable-base"
RELEASE="stable"
else
echo "Uhoh, unknown debian version $DEBIAN_VERSION_NUMBER"
exit 1
RELEASE="testing"
fi
CONTAINER_NAME="job-$CUSTOM_ENV_CI_JOB_ID-$CUSTOM_ENV_CI_JOB_NAME_SLUG"
BASE_IMAGE="ynh-$IMAGE-bullseye-amd64-$RELEASE-base"
if [[ $IMAGE == "build-and-lint" ]]
then
CONTAINER_NAME="$DEBIAN-build-and-lint"
else
CONTAINER_NAME="job-$CUSTOM_ENV_CI_JOB_ID-$CUSTOM_ENV_CI_JOB_NAME_SLUG"
fi

View file

@ -98,9 +98,8 @@ trap "exit $SYSTEM_FAILURE_EXIT_CODE" ERR
###############################################################################
info "Starting $CONTAINER_NAME from $BASE_IMAGE ..."
if ! incus info "$CONTAINER_NAME" >/dev/null 2>/dev/null ; then
info "Starting $CONTAINER_NAME from $BASE_IMAGE ..."
# Force the usage of the fingerprint because otherwise for some reason lxd won't use the newer version
# available even though it's aware it exists -_-
@ -108,17 +107,18 @@ if ! incus info "$CONTAINER_NAME" >/dev/null 2>/dev/null ; then
# NB: this image comes from the 'common' image repository shared with the appci, ynh-dev etc
incus launch yunohost:$BASE_HASH $CONTAINER_NAME
sleep 2
fi
# Stop the container if it's running
if [ "$(incus info $CONTAINER_NAME | grep Status | awk '{print tolower($2)}')" == "running" ]; then
incus stop "$CONTAINER_NAME" --timeout 30 || incus stop "$CONTAINER_NAME" --force
# Start the container if it's not running
if [ "$(incus info $CONTAINER_NAME | grep Status | awk '{print tolower($2)}')" != "running" ]; then
incus start $CONTAINER_NAME
fi
# Unset the mac address to ensure the copy will get a new one and will be able to get new IP
incus start $CONTAINER_NAME
sleep 2
if [[ $IMAGE == "build-and-lint" ]]
then
exit 0
fi
incus exec $CONTAINER_NAME dhclient eth0