add versions support

This commit is contained in:
Kay0u 2020-03-20 00:55:43 +01:00
parent dea11a5b3e
commit b256a91314
No known key found for this signature in database
GPG key ID: 7FF262C033518333
2 changed files with 25 additions and 24 deletions

View file

@ -16,6 +16,7 @@
CONTAINER_ID="runner-$CUSTOM_ENV_CI_RUNNER_ID-project-$CUSTOM_ENV_CI_PROJECT_ID-concurrent-$CUSTOM_ENV_CI_CONCURRENT_PROJECT_ID-$CUSTOM_ENV_CI_JOB_ID" CONTAINER_ID="runner-$CUSTOM_ENV_CI_RUNNER_ID-project-$CUSTOM_ENV_CI_PROJECT_ID-concurrent-$CUSTOM_ENV_CI_CONCURRENT_PROJECT_ID-$CUSTOM_ENV_CI_JOB_ID"
ARCH="$(echo $CUSTOM_ENV_CI_RUNNER_EXECUTABLE_ARCH | cut -d'/' -f2)" # linux/amd64 ARCH="$(echo $CUSTOM_ENV_CI_RUNNER_EXECUTABLE_ARCH | cut -d'/' -f2)" # linux/amd64
DEFAULT_BRANCH=$(echo $CUSTOM_ENV_CI_DEFAULT_BRANCH | cut -d'-' -f1) # stretch-unstable, buster-unstable... DEFAULT_BRANCH=$(echo $CUSTOM_ENV_CI_DEFAULT_BRANCH | cut -d'-' -f1) # stretch-unstable, buster-unstable...
CURRENT_VERSION=$(echo $CUSTOM_ENV_CI_DEFAULT_BRANCH | cut -d'-' -f2) # stretch-unstable, stretch-testing, stretch-stable...
CURRENT_BRANCH="$CUSTOM_ENV_CI_COMMIT_REF_NAME" CURRENT_BRANCH="$CUSTOM_ENV_CI_COMMIT_REF_NAME"
DEBIAN_VERSION=$(echo $CUSTOM_ENV_CI_COMMIT_REF_NAME | cut -d'-' -f1) # CUSTOM_ENV_CI_COMMIT_REF_NAME is the target branch of the MR: stretch-unstable, buster-unstable... DEBIAN_VERSION=$(echo $CUSTOM_ENV_CI_COMMIT_REF_NAME | cut -d'-' -f1) # CUSTOM_ENV_CI_COMMIT_REF_NAME is the target branch of the MR: stretch-unstable, buster-unstable...
if [ -z "$DEBIAN_VERSION" ] || [ "$DEBIAN_VERSION" != "stretch" ] && [ "$DEBIAN_VERSION" != "buster" ] if [ -z "$DEBIAN_VERSION" ] || [ "$DEBIAN_VERSION" != "stretch" ] && [ "$DEBIAN_VERSION" != "buster" ]

View file

@ -10,7 +10,7 @@ trap "exit $SYSTEM_FAILURE_EXIT_CODE" ERR
clean_containers() clean_containers()
{ {
for image_to_delete in "yunohost-$DEBIAN_VERSION"{,"-tmp"} for image_to_delete in "yunohost-$DEBIAN_VERSION-"{"stable","testing","unstable"}""{,"-tmp"}
do do
if lxc info $image_to_delete &>/dev/null if lxc info $image_to_delete &>/dev/null
then then
@ -18,7 +18,7 @@ clean_containers()
fi fi
done done
for image_to_delete in "yunohost-$DEBIAN_VERSION-"{"before-install","before-postinstall","after-postinstall"} for image_to_delete in "yunohost-$DEBIAN_VERSION-"{"stable","testing","unstable"}"-"{"before-install","before-postinstall","after-postinstall"}
do do
if lxc image info $image_to_delete &>/dev/null if lxc image info $image_to_delete &>/dev/null
then then
@ -51,38 +51,38 @@ rebuild_base_container()
{ {
clean_containers clean_containers
lxc launch images:debian/$DEBIAN_VERSION/$ARCH "yunohost-$DEBIAN_VERSION-tmp" lxc launch images:debian/$DEBIAN_VERSION/$ARCH "yunohost-$DEBIAN_VERSION-$CURRENT_VERSION-tmp"
lxc exec "yunohost-$DEBIAN_VERSION-tmp" -- /bin/bash -c "apt-get install curl -y" lxc exec "yunohost-$DEBIAN_VERSION-$CURRENT_VERSION-tmp" -- /bin/bash -c "apt-get install curl -y"
# Install Git LFS, git comes pre installed with ubuntu image. # Install Git LFS, git comes pre installed with ubuntu image.
lxc exec "yunohost-$DEBIAN_VERSION-tmp" -- /bin/bash -c "curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash" lxc exec "yunohost-$DEBIAN_VERSION-$CURRENT_VERSION-tmp" -- /bin/bash -c "curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash"
lxc exec "yunohost-$DEBIAN_VERSION-tmp" -- /bin/bash -c "apt-get install git-lfs -y" lxc exec "yunohost-$DEBIAN_VERSION-$CURRENT_VERSION-tmp" -- /bin/bash -c "apt-get install git-lfs -y"
# Install gitlab-runner binary since we need for cache/artifacts. # Install gitlab-runner binary since we need for cache/artifacts.
lxc exec "yunohost-$DEBIAN_VERSION-tmp" -- /bin/bash -c "curl -s https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh | bash" lxc exec "yunohost-$DEBIAN_VERSION-$CURRENT_VERSION-tmp" -- /bin/bash -c "curl -s https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh | bash"
lxc exec "yunohost-$DEBIAN_VERSION-tmp" -- /bin/bash -c "apt-get install gitlab-runner -y" lxc exec "yunohost-$DEBIAN_VERSION-$CURRENT_VERSION-tmp" -- /bin/bash -c "apt-get install gitlab-runner -y"
lxc stop "yunohost-$DEBIAN_VERSION-tmp" lxc stop "yunohost-$DEBIAN_VERSION-$CURRENT_VERSION-tmp"
# Create image before install # Create image before install
lxc publish "yunohost-$DEBIAN_VERSION-tmp" --alias "yunohost-$DEBIAN_VERSION-before-install" lxc publish "yunohost-$DEBIAN_VERSION-$CURRENT_VERSION-tmp" --alias "yunohost-$DEBIAN_VERSION-$CURRENT_VERSION-before-install"
lxc start "yunohost-$DEBIAN_VERSION-tmp" lxc start "yunohost-$DEBIAN_VERSION-$CURRENT_VERSION-tmp"
wait_container "yunohost-$DEBIAN_VERSION-tmp" wait_container "yunohost-$DEBIAN_VERSION-$CURRENT_VERSION-tmp"
# Install yunohost # Install yunohost
lxc exec "yunohost-$DEBIAN_VERSION-tmp" -- /bin/bash -c "curl https://install.yunohost.org | bash -s -- -a -d unstable" lxc exec "yunohost-$DEBIAN_VERSION-$CURRENT_VERSION-tmp" -- /bin/bash -c "curl https://install.yunohost.org | bash -s -- -a -d $CURRENT_VERSION"
lxc stop "yunohost-$DEBIAN_VERSION-tmp" lxc stop "yunohost-$DEBIAN_VERSION-$CURRENT_VERSION-tmp"
# Create image before postinstall # Create image before postinstall
lxc publish "yunohost-$DEBIAN_VERSION-tmp" --alias "yunohost-$DEBIAN_VERSION-before-postinstall" lxc publish "yunohost-$DEBIAN_VERSION-$CURRENT_VERSION-tmp" --alias "yunohost-$DEBIAN_VERSION-$CURRENT_VERSION-before-postinstall"
lxc start "yunohost-$DEBIAN_VERSION-tmp" lxc start "yunohost-$DEBIAN_VERSION-$CURRENT_VERSION-tmp"
wait_container "yunohost-$DEBIAN_VERSION-tmp" wait_container "yunohost-$DEBIAN_VERSION-$CURRENT_VERSION-tmp"
# Running post Install # Running post Install
lxc exec "yunohost-$DEBIAN_VERSION-tmp" -- /bin/bash -c "yunohost tools postinstall -d domain.tld -p the_password --ignore-dyndns" lxc exec "yunohost-$DEBIAN_VERSION-$CURRENT_VERSION-tmp" -- /bin/bash -c "yunohost tools postinstall -d domain.tld -p the_password --ignore-dyndns"
lxc stop "yunohost-$DEBIAN_VERSION-tmp" lxc stop "yunohost-$DEBIAN_VERSION-$CURRENT_VERSION-tmp"
# Create image after postinstall # Create image after postinstall
lxc publish "yunohost-$DEBIAN_VERSION-tmp" --alias "yunohost-$DEBIAN_VERSION-after-postinstall" lxc publish "yunohost-$DEBIAN_VERSION-$CURRENT_VERSION-tmp" --alias "yunohost-$DEBIAN_VERSION-$CURRENT_VERSION-after-postinstall"
lxc delete "yunohost-$DEBIAN_VERSION-tmp" lxc delete "yunohost-$DEBIAN_VERSION-$CURRENT_VERSION-tmp"
} }
update_image() { update_image() {
@ -111,14 +111,14 @@ start_container () {
lxc delete -f "$CONTAINER_ID" lxc delete -f "$CONTAINER_ID"
fi fi
if ! lxc image info "yunohost-$DEBIAN_VERSION-$SNAPSHOT_NAME" &>/dev/null if ! lxc image info "yunohost-$DEBIAN_VERSION-$CURRENT_VERSION-$SNAPSHOT_NAME" &>/dev/null
then then
rebuild_base_container rebuild_base_container
fi fi
update_image "yunohost-$DEBIAN_VERSION-$SNAPSHOT_NAME" update_image "yunohost-$DEBIAN_VERSION-$CURRENT_VERSION-$SNAPSHOT_NAME"
lxc launch "yunohost-$DEBIAN_VERSION-$SNAPSHOT_NAME" "$CONTAINER_ID" 2>/dev/null lxc launch "yunohost-$DEBIAN_VERSION-$CURRENT_VERSION-$SNAPSHOT_NAME" "$CONTAINER_ID" 2>/dev/null
mkdir -p ${currentDir}/cache mkdir -p ${currentDir}/cache
chmod 777 ${currentDir}/cache chmod 777 ${currentDir}/cache