mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-08-06 17:40:58 +00:00
chore(upgrade): sync lxc-helpers v1.0.3
This commit is contained in:
parent
0e99df94b7
commit
50aec4962b
2 changed files with 132 additions and 104 deletions
|
@ -7,9 +7,10 @@ LXC_SELF_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
LXC_BIN=/usr/local/bin
|
LXC_BIN=/usr/local/bin
|
||||||
LXC_CONTAINER_CONFIG_ALL="unprivileged lxc libvirt docker k8s"
|
LXC_CONTAINER_CONFIG_ALL="unprivileged lxc libvirt docker k8s"
|
||||||
LXC_CONTAINER_CONFIG_DEFAULT="lxc libvirt docker"
|
LXC_CONTAINER_CONFIG_DEFAULT="lxc libvirt docker"
|
||||||
LXC_IPV6_PREFIX_DEFAULT="fc15"
|
LXC_IPV6_PREFIX_DEFAULT="fd15"
|
||||||
LXC_DOCKER_PREFIX_DEFAULT="172.17"
|
LXC_DOCKER_PREFIX_DEFAULT="172.17"
|
||||||
LXC_IPV6_DOCKER_PREFIX_DEFAULT="fd00:d0ca"
|
LXC_IPV6_DOCKER_PREFIX_DEFAULT="fd00:d0ca"
|
||||||
|
LXC_APT_TOO_OLD='1 week ago'
|
||||||
|
|
||||||
: ${LXC_SUDO:=}
|
: ${LXC_SUDO:=}
|
||||||
: ${LXC_CONTAINER_RELEASE:=bookworm}
|
: ${LXC_CONTAINER_RELEASE:=bookworm}
|
||||||
|
@ -196,8 +197,7 @@ EOF
|
||||||
function lxc_container_config() {
|
function lxc_container_config() {
|
||||||
for config in "$@"; do
|
for config in "$@"; do
|
||||||
case $config in
|
case $config in
|
||||||
unprivileged)
|
unprivileged) ;;
|
||||||
;;
|
|
||||||
lxc)
|
lxc)
|
||||||
echo nesting
|
echo nesting
|
||||||
echo cap
|
echo cap
|
||||||
|
@ -277,7 +277,6 @@ function lxc_container_mount() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function lxc_container_start() {
|
function lxc_container_start() {
|
||||||
local name="$1"
|
local name="$1"
|
||||||
|
|
||||||
|
@ -319,6 +318,21 @@ function lxc_exists() {
|
||||||
test "$($LXC_SUDO lxc-ls --filter=^$name\$)"
|
test "$($LXC_SUDO lxc-ls --filter=^$name\$)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function lxc_exists_and_apt_not_old() {
|
||||||
|
local name="$1"
|
||||||
|
|
||||||
|
if lxc_exists $name; then
|
||||||
|
if lxc_apt_is_old $name; then
|
||||||
|
$LXC_SUDO lxc-destroy --force --name="$name"
|
||||||
|
return 1
|
||||||
|
else
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
function lxc_running() {
|
function lxc_running() {
|
||||||
local name="$1"
|
local name="$1"
|
||||||
|
|
||||||
|
@ -328,7 +342,7 @@ function lxc_running() {
|
||||||
function lxc_build_template_release() {
|
function lxc_build_template_release() {
|
||||||
local name="$(lxc_template_release)"
|
local name="$(lxc_template_release)"
|
||||||
|
|
||||||
if lxc_exists $name ; then
|
if lxc_exists_and_apt_not_old $name; then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -346,7 +360,7 @@ function lxc_build_template() {
|
||||||
local name="$1"
|
local name="$1"
|
||||||
local newname="$2"
|
local newname="$2"
|
||||||
|
|
||||||
if lxc_exists $newname ; then
|
if lxc_exists_and_apt_not_old $newname; then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -361,6 +375,20 @@ function lxc_build_template() {
|
||||||
lxc_container_configure $newname
|
lxc_container_configure $newname
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function lxc_apt_age() {
|
||||||
|
local name="$1"
|
||||||
|
$LXC_SUDO stat --format %Y $(lxc_root $name)/var/cache/apt/pkgcache.bin
|
||||||
|
}
|
||||||
|
|
||||||
|
function lxc_apt_is_old() {
|
||||||
|
local name="$1"
|
||||||
|
|
||||||
|
local age=$(lxc_apt_age $name)
|
||||||
|
local too_old=$(date --date "$LXC_APT_TOO_OLD" +%s)
|
||||||
|
|
||||||
|
test $age -lt $too_old
|
||||||
|
}
|
||||||
|
|
||||||
function lxc_apt_install() {
|
function lxc_apt_install() {
|
||||||
local name="$1"
|
local name="$1"
|
||||||
shift
|
shift
|
||||||
|
|
|
@ -101,7 +101,7 @@ ACTIONS IN THE CONTAINER
|
||||||
Install LXC in the `name` container to allow the creation of
|
Install LXC in the `name` container to allow the creation of
|
||||||
named containers. `prefix` is a class C IP prefix from which
|
named containers. `prefix` is a class C IP prefix from which
|
||||||
containers will obtain their IP (for instance 10.40.50). `prefixv6`
|
containers will obtain their IP (for instance 10.40.50). `prefixv6`
|
||||||
is an optional IPv6 private address prefix that defaults to fc15.
|
is an optional IPv6 private address prefix that defaults to fd15.
|
||||||
|
|
||||||
lxc_container_run `name` command [options...]
|
lxc_container_run `name` command [options...]
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue