Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added optional support for ramfs #138

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions lib/build_base_lxc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ function launch_new_lxc()
{
lxc info $LXC_BASE >/dev/null && lxc delete $LXC_BASE --force

profile_option=""
if [ "$profile" != "" ]; then
profile_option="--profile $profile"
fi

if [ $(get_arch) = $ARCH ];
then
lxc launch images:debian/$DIST/$ARCH $LXC_BASE -c security.privileged=true -c security.nesting=true
lxc launch images:debian/$DIST/$ARCH $LXC_BASE $profile_option -c security.privileged=true -c security.nesting=true
else
lxc image info $LXC_BASE >/dev/null && lxc image delete $LXC_BASE

Expand All @@ -23,7 +28,7 @@ function launch_new_lxc()
popd
rm -rf "$tmp_dir"

lxc launch $LXC_BASE $LXC_BASE -c security.privileged=true -c security.nesting=true
lxc launch $LXC_BASE $LXC_BASE $profile_option -c security.privileged=true -c security.nesting=true
fi
}

Expand All @@ -33,17 +38,17 @@ function rebuild_base_lxc()

launch_new_lxc
sleep 5

IN_LXC="lxc exec $LXC_BASE --"

INSTALL_SCRIPT="https://install.yunohost.org/$DIST"
$IN_LXC apt install curl -y
$IN_LXC /bin/bash -c "curl $INSTALL_SCRIPT | bash -s -- -a -d $YNH_BRANCH"

$IN_LXC systemctl -q stop apt-daily.timer
$IN_LXC systemctl -q stop apt-daily-upgrade.timer
$IN_LXC systemctl -q stop apt-daily.service
$IN_LXC systemctl -q stop apt-daily-upgrade.service
$IN_LXC systemctl -q stop apt-daily-upgrade.service
$IN_LXC systemctl -q disable apt-daily.timer
$IN_LXC systemctl -q disable apt-daily-upgrade.timer
$IN_LXC systemctl -q disable apt-daily.service
Expand Down
8 changes: 8 additions & 0 deletions lib/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ LXC_NAME="ynh-appci-$DIST-$ARCH-$YNH_BRANCH-test-${WORKER_ID}"

readonly lock_file="./pcheck-${WORKER_ID}.lock"

LXC_PROFILE_LIST=(yunohost_ramfs yunohost_btrfs yunohost_dir)

#=================================================
# LXC helpers
#=================================================
Expand Down Expand Up @@ -53,6 +55,12 @@ function check_lxd_setup()

ip a | grep -q lxdbr0 \
|| log_critical "There is no 'lxdbr0' interface... Did you ran 'lxd init' ?"

# Check the asked profile exists
if [[ "$profile" != "" ]] && [[ $(lxc profile list) != *"$profile"* ]]
then
log_critical "The lxd profile asked, $profile, is not configured. Did you run setup_lxd.sh ?"
fi
}

#=================================================
Expand Down
9 changes: 7 additions & 2 deletions lib/lxc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,25 @@

LXC_CREATE () {
log_info "Launching new LXC $LXC_NAME ..."
profile_option=""
if [ "$profile" != "" ]; then
profile_option="--profile $profile"
fi

# Check if we can launch container from YunoHost remote image
if lxc remote list | grep -q "yunohost" && lxc image list yunohost:$LXC_BASE | grep -q -w $LXC_BASE; then
# 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 -_-
LXC_BASE_HASH="$(lxc image list yunohost:ynh-appci-bullseye-amd64-stable-base --format json | jq -r '.[].fingerprint')"
lxc launch yunohost:$LXC_BASE_HASH $LXC_NAME \
lxc launch yunohost:$LXC_BASE_HASH $LXC_NAME $profile_option \
-c security.nesting=true \
-c security.privileged=true \
-c limits.memory=80% \
-c limits.cpu.allowance=80% \
>>/proc/self/fd/3
# Check if we can launch container from a local image
elif lxc image list $LXC_BASE | grep -q -w $LXC_BASE; then
lxc launch $LXC_BASE $LXC_NAME \
lxc launch $LXC_BASE $LXC_NAME $profile_option \
-c security.nesting=true \
-c security.privileged=true \
-c limits.memory=80% \
Expand Down
52 changes: 47 additions & 5 deletions package_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ print_help() {
Usage: package_check.sh [OPTION]... PACKAGE_TO_CHECK

-b, --branch=BRANCH Specify a branch to check.
-a, --arch=ARCH
-d, --dist=DIST
-y, --ynh-branch=BRANCH
-a, --arch=ARCH
-d, --dist=DIST
-y, --ynh-branch=BRANCH
-i, --interactive Wait for the user to continue before each remove
-e, --interactive-on-errors Wait for the user to continue on errors
-s, --force-stop Force the stop of running package_check
-p, --profile=PROFILE LXD profile to use when creating the instance
-r, --rebuild (Re)Build the base container
(N.B.: you're not supposed to use this option,
images are supposed to be fetch from
Expand All @@ -39,6 +40,7 @@ interactive=0
interactive_on_errors=0
rebuild=0
force_stop=0
profile=""

function parse_args() {

Expand All @@ -52,6 +54,11 @@ function parse_args() {
getopts_built_arg+=(-b)
arguments[$i]=${arguments[$i]//--branch=/}
fi
if [[ "${arguments[$i]}" =~ "--profile=" ]]
then
getopts_built_arg+=(-p)
arguments[$i]=${arguments[$i]//--profile=/}
fi
# For each argument in the array, reduce to short argument for getopts
arguments[$i]=${arguments[$i]//--interactive/-i}
arguments[$i]=${arguments[$i]//--rebuild/-r}
Expand All @@ -71,7 +78,7 @@ function parse_args() {
# Initialize the index of getopts
OPTIND=1
# Parse with getopts only if the argument begin by -
getopts ":b:iresh" parameter || true
getopts ":b:iresp:h" parameter || true
case $parameter in
b)
# --branch=branch-name
Expand All @@ -98,6 +105,11 @@ function parse_args() {
force_stop=1
shift_value=1
;;
p)
# --profile=profile
profile="$OPTARG"
shift_value=2
;;
h)
# --help
print_help
Expand Down Expand Up @@ -128,6 +140,28 @@ function parse_args() {
arguments=("$@")
parse_args

#=================================================
# Guess the best lxd profile to apply
#=================================================
select_the_best_profile () {
if [[ "$profile" == "" ]]
then
# No profile preselected try to find one automatically
for name in "${LXC_PROFILE_LIST[@]}"
do
if [[ "$profile" == "" ]] && [[ $(lxc profile list --format=compact) == *"$name"* ]]
then
profile=$name
fi
done
fi

if [[ "$profile" != "" ]]
then
echo "Using LXD profile $profile"
fi
}

#=================================================
# Cleanup / force-stop
#=================================================
Expand Down Expand Up @@ -193,6 +227,8 @@ trap 'exit 2' TERM
assert_we_are_connected_to_the_internets
assert_we_have_all_dependencies

select_the_best_profile

if [[ $rebuild == 1 ]]
then
rebuild_base_lxc 2>&1 | tee -a "./build_base_lxc.log"
Expand All @@ -202,7 +238,13 @@ fi
self_upgrade
fetch_or_upgrade_package_linter

readonly TEST_CONTEXT=$(mktemp -d /tmp/package_check.XXXXXX)
root_tmp_dir=/tmp
if [[ $profile == "yunohost_ramfs" ]]
then
# Download the application into the ramdisk if it exist
root_tmp_dir=/tmp/yunohost_ramfs
fi
readonly TEST_CONTEXT=$(mktemp -d $root_tmp_dir/package_check.XXXXXX)

fetch_package_to_test "$path_to_package_to_test"
run_all_tests
Expand Down
Loading