yunohost-ci/prepare.sh

117 lines
3.7 KiB
Bash
Raw Normal View History

2019-11-25 13:11:18 +01:00
#!/usr/bin/env bash
# /opt/lxd-executor/prepare.sh
currentDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
source ${currentDir}/base.sh # Get variables from base.
set -eo pipefail
# trap any error, and mark it as a system failure.
trap "exit $SYSTEM_FAILURE_EXIT_CODE" ERR
2019-11-26 14:15:34 +01:00
clean_containers()
{
2019-11-26 14:43:09 +01:00
for image_to_delete in "yunohost-$DEBIAN_VERSION" "yunohost-$DEBIAN_VERSION-tmp"
2019-11-26 14:15:34 +01:00
do
if lxc info $image_to_delete &>/dev/null
then
lxc delete $image_to_delete --force
fi
done
2019-11-26 14:43:09 +01:00
for image_to_delete in "yunohost-$DEBIAN_VERSION-before-install" "yunohost-$DEBIAN_VERSION-before-postinstall" "yunohost-$DEBIAN_VERSION-after-postinstall"
2019-11-26 14:15:34 +01:00
do
if lxc image info $image_to_delete &>/dev/null
then
lxc image delete $image_to_delete
fi
done
}
2019-11-26 15:43:38 +01:00
wait_container()
{
# Wait for container to start, we are using systemd to check this,
# for the sake of brevity.
for i in $(seq 1 10); do
if lxc exec "$1" -- /bin/bash -c "systemctl isolate multi-user.target" >/dev/null 2>/dev/null; then
break
fi
if [ "$i" == "10" ]; then
echo 'Waited for 10 seconds to start container, exiting..'
# Inform GitLab Runner that this is a system failure, so it
# should be retried.
exit "$SYSTEM_FAILURE_EXIT_CODE"
fi
sleep 1s
done
}
2019-11-25 13:11:18 +01:00
rebuild_base_container()
{
2019-11-26 14:15:34 +01:00
clean_containers
2019-11-26 14:01:29 +01:00
lxc launch images:debian/$DEBIAN_VERSION/amd64 "yunohost-$DEBIAN_VERSION-tmp"
2019-11-26 14:43:09 +01:00
lxc exec "yunohost-$DEBIAN_VERSION-tmp" -- /bin/bash -c "apt-get install curl -y"
2019-11-26 14:01:29 +01:00
# Install Git LFS, git comes pre installed with ubuntu image.
2019-11-26 14:43:09 +01:00
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-tmp" -- /bin/bash -c "apt-get install git-lfs -y"
2019-11-25 13:11:18 +01:00
# Install gitlab-runner binary since we need for cache/artifacts.
2019-11-26 14:43:09 +01:00
lxc exec "yunohost-$DEBIAN_VERSION-tmp" -- /bin/bash -c "curl -s https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh | bash"
2019-12-23 07:05:23 +01:00
lxc exec "yunohost-$DEBIAN_VERSION-tmp" -- /bin/bash -c "apt-get install gitlab-runner -y"
2019-11-26 14:01:29 +01:00
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"
2019-11-26 15:43:38 +01:00
wait_container "yunohost-$DEBIAN_VERSION-tmp"
2019-11-26 14:01:29 +01:00
2019-11-25 13:11:18 +01:00
# Install yunohost
2019-11-26 14:43:09 +01:00
lxc exec "yunohost-$DEBIAN_VERSION-tmp" -- /bin/bash -c "curl https://install.yunohost.org | bash -s -- -a -d unstable"
2019-11-26 14:01:29 +01:00
lxc stop "yunohost-$DEBIAN_VERSION-tmp"
# Create image before postinstall
lxc publish "yunohost-$DEBIAN_VERSION-tmp" --alias "yunohost-$DEBIAN_VERSION-before-postinstall"
lxc start "yunohost-$DEBIAN_VERSION-tmp"
2019-11-26 15:43:38 +01:00
wait_container "yunohost-$DEBIAN_VERSION-tmp"
2019-11-26 14:01:29 +01:00
# Running post Install
2019-11-26 14:43:09 +01:00
lxc exec "yunohost-$DEBIAN_VERSION-tmp" -- /bin/bash -c "yunohost tools postinstall -d domain.tld -p the_password --ignore-dyndns"
2019-11-26 14:01:29 +01:00
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"
2019-11-25 13:11:18 +01:00
}
start_container () {
2019-11-25 14:16:24 +01:00
set -x
2019-11-26 14:15:34 +01:00
if lxc info "$CONTAINER_ID" >/dev/null 2>/dev/null ; then
echo 'Found old container, deleting'
lxc delete -f "$CONTAINER_ID"
fi
2019-11-26 14:01:29 +01:00
if ! lxc image info "yunohost-$DEBIAN_VERSION-$SNAPSHOT_NAME" &>/dev/null
2019-11-25 13:11:18 +01:00
then
rebuild_base_container
fi
2019-11-26 14:01:29 +01:00
lxc launch "yunohost-$DEBIAN_VERSION-$SNAPSHOT_NAME" "$CONTAINER_ID" 2>/dev/null
2019-11-25 14:16:24 +01:00
2019-12-23 11:36:31 +01:00
mkdir -p ${currentDir}/cache
chmod 777 ${currentDir}/cache
lxc config device add "$CONTAINER_ID" cache-folder disk path=/cache source="${currentDir}/cache"
2019-11-25 14:16:24 +01:00
set +x
2019-11-25 13:11:18 +01:00
2019-11-26 15:43:38 +01:00
wait_container $CONTAINER_ID
2019-11-25 13:11:18 +01:00
}
echo "Running in $CONTAINER_ID"
start_container