mirror of
https://github.com/YunoHost/ynh-dev.git
synced 2024-09-03 20:05:59 +02:00
Allow the use of incus instead of LXD. In the future, we could remove LXD support, making the README way shorter (no snap, etc)
This commit is contained in:
parent
5c8e3e773b
commit
be80111c61
1 changed files with 68 additions and 24 deletions
92
ynh-dev
92
ynh-dev
|
@ -3,14 +3,16 @@
|
||||||
function show_usage() {
|
function show_usage() {
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
|
|
||||||
${BLUE}On the host, to manage the LXC${NORMAL}
|
${BLUE}On the host, to manage boxes${NORMAL}
|
||||||
${BLUE}==============================${NORMAL}
|
${BLUE}============================${NORMAL}
|
||||||
|
|
||||||
start [DIST] [NAME] [YNH_BRANCH] (Create and) starts a LXC (DIST=bookworm, NAME=ynh-dev and YNH_BRANCH=unstable by default)
|
start [DIST] [NAME] [YNH_BRANCH] (Create and) starts a box (DIST=bookworm, NAME=ynh-dev and YNH_BRANCH=unstable by default)
|
||||||
attach [DIST] [NAME] [YNH_BRANCH] Attach an already started LXC (DIST=bookworm, NAME=ynh-dev and YNH_BRANCH=unstable by default)
|
attach [DIST] [NAME] [YNH_BRANCH] Attach an already started box (DIST=bookworm, NAME=ynh-dev and YNH_BRANCH=unstable by default)
|
||||||
destroy [DIST] [NAME] [YNH_BRANCH] Destroy the ynh-dev LXC (DIST=bookworm, NAME=ynh-dev and YNH_BRANCH=unstable by default)
|
destroy [DIST] [NAME] [YNH_BRANCH] Destroy the ynh-dev box (DIST=bookworm, NAME=ynh-dev and YNH_BRANCH=unstable by default)
|
||||||
rebuild [DIST] [NAME] [YNH_BRANCH] Rebuild a fresh, up-to-date box (DIST=bookworm, NAME=ynh-dev and YNH_BRANCH=unstable by default)
|
rebuild [DIST] [NAME] [YNH_BRANCH] Rebuild a fresh, up-to-date box (DIST=bookworm, NAME=ynh-dev and YNH_BRANCH=unstable by default)
|
||||||
|
|
||||||
|
Pass YNHDEV_BACKEND=incus to use incus instead of lxd.
|
||||||
|
|
||||||
${BLUE}Inside the dev instance${NORMAL}
|
${BLUE}Inside the dev instance${NORMAL}
|
||||||
${BLUE}=======================${NORMAL}
|
${BLUE}=======================${NORMAL}
|
||||||
|
|
||||||
|
@ -168,25 +170,67 @@ function check_lxd_setup()
|
||||||
|| critical "There is no 'lxcbr0' or 'lxdbr0' interface... Did you ran 'lxd init' ?"
|
|| critical "There is no 'lxcbr0' or 'lxdbr0' interface... Did you ran 'lxd init' ?"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function check_incus_setup()
|
||||||
|
{
|
||||||
|
# Check incus is installed somehow
|
||||||
|
if ! which incus &>/dev/null; then
|
||||||
|
critical "You need to have Incus installed for ynh-dev to be usable from the host machine. Refer to the README to know how to install it."
|
||||||
|
fi
|
||||||
|
if ! id -nG "$(whoami)" | grep -qw "incus-admin"; then
|
||||||
|
critical "You need to be in the incus-admin group!"
|
||||||
|
fi
|
||||||
|
|
||||||
|
ip a | grep -q incusbr0 \
|
||||||
|
|| warn "There is no 'incusbr0' interface... Did you ran 'incus admin init' ?"
|
||||||
|
|
||||||
|
set_incus_remote
|
||||||
|
}
|
||||||
|
|
||||||
|
function set_incus_remote()
|
||||||
|
{
|
||||||
|
configured=$(incus remote list -f json | jq 'has("yunohost")')
|
||||||
|
if [[ "$configured" != "true" ]]; then
|
||||||
|
incus remote add yunohost https://devbaseimgs.yunohost.org --public
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function check_setup()
|
||||||
|
{
|
||||||
|
if [[ "${YNHDEV_BACKEND:-}" == "incus" ]]; then
|
||||||
|
check_incus_setup
|
||||||
|
else
|
||||||
|
check_lxd_setup
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function backend()
|
||||||
|
{
|
||||||
|
if [[ "${YNHDEV_BACKEND:-}" == "incus" ]]; then
|
||||||
|
incus "$@"
|
||||||
|
else
|
||||||
|
sudo lxc "$@"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
function start_ynhdev()
|
function start_ynhdev()
|
||||||
{
|
{
|
||||||
check_lxd_setup
|
check_setup
|
||||||
|
|
||||||
local DIST=${1:-bookworm}
|
local DIST=${1:-bookworm}
|
||||||
local YNH_BRANCH=${3:-unstable}
|
local YNH_BRANCH=${3:-unstable}
|
||||||
local BOX=${2:-ynh-dev}-${DIST}-${YNH_BRANCH}
|
local BOX=${2:-ynh-dev}-${DIST}-${YNH_BRANCH}
|
||||||
|
|
||||||
if ! sudo lxc info $BOX &>/dev/null
|
if ! backend info $BOX &>/dev/null
|
||||||
then
|
then
|
||||||
if ! sudo lxc image info $BOX-base &>/dev/null
|
if ! backend image info $BOX-base &>/dev/null
|
||||||
then
|
then
|
||||||
LXC_BASE="ynh-dev-$DIST-amd64-$YNH_BRANCH-base"
|
LXC_BASE="ynh-dev-$DIST-amd64-$YNH_BRANCH-base"
|
||||||
sudo lxc launch yunohost:$LXC_BASE $BOX -c security.nesting=true -c security.privileged=true \
|
backend launch yunohost:$LXC_BASE $BOX -c security.nesting=true -c security.privileged=true \
|
||||||
|| critical "Failed to launch the container ?"
|
|| critical "Failed to launch the container ?"
|
||||||
else
|
else
|
||||||
sudo lxc launch $BOX-base $BOX -c security.nesting=true -c security.privileged=true
|
backend launch $BOX-base $BOX -c security.nesting=true -c security.privileged=true
|
||||||
fi
|
fi
|
||||||
sudo lxc config device add $BOX ynhdev-shared-folder disk path=/ynh-dev source="$(readlink -f $(pwd))"
|
backend config device add $BOX ynhdev-shared-folder disk path=/ynh-dev source="$(readlink -f $(pwd))"
|
||||||
info "Now attaching to the container"
|
info "Now attaching to the container"
|
||||||
else
|
else
|
||||||
info "Attaching to existing container"
|
info "Attaching to existing container"
|
||||||
|
@ -197,41 +241,41 @@ function start_ynhdev()
|
||||||
|
|
||||||
function attach_ynhdev()
|
function attach_ynhdev()
|
||||||
{
|
{
|
||||||
check_lxd_setup
|
check_setup
|
||||||
local DIST=${1:-bookworm}
|
local DIST=${1:-bookworm}
|
||||||
local YNH_BRANCH=${3:-unstable}
|
local YNH_BRANCH=${3:-unstable}
|
||||||
local BOX=${2:-ynh-dev}-${DIST}-${YNH_BRANCH}
|
local BOX=${2:-ynh-dev}-${DIST}-${YNH_BRANCH}
|
||||||
sudo lxc start $BOX 2>/dev/null || true
|
backend start $BOX 2>/dev/null || true
|
||||||
sudo lxc exec $BOX --cwd /ynh-dev -- /bin/bash
|
backend exec $BOX --cwd /ynh-dev -- /bin/bash
|
||||||
}
|
}
|
||||||
|
|
||||||
function destroy_ynhdev()
|
function destroy_ynhdev()
|
||||||
{
|
{
|
||||||
check_lxd_setup
|
check_setup
|
||||||
local DIST=${1:-bookworm}
|
local DIST=${1:-bookworm}
|
||||||
local YNH_BRANCH=${3:-unstable}
|
local YNH_BRANCH=${3:-unstable}
|
||||||
local BOX=${2:-ynh-dev}-${DIST}-${YNH_BRANCH}
|
local BOX=${2:-ynh-dev}-${DIST}-${YNH_BRANCH}
|
||||||
sudo lxc stop $BOX
|
backend stop $BOX
|
||||||
sudo lxc delete $BOX
|
backend delete $BOX
|
||||||
}
|
}
|
||||||
|
|
||||||
function rebuild_ynhdev()
|
function rebuild_ynhdev()
|
||||||
{
|
{
|
||||||
check_lxd_setup
|
check_setup
|
||||||
|
|
||||||
local DIST=${1:-bookworm}
|
local DIST=${1:-bookworm}
|
||||||
local YNH_BRANCH=${3:-unstable}
|
local YNH_BRANCH=${3:-unstable}
|
||||||
local BOX=${2:-ynh-dev}-${DIST}-${YNH_BRANCH}
|
local BOX=${2:-ynh-dev}-${DIST}-${YNH_BRANCH}
|
||||||
|
|
||||||
set -x
|
set -x
|
||||||
sudo lxc info $BOX-rebuild >/dev/null && sudo lxc delete $BOX-rebuild --force
|
backend info $BOX-rebuild >/dev/null && backend delete $BOX-rebuild --force
|
||||||
sudo lxc launch images:debian/$DIST/amd64 $BOX-rebuild -c security.nesting=true -c security.privileged=true
|
backend launch images:debian/$DIST/amd64 $BOX-rebuild -c security.nesting=true -c security.privileged=true
|
||||||
sleep 5
|
sleep 5
|
||||||
sudo lxc exec $BOX-rebuild -- apt install curl -y
|
backend exec $BOX-rebuild -- apt install curl -y
|
||||||
INSTALL_SCRIPT="https://install.yunohost.org/$DIST"
|
INSTALL_SCRIPT="https://install.yunohost.org/$DIST"
|
||||||
sudo lxc exec $BOX-rebuild -- /bin/bash -c "curl $INSTALL_SCRIPT | bash -s -- -a -d $YNH_BRANCH"
|
backend exec $BOX-rebuild -- /bin/bash -c "curl $INSTALL_SCRIPT | bash -s -- -a -d $YNH_BRANCH"
|
||||||
sudo lxc stop $BOX-rebuild
|
backend stop $BOX-rebuild
|
||||||
sudo lxc publish $BOX-rebuild --alias $BOX-base
|
backend publish $BOX-rebuild --alias $BOX-base
|
||||||
set +x
|
set +x
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue