First commit

This commit is contained in:
Kay0u 2019-11-25 21:11:18 +09:00
commit 6efdfd0ae9
No known key found for this signature in database
GPG key ID: 7FF262C033518333
4 changed files with 181 additions and 0 deletions

27
base.sh Normal file
View file

@ -0,0 +1,27 @@
#!/usr/bin/env bash
# /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_SLUG=stretch-unstable
#CUSTOM_ENV_CI_DEFAULT_BRANCH=stretch-unstable
#CUSTOM_ENV_CI_JOB_NAME=build1
#CUSTOM_ENV_CI_COMMIT_REF_SLUG=stretch-unstable
#CUSTOM_ENV_CI_BUILD_STAGE=pre-postinstall
#CUSTOM_ENV_CI_JOB_STAGE=pre-postinstall
#CUSTOM_ENV_CI_BUILD_REF_NAME=stretch-unstable
#CUSTOM_ENV_CI_BUILD_NAME=build1
#CUSTOM_ENV_CI_PROJECT_TITLE=yunohost
#CUSTOM_ENV_CI_RUNNER_EXECUTABLE_ARCH=linux/amd64
#CUSTOM_ENV_CI_PROJECT_NAMESPACE=yunohost
#CUSTOM_ENV_CI_COMMIT_REF_NAME=stretch-unstable
#CUSTOM_ENV_CI_PROJECT_NAME=yunohost
#CUSTOM_ENV_CI_PROJECT_DIR=/builds/yunohost/yunohost
CONTAINER_ID="ci"
PROJECT_DIR="$CUSTOM_ENV_CI_PROJECT_DIR"
PROJECT_NAME="$CUSTOM_ENV_CI_PROJECT_NAME"
if [ -z "$SNAPSHOT_NAME" ]
then
SNAPSHOT_NAME="after-postinstall"
fi

10
cleanup.sh Normal file
View file

@ -0,0 +1,10 @@
#!/usr/bin/env bash
# /opt/lxd-executor/cleanup.sh
currentDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
source ${currentDir}/base.sh # Get variables from base.
#echo "Deleting container $CONTAINER_ID"
#lxc delete -f "$CONTAINER_ID"

70
prepare.sh Normal file
View file

@ -0,0 +1,70 @@
#!/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
rebuild_base_container()
{
set -x
lxc info $CONTAINER_ID-rebuild >/dev/null && sudo lxc delete $CONTAINER_ID-rebuild --force
lxc launch images:debian/stretch/amd64 $CONTAINER_ID-rebuild
lxc config set $CONTAINER_ID-rebuild security.privileged true
lxc restart $CONTAINER_ID-rebuild
lxc exec $CONTAINER_ID-rebuild -- apt install curl -y
# 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"
# Install yunohost
lxc exec $CONTAINER_ID-rebuild -- /bin/bash -c "curl https://install.yunohost.org | bash -s -- -a -d unstable"
lxc stop $CONTAINER_ID-rebuild
lxc publish $CONTAINER_ID-rebuild --alias $CONTAINER_ID-base
set +x
}
start_container () {
if ! lxc image info "$CONTAINER_ID-base" &>/dev/null
then
rebuild_base_container
fi
if ! lxc info $CONTAINER_ID | grep -q "before-postinstall"
then
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
# 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 "$CONTAINER_ID" -- sh -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
}
echo "Running in $CONTAINER_ID"
start_container

74
run.sh Normal file
View file

@ -0,0 +1,74 @@
#!/usr/bin/env bash
# /opt/lxd-executor/run.sh
currentDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
source ${currentDir}/base.sh # Get variables from base.
create_sym_link() {
local DEST=$1
local LINK=$2
# Remove current sources if not a symlink
[ -L "$LINK" ] || rm -rf $LINK
# Symlink from Git repository
lxc exec "$CONTAINER_ID" -- sh -c "ln -sfn $DEST $LINK"
}
case ${2} in
prepare_script)
;;
get_sources)
;;
restore_cache)
;;
download_artifacts)
;;
build_script)
case $PROJECT_NAME in
yunohost)
# bin
create_sym_link "$CUSTOM_ENV_CI_PROJECT_DIR/bin/yunohost" "/usr/bin/yunohost"
create_sym_link "$CUSTOM_ENV_CI_PROJECT_DIR/bin/yunohost-api" "/usr/bin/yunohost-api"
# data
create_sym_link "$CUSTOM_ENV_CI_PROJECT_DIR/data/actionsmap/yunohost.yml" "/usr/share/moulinette/actionsmap/yunohost.yml"
create_sym_link "$CUSTOM_ENV_CI_PROJECT_DIR/data/hooks" "/usr/share/yunohost/hooks"
create_sym_link "$CUSTOM_ENV_CI_PROJECT_DIR/data/templates" "/usr/share/yunohost/templates"
create_sym_link "$CUSTOM_ENV_CI_PROJECT_DIR/data/helpers" "/usr/share/yunohost/helpers"
create_sym_link "$CUSTOM_ENV_CI_PROJECT_DIR/data/helpers.d" "/usr/share/yunohost/helpers.d"
create_sym_link "$CUSTOM_ENV_CI_PROJECT_DIR/data/other" "/usr/share/yunohost/yunohost-config/moulinette"
# debian
create_sym_link "$CUSTOM_ENV_CI_PROJECT_DIR/debian/conf/pam/mkhomedir" "/usr/share/pam-configs/mkhomedir"
# lib
create_sym_link "$CUSTOM_ENV_CI_PROJECT_DIR/lib/metronome/modules/ldap.lib.lua" "/usr/lib/metronome/modules/ldap.lib.lua"
create_sym_link "$CUSTOM_ENV_CI_PROJECT_DIR/lib/metronome/modules/mod_auth_ldap2.lua" "/usr/lib/metronome/modules/mod_auth_ldap2.lua"
create_sym_link "$CUSTOM_ENV_CI_PROJECT_DIR/lib/metronome/modules/mod_legacyauth.lua" "/usr/lib/metronome/modules/mod_legacyauth.lua"
create_sym_link "$CUSTOM_ENV_CI_PROJECT_DIR/lib/metronome/modules/mod_storage_ldap.lua" "/usr/lib/metronome/modules/mod_storage_ldap.lua"
create_sym_link "$CUSTOM_ENV_CI_PROJECT_DIR/lib/metronome/modules/vcard.lib.lua" "/usr/lib/metronome/modules/vcard.lib.lua"
# src
create_sym_link "$CUSTOM_ENV_CI_PROJECT_DIR/src/yunohost" "/usr/lib/moulinette/yunohost"
# locales
create_sym_link "$CUSTOM_ENV_CI_PROJECT_DIR/locales" "/usr/lib/moulinette/yunohost/locales"
;;
esac
;;
after_script)
;;
archive_cache)
;;
upload_artifact_on_success)
;;
upload_artifact_on_failure)
;;
esac
lxc exec "$CONTAINER_ID" /bin/bash < "${1}"
if [ $? -ne 0 ]; then
# Exit using the variable, to make the build as failure in GitLab
# CI.
exit $BUILD_FAILURE_EXIT_CODE
fi