221 lines
6 KiB
Bash
Executable file
221 lines
6 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
source $(dirname $0)/lxc-helpers-lib.sh
|
|
|
|
function test_destroy() {
|
|
local name="$1"
|
|
|
|
lxc_maybe_sudo
|
|
lxc_container_stop $name
|
|
lxc_container_destroy $name
|
|
}
|
|
|
|
function test_lxc_config() {
|
|
lxc_container_config $LXC_CONTAINER_CONFIG_ALL | tee -a $TMP_DIR/config
|
|
local funcs=${@:-$(set | sed -n -e 's/^lxc_container_config_\([0-9a-z_]*\) .*/\1/p')}
|
|
for func in $funcs ; do
|
|
grep --quiet "include $func" $TMP_DIR/config
|
|
done
|
|
}
|
|
|
|
function test_lxc_helpers_mount_teardown() {
|
|
test_destroy lxc_helpers_mount
|
|
}
|
|
|
|
function test_lxc_helpers_mount() {
|
|
local name=lxc_helpers_mount
|
|
|
|
test_lxc_helpers_mount_teardown
|
|
|
|
lxc_container_create $name
|
|
|
|
lxc_container_mount $name $TMP_DIR
|
|
lxc_container_mount $name $TMP_DIR # do it twice to make sure it is idempotent
|
|
test $($LXC_SUDO grep --count $TMP_DIR $(lxc_config $name)) = 1
|
|
|
|
lxc_container_start $name
|
|
touch $TMP_DIR/lxc_helper_test.stone
|
|
$LXC_SUDO lxc-attach --name $name -- test -f $TMP_DIR/lxc_helper_test.stone
|
|
|
|
test_lxc_helpers_mount_teardown
|
|
}
|
|
|
|
function test_lxc_helpers_id_teardown() {
|
|
LXC_CONTAINER_CONFIG=$LXC_CONTAINER_CONFIG_DEFAULT
|
|
test_destroy lxc_helpers_id
|
|
}
|
|
|
|
function test_lxc_helpers_id() {
|
|
local name=lxc_helpers_id
|
|
|
|
test_lxc_helpers_id_teardown
|
|
LXC_CONTAINER_CONFIG=unprivileged
|
|
|
|
lxc_container_create $name
|
|
|
|
lxc_container_start $name
|
|
lxc_container_user_install $name 1000 debian
|
|
( echo '#!/bin/bash' ; echo id ) | $LXC_SUDO tee $(lxc_root $name)/usr/local/bin/script.sh
|
|
lxc_container_run_script_as $name debian /usr/local/bin/script.sh | tee $TMP_DIR/script.output
|
|
grep debian $TMP_DIR/script.output
|
|
|
|
test_lxc_helpers_id_teardown
|
|
}
|
|
|
|
function test_lxc_helpers_release() {
|
|
local name=$(lxc_template_release)
|
|
|
|
lxc_maybe_sudo
|
|
lxc_container_destroy $name
|
|
|
|
lxc_build_template_release
|
|
|
|
lxc_container_start $name
|
|
$LXC_SUDO lxc-attach --name $name -- which python3
|
|
lxc_container_stop $name
|
|
}
|
|
|
|
function test_lxc_helpers_docker_teardown() {
|
|
LXC_CONTAINER_CONFIG=$LXC_CONTAINER_CONFIG_DEFAULT
|
|
test_destroy lxc_helpers_docker
|
|
}
|
|
|
|
function test_lxc_helpers_docker() {
|
|
local name=lxc_helpers_docker
|
|
|
|
test_lxc_helpers_docker_teardown
|
|
LXC_CONTAINER_CONFIG=docker
|
|
|
|
lxc_container_create $name
|
|
|
|
lxc_container_start $name
|
|
lxc_install_docker $name
|
|
lxc_container_user_install $name 1000 debian
|
|
lxc_apt_install $name iputils-ping
|
|
|
|
(
|
|
cat <<'EOF'
|
|
#!/bin/bash
|
|
|
|
set -ex
|
|
|
|
docker info
|
|
docker run -d --name testcontainer debian:bookworm sleep 200000
|
|
|
|
ipv6=$(docker inspect -f "{{range .NetworkSettings.Networks}}{{.GlobalIPv6Address}}{{end}}" testcontainer)
|
|
ping -w 5 -c 1 -6 $ipv6
|
|
|
|
ipv4=$(docker inspect -f "{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}" testcontainer)
|
|
ping -w 1 -c 1 -4 $ipv4
|
|
|
|
echo SUCCESS
|
|
EOF
|
|
) | $LXC_SUDO tee $(lxc_root $name)/usr/local/bin/script.sh
|
|
lxc_container_run_script_as $name debian /usr/local/bin/script.sh | tee $TMP_DIR/script.output
|
|
grep 'SUCCESS' $TMP_DIR/script.output
|
|
|
|
test_lxc_helpers_docker_teardown
|
|
}
|
|
|
|
function test_lxc_helpers_libvirt_teardown() {
|
|
LXC_CONTAINER_CONFIG=$LXC_CONTAINER_CONFIG_DEFAULT
|
|
test_destroy lxc_helpers_libvirt
|
|
}
|
|
|
|
function test_lxc_helpers_libvirt() {
|
|
local name=lxc_helpers_libvirt
|
|
|
|
test_lxc_helpers_libvirt_teardown
|
|
LXC_CONTAINER_CONFIG=libvirt
|
|
|
|
lxc_container_create $name
|
|
|
|
lxc_container_start $name
|
|
lxc_apt_install $name libvirt-daemon-system
|
|
lxc_container_user_install $name 1000 debian
|
|
|
|
( echo '#!/bin/bash' ; echo '< /dev/kvm' ; echo 'id' ) | $LXC_SUDO tee $(lxc_root $name)/usr/local/bin/script.sh
|
|
lxc_container_run_script_as $name debian /usr/local/bin/script.sh | tee $TMP_DIR/script.output
|
|
grep --quiet '(kvm)' $TMP_DIR/script.output
|
|
grep --quiet '(libvirt)' $TMP_DIR/script.output
|
|
|
|
test_lxc_helpers_libvirt_teardown
|
|
}
|
|
|
|
function test_lxc_helpers_lxc_teardown() {
|
|
LXC_CONTAINER_CONFIG=$LXC_CONTAINER_CONFIG_DEFAULT
|
|
test_destroy lxc_helpers_lxc
|
|
}
|
|
|
|
function test_lxc_helpers_lxc() {
|
|
local name=lxc_helpers_lxc
|
|
|
|
test_lxc_helpers_lxc_teardown
|
|
LXC_CONTAINER_CONFIG=lxc
|
|
|
|
lxc_container_create $name
|
|
|
|
lxc_container_start $name
|
|
local prefix=10.250.100 prefixv6=fc01
|
|
lxc_install_lxc $name $prefix $prefixv6
|
|
$LXC_SUDO lxc-attach --name $name -- systemctl is-active --quiet lxc-net
|
|
$LXC_SUDO lxc-attach --name $name -- apt-get install -qq -y iputils-ping
|
|
$LXC_SUDO lxc-attach --name $name -- ping -w 1 -c 1 -4 $prefix.1
|
|
$LXC_SUDO lxc-attach --name $name -- ping -w 1 -c 1 -6 $prefixv6::216:3eff:fe00:1
|
|
|
|
test_lxc_helpers_lxc_teardown
|
|
}
|
|
|
|
function test_lxc_helpers_k8s_teardown() {
|
|
LXC_CONTAINER_CONFIG=$LXC_CONTAINER_CONFIG_DEFAULT
|
|
test_destroy lxc_helpers_k8s
|
|
}
|
|
|
|
function test_lxc_helpers_k8s() {
|
|
local name=lxc_helpers_k8s
|
|
|
|
test_lxc_helpers_k8s_teardown
|
|
LXC_CONTAINER_CONFIG=k8s
|
|
|
|
lxc_container_create $name
|
|
|
|
lxc_container_start $name
|
|
lxc_apt_install $name curl
|
|
cat <<EOF | $LXC_SUDO tee $(lxc_root $name)/usr/local/bin/script.sh
|
|
#!/bin/bash
|
|
set -xe
|
|
export KUBECONFIG=/etc/rancher/k3s/k3s.yaml
|
|
|
|
curl -sfL https://get.k3s.io | K3S_KUBECONFIG_MODE=0644 sh -
|
|
systemctl is-active --quiet k3s
|
|
|
|
curl -fsSL https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash -
|
|
helm version
|
|
|
|
k3s kubectl get nodes
|
|
|
|
helm show chart oci://codeberg.org/forgejo-contrib/forgejo
|
|
|
|
helm install forgejo oci://codeberg.org/forgejo-contrib/forgejo \
|
|
--set persistence.size=1Gi --set postgresql.primary.persistence.size=1Gi \
|
|
--set service.http.type="LoadBalancer" --debug --atomic --wait \
|
|
--debug --timeout 10m
|
|
|
|
kubectl get service
|
|
|
|
kubectl --namespace default port-forward svc/forgejo-http 3000:3000 & disown
|
|
|
|
curl -X 'GET' \
|
|
-H 'Accept: application/json' \
|
|
'http://localhost:3000/api/v1/version'
|
|
|
|
echo "SUCCESS"
|
|
|
|
EOF
|
|
lxc_container_run_script $name /usr/local/bin/script.sh | tee $TMP_DIR/script.output
|
|
grep --quiet 'SUCCESS' $TMP_DIR/script.output
|
|
|
|
test_lxc_helpers_k8s_teardown
|
|
}
|