mirror of
https://github.com/YunoHost/yunohost-ci.git
synced 2024-09-03 20:05:53 +02:00
Improve images management
This commit is contained in:
parent
8f5d37ea32
commit
2f1c10f977
3 changed files with 44 additions and 28 deletions
8
base.sh
8
base.sh
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
# /opt/lxd-executor/base.sh
|
# /opt/lxd-executor/base.sh
|
||||||
|
|
||||||
#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"
|
|
||||||
#CUSTOM_ENV_CI_BUILD_REF_NAME=stretch-unstable
|
#CUSTOM_ENV_CI_BUILD_REF_NAME=stretch-unstable
|
||||||
#CUSTOM_ENV_CI_BUILD_REF_SLUG=stretch-unstable
|
#CUSTOM_ENV_CI_BUILD_REF_SLUG=stretch-unstable
|
||||||
#CUSTOM_ENV_CI_DEFAULT_BRANCH=stretch-unstable
|
#CUSTOM_ENV_CI_DEFAULT_BRANCH=stretch-unstable
|
||||||
|
@ -18,7 +17,12 @@
|
||||||
#CUSTOM_ENV_CI_COMMIT_REF_NAME=stretch-unstable
|
#CUSTOM_ENV_CI_COMMIT_REF_NAME=stretch-unstable
|
||||||
#CUSTOM_ENV_CI_PROJECT_NAME=yunohost
|
#CUSTOM_ENV_CI_PROJECT_NAME=yunohost
|
||||||
#CUSTOM_ENV_CI_PROJECT_DIR=/builds/yunohost/yunohost
|
#CUSTOM_ENV_CI_PROJECT_DIR=/builds/yunohost/yunohost
|
||||||
CONTAINER_ID="ci"
|
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"
|
||||||
|
DEBIAN_VERSION="$CUSTOM_ENV_DEBIAN_VERSION"
|
||||||
|
if [ -z "$DEBIAN_VERSION" ]
|
||||||
|
then
|
||||||
|
DEBIAN_VERSION="stretch"
|
||||||
|
fi
|
||||||
PROJECT_DIR="$CUSTOM_ENV_CI_PROJECT_DIR"
|
PROJECT_DIR="$CUSTOM_ENV_CI_PROJECT_DIR"
|
||||||
PROJECT_NAME="$CUSTOM_ENV_CI_PROJECT_NAME"
|
PROJECT_NAME="$CUSTOM_ENV_CI_PROJECT_NAME"
|
||||||
SNAPSHOT_NAME="$CUSTOM_ENV_SNAPSHOT_NAME"
|
SNAPSHOT_NAME="$CUSTOM_ENV_SNAPSHOT_NAME"
|
||||||
|
|
|
@ -5,6 +5,6 @@
|
||||||
currentDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
currentDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
||||||
source ${currentDir}/base.sh # Get variables from base.
|
source ${currentDir}/base.sh # Get variables from base.
|
||||||
|
|
||||||
#echo "Deleting container $CONTAINER_ID"
|
echo "Deleting container $CONTAINER_ID"
|
||||||
|
|
||||||
#lxc delete -f "$CONTAINER_ID"
|
lxc delete -f "$CONTAINER_ID"
|
60
prepare.sh
60
prepare.sh
|
@ -12,40 +12,52 @@ trap "exit $SYSTEM_FAILURE_EXIT_CODE" ERR
|
||||||
|
|
||||||
rebuild_base_container()
|
rebuild_base_container()
|
||||||
{
|
{
|
||||||
lxc info $CONTAINER_ID-rebuild >/dev/null && sudo lxc delete $CONTAINER_ID-rebuild --force
|
lxc info "yunohost-$DEBIAN_VERSION" >/dev/null && lxc delete "yunohost-$DEBIAN_VERSION" --force
|
||||||
lxc launch images:debian/stretch/amd64 $CONTAINER_ID-rebuild
|
lxc launch images:debian/$DEBIAN_VERSION/amd64 "yunohost-$DEBIAN_VERSION-tmp"
|
||||||
lxc config set $CONTAINER_ID-rebuild security.privileged true
|
lxc exec "yunohost-$DEBIAN_VERSION-tmp" -- sh -c "apt-get install curl -y"
|
||||||
lxc restart $CONTAINER_ID-rebuild
|
# Install Git LFS, git comes pre installed with ubuntu image.
|
||||||
lxc exec $CONTAINER_ID-rebuild -- apt install curl -y
|
lxc exec "yunohost-$DEBIAN_VERSION-tmp" -- sh -c "curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash"
|
||||||
|
lxc exec "yunohost-$DEBIAN_VERSION-tmp" -- sh -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 $CONTAINER_ID-rebuild -- /bin/bash -c "curl -s https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh | bash"
|
lxc exec "yunohost-$DEBIAN_VERSION-tmp" -- sh -c "curl -s https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh | bash"
|
||||||
|
lxc stop "yunohost-$DEBIAN_VERSION-tmp"
|
||||||
|
|
||||||
|
# Create image before install
|
||||||
|
lxc publish "yunohost-$DEBIAN_VERSION-tmp" --alias "yunohost-$DEBIAN_VERSION-before-install"
|
||||||
|
lxc start "yunohost-$DEBIAN_VERSION-tmp"
|
||||||
|
|
||||||
# Install yunohost
|
# Install yunohost
|
||||||
lxc exec $CONTAINER_ID-rebuild -- /bin/bash -c "curl https://install.yunohost.org | bash -s -- -a -d unstable"
|
lxc exec "yunohost-$DEBIAN_VERSION-tmp" -- sh -c "curl https://install.yunohost.org | bash -s -- -a -d unstable"
|
||||||
lxc stop $CONTAINER_ID-rebuild
|
lxc stop "yunohost-$DEBIAN_VERSION-tmp"
|
||||||
lxc publish $CONTAINER_ID-rebuild --alias $CONTAINER_ID-base
|
|
||||||
|
# Create image before postinstall
|
||||||
|
lxc publish "yunohost-$DEBIAN_VERSION-tmp" --alias "yunohost-$DEBIAN_VERSION-before-postinstall"
|
||||||
|
lxc start "yunohost-$DEBIAN_VERSION-tmp"
|
||||||
|
|
||||||
|
# Running post Install
|
||||||
|
lxc exec "yunohost-$DEBIAN_VERSION-tmp" -- sh -c "yunohost tools postinstall -d domain.tld -p the_password --ignore-dyndns"
|
||||||
|
lxc stop "yunohost-$DEBIAN_VERSION-tmp"
|
||||||
|
|
||||||
|
# Create image after postinstall
|
||||||
|
lxc publish "yunohost-$DEBIAN_VERSION-tmp" --alias "yunohost-$DEBIAN_VERSION-after-postinstall"
|
||||||
|
|
||||||
|
lxc delete "yunohost-$DEBIAN_VERSION-tmp"
|
||||||
}
|
}
|
||||||
|
|
||||||
start_container () {
|
start_container () {
|
||||||
set -x
|
set -x
|
||||||
|
|
||||||
if ! lxc image info "$CONTAINER_ID-base" &>/dev/null
|
if lxc info "$CONTAINER_ID" >/dev/null 2>/dev/null ; then
|
||||||
|
echo 'Found old container, deleting'
|
||||||
|
lxc delete -f "$CONTAINER_ID"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! lxc image info "yunohost-$DEBIAN_VERSION-$SNAPSHOT_NAME" &>/dev/null
|
||||||
then
|
then
|
||||||
rebuild_base_container
|
rebuild_base_container
|
||||||
fi
|
fi
|
||||||
if ! lxc info $CONTAINER_ID | grep -q "before-postinstall"
|
|
||||||
then
|
lxc launch "yunohost-$DEBIAN_VERSION-$SNAPSHOT_NAME" "$CONTAINER_ID" 2>/dev/null
|
||||||
lxc launch "$CONTAINER_ID-base" "$CONTAINER_ID"
|
|
||||||
lxc config set "$CONTAINER_ID" security.privileged true
|
|
||||||
lxc snapshot "$CONTAINER_ID" "before-postinstall"
|
|
||||||
fi
|
|
||||||
if ! lxc info $CONTAINER_ID | grep -q "after-postinstall"
|
|
||||||
then
|
|
||||||
lxc exec "$CONTAINER_ID" -- sh -c "yunohost tools postinstall -d domain.tld -p the_password --ignore-dyndns"
|
|
||||||
lxc snapshot "$CONTAINER_ID" "after-postinstall"
|
|
||||||
fi
|
|
||||||
|
|
||||||
lxc restore "$CONTAINER_ID" "$SNAPSHOT_NAME"
|
|
||||||
lxc start "$CONTAINER_ID" 2>/dev/null || true
|
|
||||||
|
|
||||||
set +x
|
set +x
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue