build-LXD.sh,system_tests.py,build-lxd.yml: Add support for incus

Signed-off-by: Tobias Knöppler <6317548+theCalcaholic@users.noreply.github.com>
Signed-off-by: Tobias K <6317548+theCalcaholic@users.noreply.github.com>
This commit is contained in:
Tobias Knöppler 2024-04-28 18:27:26 +02:00 committed by Tobias K
parent 07dab0b7ee
commit eadb23c049
No known key found for this signature in database
GPG Key ID: 44FD368932E645C1
4 changed files with 118 additions and 102 deletions

View File

@ -34,18 +34,22 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
outputs: outputs:
runner_label: ${{ steps.script.outputs.runner_label }} runner_label: ${{ steps.script.outputs.runner_label }}
lxc_cmd: ${{ steps.script.outputs.lxc_cmd }}
steps: steps:
- name: script - name: script
id: script id: script
run: | run: |
if [[ "${LXD_ARCH}" == "arm64" ]] if [[ "${LXD_ARCH}" == "arm64" ]]
then then
LXC_CMD="incus"
RUNNER_LABEL="ubuntu-20.04-arm64" RUNNER_LABEL="ubuntu-20.04-arm64"
else else
LXC_CMD="lxc"
RUNNER_LABEL="ubuntu-20.04" RUNNER_LABEL="ubuntu-20.04"
fi fi
echo "runner_label=$RUNNER_LABEL" | tee -a $GITHUB_OUTPUT
echo "runner_label=$RUNNER_LABEL" | tee -a $GITHUB_OUTPUT
echo "lxc_cmd=$LXC_CMD" | tee -a $GITHUB_OUTPUT
build-current: build-current:
needs: needs:
- determine-runner - determine-runner
@ -57,14 +61,16 @@ jobs:
VERSION: "${{ inputs.git_ref || github.head_ref || github.ref_name }}" VERSION: "${{ inputs.git_ref || github.head_ref || github.ref_name }}"
ARTIFACT_NAME: "${{ github.run_id }}-lxd-${{ inputs.arch || 'x86' }}-image" ARTIFACT_NAME: "${{ github.run_id }}-lxd-${{ inputs.arch || 'x86' }}-image"
LXD_ARCH: "${{ inputs.arch || 'x86' }}" LXD_ARCH: "${{ inputs.arch || 'x86' }}"
LXC: "${{ needs.determine-runner.outputs.lxc_cmd }}"
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v3 uses: actions/checkout@v3
with: with:
ref: "${{ env.VERSION }}" ref: "${{ env.VERSION }}"
- name: Cleanup lxd - name: Cleanup lxd
run: test -z "$(lxc profile device show default | grep eth0)" || lxc profile device remove default eth0 run: test -z "$("$LXC" profile device show default | grep eth0)" || "$LXC" profile device remove default eth0
- uses: whywaita/setup-lxd@v1 - uses: whywaita/setup-lxd@v1
if: ${{ needs.determine-runner.outputs.lxc_cmd == 'lxc' }}
continue-on-error: true continue-on-error: true
with: with:
lxd_version: latest/stable lxd_version: latest/stable
@ -73,6 +79,8 @@ jobs:
sudo iptables -I DOCKER-USER -i lxdbr0 -j ACCEPT sudo iptables -I DOCKER-USER -i lxdbr0 -j ACCEPT
sudo iptables -I DOCKER-USER -o lxdbr0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT sudo iptables -I DOCKER-USER -o lxdbr0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
- name: Build LXD image - name: Build LXD image
env:
USE_INCUS: "${{ needs.determine-runner.outputs.lxc_cmd == 'incus' && 'yes' || 'no' }}"
run: | run: |
./build/build-LXD.sh ./build/build-LXD.sh
- name: Pack LXD image - name: Pack LXD image
@ -80,7 +88,7 @@ jobs:
run: | run: |
. ./build/buildlib.sh . ./build/buildlib.sh
ARTIFACT_FILE="NextcloudPi_LXD_${LXD_ARCH:-x86}_${VERSION//\//_}" ARTIFACT_FILE="NextcloudPi_LXD_${LXD_ARCH:-x86}_${VERSION//\//_}"
lxc image export -q ncp/"${version}" "output/${ARTIFACT_FILE}" "$LXC" image export -q ncp/"${version}" "output/${ARTIFACT_FILE}"
echo "artifact_file=${ARTIFACT_FILE}.tar.gz" >> $GITHUB_OUTPUT echo "artifact_file=${ARTIFACT_FILE}.tar.gz" >> $GITHUB_OUTPUT
- name: upload LXD image to artifact store - name: upload LXD image to artifact store
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
@ -90,6 +98,8 @@ jobs:
if-no-files-found: error if-no-files-found: error
build-previous: build-previous:
needs:
- determine-runner
runs-on: [ ubuntu-20.04 ] runs-on: [ ubuntu-20.04 ]
if: ${{ inputs.arch == 'x86' || inputs.arch == '' }} if: ${{ inputs.arch == 'x86' || inputs.arch == '' }}
outputs: outputs:
@ -100,6 +110,7 @@ jobs:
VERSION: "${{ inputs.git_ref || github.head_ref || github.ref_name }}" VERSION: "${{ inputs.git_ref || github.head_ref || github.ref_name }}"
ARTIFACT_NAME: "${{ github.run_id }}-lxd-${{ inputs.arch || 'x86' }}-image-previous" ARTIFACT_NAME: "${{ github.run_id }}-lxd-${{ inputs.arch || 'x86' }}-image-previous"
LXD_ARCH: "${{ inputs.arch || 'x86' }}" LXD_ARCH: "${{ inputs.arch || 'x86' }}"
LXC: "${{ needs.determine-runner.outputs.lxc_cmd }}"
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v3 uses: actions/checkout@v3
@ -134,6 +145,7 @@ jobs:
echo "VERSION=$version" >> "$GITHUB_ENV" echo "VERSION=$version" >> "$GITHUB_ENV"
echo "previous_version=${version}" >> $GITHUB_OUTPUT echo "previous_version=${version}" >> $GITHUB_OUTPUT
- uses: whywaita/setup-lxd@v1 - uses: whywaita/setup-lxd@v1
if: ${{ needs.determine-runner.outputs.lxc_cmd == 'lxc' }}
continue-on-error: true continue-on-error: true
with: with:
lxd_version: latest/stable lxd_version: latest/stable
@ -143,6 +155,8 @@ jobs:
sudo iptables -I DOCKER-USER -o lxdbr0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT sudo iptables -I DOCKER-USER -o lxdbr0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
- name: Build LXD image - name: Build LXD image
env:
USE_INCUS: "${{ needs.determine-runner.outputs.lxc_cmd == 'incus' && 'yes' || 'no' }}"
run: | run: |
./build/build-LXD.sh ./build/build-LXD.sh
- name: Pack LXD image - name: Pack LXD image
@ -150,7 +164,7 @@ jobs:
run: | run: |
. ./build/buildlib.sh . ./build/buildlib.sh
ARTIFACT_FILE="NextcloudPi_LXD_${LXD_ARCH:-x86}_${VERSION//\//_}" ARTIFACT_FILE="NextcloudPi_LXD_${LXD_ARCH:-x86}_${VERSION//\//_}"
lxc image export -q ncp/"${version}" "output/${ARTIFACT_FILE}" "${LXC}" image export -q ncp/"${version}" "output/${ARTIFACT_FILE}"
echo "artifact_file=${ARTIFACT_FILE}.tar.gz" >> $GITHUB_OUTPUT echo "artifact_file=${ARTIFACT_FILE}.tar.gz" >> $GITHUB_OUTPUT
- name: upload LXD image to artifact store - name: upload LXD image to artifact store
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
@ -161,6 +175,7 @@ jobs:
test-update: test-update:
needs: needs:
- determine-runner
- build-previous - build-previous
runs-on: [ubuntu-20.04] runs-on: [ubuntu-20.04]
outputs: outputs:
@ -169,8 +184,10 @@ jobs:
env: env:
VERSION: "${{ inputs.git_ref || github.ref }}" VERSION: "${{ inputs.git_ref || github.ref }}"
ARTIFACT_NAME: "${{ needs.build-previous.outputs.artifact_name }}" ARTIFACT_NAME: "${{ needs.build-previous.outputs.artifact_name }}"
LXC: "${{ needs.determine-runner.outputs.lxc_cmd }}"
steps: steps:
- uses: whywaita/setup-lxd@v1 - uses: whywaita/setup-lxd@v1
if: ${{ needs.determine-runner.outputs.lxc_cmd == 'lxc' }}
continue-on-error: true continue-on-error: true
with: with:
lxd_version: latest/stable lxd_version: latest/stable
@ -203,43 +220,43 @@ jobs:
- name: Launch ncp container - name: Launch ncp container
run: | run: |
set -x set -x
lxc delete -q -f ncp || true "$LXC" delete -q -f ncp || true
lxc image import -q "./${{ needs.build-previous.outputs.artifact_file }}" --alias "ncp/update" "$LXC" image import -q "./${{ needs.build-previous.outputs.artifact_file }}" --alias "ncp/update"
systemd-run --user --scope -p "Delegate=yes" lxc launch -q "ncp/update" ncp systemd-run --user --scope -p "Delegate=yes" "$LXC" launch -q "ncp/update" ncp
lxc exec ncp -- bash -c 'while [ "$(systemctl is-system-running 2>/dev/null)" != "running" ] && [ "$(systemctl is-system-running 2>/dev/null)" != "degraded" ]; do :; done' "$LXC" exec ncp -- bash -c 'while [ "$(systemctl is-system-running 2>/dev/null)" != "running" ] && [ "$(systemctl is-system-running 2>/dev/null)" != "degraded" ]; do :; done'
lxc exec ncp -- rm -f /opt/ncdata/data/nextcloud.log "$LXC" exec ncp -- rm -f /opt/ncdata/data/nextcloud.log
sleep 30 sleep 30
ip="$(lxc list -c n4 -f csv | grep '^ncp' | cut -d ',' -f2)" ip="$("$LXC" list -c n4 -f csv | grep '^ncp' | cut -d ',' -f2)"
ip="${ip/% *}" ip="${ip/% *}"
echo "${ip} nextcloudpi.local" | sudo tee /etc/hosts echo "${ip} nextcloudpi.local" | sudo tee /etc/hosts
- name: Activate and Test LXD Image - name: Activate and Test LXD Image
working-directory: ./tests working-directory: ./tests
run: | run: |
lxc exec ncp -- bash -c 'tail -f /var/log/ncp.log' |& awk '{ print "NCP::" $0 }' & "$LXC" exec ncp -- bash -c 'tail -f /var/log/ncp.log' |& awk '{ print "NCP::" $0 }' &
python activation_tests.py --no-gui "nextcloudpi.local" 443 4443 || { python activation_tests.py --no-gui "nextcloudpi.local" 443 4443 || {
echo "Activation test failed!" echo "Activation test failed!"
echo "Geckodriver logs:" echo "Geckodriver logs:"
tail -n 20 geckodriver.log >&2 || true tail -n 20 geckodriver.log >&2 || true
echo "================" echo "================"
echo "ncp.log: " echo "ncp.log: "
lxc exec ncp -- "tail -n20 /var/log/ncp.log" || true "$LXC" exec ncp -- "tail -n20 /var/log/ncp.log" || true
exit 1 exit 1
} }
python system_tests.py --non-interactive || { python system_tests.py --non-interactive || {
echo "System test failed!" echo "System test failed!"
exit 1 exit 1
} }
python nextcloud_tests.py --no-gui "nextcloudpi.local" 443 4443 || { python nextcloud_tests.py --no-gui --skip-release-check "nextcloudpi.local" 443 4443 || {
echo "Nextcloud test failed!" echo "Nextcloud test failed!"
echo "Geckodriver logs:" echo "Geckodriver logs:"
tail -n 20 geckodriver.log >&2 || true tail -n 20 geckodriver.log >&2 || true
echo "================" echo "================"
echo "ncp.log: " echo "ncp.log: "
lxc exec ncp -- "tail -n20 /var/log/ncp.log" || true "$LXC" exec ncp -- "tail -n20 /var/log/ncp.log" || true
echo "================" echo "================"
echo "nextcloud log: " echo "nextcloud log: "
datadir="$(lxc exec ncp -- ncc config:system:get datadirectory)" datadir="$("$LXC" exec ncp -- ncc config:system:get datadirectory)"
lxc exec ncp -- cat "$datadir/nextcloud.log" || true "$LXC" exec ncp -- cat "$datadir/nextcloud.log" || true
exit 1 exit 1
} }
@ -250,42 +267,61 @@ jobs:
BRANCH="${BRANCH/refs\/tags\//}" BRANCH="${BRANCH/refs\/tags\//}"
if [[ "$BRANCH" =~ "refs/pull/"* ]] if [[ "$BRANCH" =~ "refs/pull/"* ]]
then then
UPDATE_ARGS=("${{ github.base_ref }}" "$VERSION") UPDATE_ARGS=("${{ github.head_ref }}" "$VERSION")
else else
UPDATE_ARGS=("$BRANCH") UPDATE_ARGS=("$BRANCH")
fi fi
echo "VERSION=${VERSION}" >> "$GITHUB_ENV" echo "VERSION=${VERSION}" >> "$GITHUB_ENV"
echo "Running update ${{ needs.build-previous.outputs.previous_version }} -> ${VERSION}" echo "Running update ${{ needs.build-previous.outputs.previous_version }} -> ${VERSION}"
current_nc_version="$(lxc exec ncp -- ncc status | grep "version:" | awk '{ print $3 }')" current_nc_version="$("$LXC" exec ncp -- ncc status | grep "version:" | awk '{ print $3 }')"
latest_nc_version="$(cat etc/ncp.cfg | jq -r '.nextcloud_version')" latest_nc_version="$(cat etc/ncp.cfg | jq -r '.nextcloud_version')"
lxc exec ncp -- bash -c "DBG=x ncp-update ${UPDATE_ARGS[*]}" "$LXC" exec ncp -- bash -c "DBG=x ncp-update ${UPDATE_ARGS[*]}"
lxc exec ncp -- /usr/local/bin/ncc status "$LXC" exec ncp -- /usr/local/bin/ncc status
if [[ "$current_nc_version" =~ "$latest_nc_version".* ]] if [[ "$current_nc_version" =~ "$latest_nc_version".* ]]
then then
echo "Nextcloud is up to date - skipping NC update test." echo "Nextcloud is up to date - skipping NC update test."
else else
lxc exec ncp -- bash -c "DBG=x ncp-update-nc ${latest_nc_version?}" "$LXC" exec ncp -- bash -c "DBG=x ncp-update-nc ${latest_nc_version?}"
fi fi
lxc exec ncp -- rm -f /opt/ncdata/data/nextcloud.log "$LXC" exec ncp -- rm -f /opt/ncdata/data/nextcloud.log
lxc stop ncp "$LXC" stop ncp
- name: Relaunch container - name: Relaunch container
run: | run: |
set -x set -x
systemd-run --user --scope -p "Delegate=yes" lxc start ncp systemd-run --user --scope -p "Delegate=yes" "$LXC" start ncp
lxc exec ncp -- bash -c 'while [ "$(systemctl is-system-running 2>/dev/null)" != "running" ] && [ "$(systemctl is-system-running 2>/dev/null)" != "degraded" ]; do :; done' "$LXC" exec ncp -- bash -c 'while [ "$(systemctl is-system-running 2>/dev/null)" != "running" ] && [ "$(systemctl is-system-running 2>/dev/null)" != "degraded" ]; do :; done'
sleep 30 sleep 30
ip="$(lxc list -c n4 -f csv | grep '^ncp' | cut -d ',' -f2)" ip="$("$LXC" list -c n4 -f csv | grep '^ncp' | cut -d ',' -f2)"
ip="${ip/% *}" ip="${ip/% *}"
echo "${ip} nextcloudpi.local" | sudo tee /etc/hosts echo "${ip} nextcloudpi.local" | sudo tee /etc/hosts
- name: Test LXD Image - name: Test LXD Image
working-directory: ./tests working-directory: ./tests
run: | run: |
lxc exec ncp -- bash -c 'tail -f /var/log/ncp.log' |& awk '{ print "NCP::" $0 }' & lxc exec ncp -- bash -c 'tail -f /var/log/ncp.log' |& awk '{ print "NCP::" $0 }' &
"$LXC" exec ncp -- bash -c 'tail -f /var/log/ncp.log' |& awk '{ print "NCP::" $0 }' &
python system_tests.py --non-interactive || {
echo "System test failed!"
exit 1
}
python nextcloud_tests.py --no-gui --skip-release-check "nextcloudpi.local" 443 4443 || {
echo "Nextcloud test failed!"
echo "Geckodriver logs:"
tail -n 20 geckodriver.log >&2 || true
echo "================"
echo "ncp.log: "
"$LXC" exec ncp -- "tail -n20 /var/log/ncp.log" || true
echo "================"
echo "nextcloud log: "
datadir="$("$LXC" exec ncp -- ncc config:system:get datadirectory)"
"$LXC" exec ncp -- cat "$datadir/nextcloud.log" || true
exit 1
}
python system_tests.py --non-interactive || { python system_tests.py --non-interactive || {
echo "System test failed!" echo "System test failed!"
exit 1 exit 1
@ -296,14 +332,14 @@ jobs:
tail -n 20 geckodriver.log >&2 || true tail -n 20 geckodriver.log >&2 || true
echo "================" echo "================"
echo "ncp.log: " echo "ncp.log: "
lxc exec ncp -- "tail -n20 /var/log/ncp.log" || true "$LXC" exec ncp -- "tail -n20 /var/log/ncp.log" || true
echo "================" echo "================"
echo "nextcloud log: " echo "nextcloud log: "
datadir="$(lxc exec ncp -- ncc config:system:get datadirectory)" datadir="$("$LXC" exec ncp -- ncc config:system:get datadirectory)"
lxc exec ncp -- cat "$datadir/nextcloud.log" || true "$LXC" exec ncp -- cat "$datadir/nextcloud.log" || true
exit 1 exit 1
} }
lxc stop ncp "$LXC" stop ncp
test-fresh-install: test-fresh-install:
needs: needs:
@ -314,14 +350,16 @@ jobs:
VERSION: "${{ inputs.git_ref || github.head_ref || github.ref_name }}" VERSION: "${{ inputs.git_ref || github.head_ref || github.ref_name }}"
ARTIFACT_NAME: ${{ needs.build-current.outputs.artifact_name }} ARTIFACT_NAME: ${{ needs.build-current.outputs.artifact_name }}
ARTIFACT_FILE: ${{ needs.build-current.outputs.artifact_file }} ARTIFACT_FILE: ${{ needs.build-current.outputs.artifact_file }}
LXC: "${{ needs.determine-runner.outputs.lxc_cmd }}"
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v3 uses: actions/checkout@v3
with: with:
ref: "${{ env.VERSION }}" ref: "${{ env.VERSION }}"
- name: Cleanup lxd - name: Cleanup lxd
run: test -z "$(lxc profile device show default | grep eth0)" || lxc profile device remove default eth0 run: test -z "$("$LXC" profile device show default | grep eth0)" || "$LXC" profile device remove default eth0
- uses: whywaita/setup-lxd@v1 - uses: whywaita/setup-lxd@v1
if: ${{ needs.determine-runner.outputs.lxc_cmd == 'lxc' }}
continue-on-error: true continue-on-error: true
with: with:
lxd_version: latest/stable lxd_version: latest/stable
@ -347,38 +385,38 @@ jobs:
- name: Remove old lxd images - name: Remove old lxd images
if: ${{ inputs.arch == 'arm64' }} if: ${{ inputs.arch == 'arm64' }}
run: | run: |
for img in $(lxc image list -c f -f csv) for img in $("$LXC" image list -c f -f csv)
do do
lxc image delete "$img" "$LXC" image delete "$img"
done done
- name: Launch ncp container - name: Launch ncp container
run: | run: |
set -x set -x
. ./build/buildlib.sh . ./build/buildlib.sh
lxc delete -q -f ncp || true "$LXC" delete -q -f ncp || true
lxc image import -q "./${ARTIFACT_FILE?}" --alias "ncp/test" || true "$LXC" image import -q "./${ARTIFACT_FILE?}" --alias "ncp/test" || true
systemd-run --user --scope -p "Delegate=yes" lxc launch -q "ncp/test" ncp || \ systemd-run --user --scope -p "Delegate=yes" "$LXC" launch -q "ncp/test" ncp || \
sudo systemd-run --scope -p "Delegate=yes" lxc launch -q "ncp/test" ncp sudo systemd-run --scope -p "Delegate=yes" "$LXC" launch -q "ncp/test" ncp
lxc exec ncp -- bash -c 'while [ "$(systemctl is-system-running 2>/dev/null)" != "running" ] && [ "$(systemctl is-system-running 2>/dev/null)" != "degraded" ]; do :; done' "$LXC" exec ncp -- bash -c 'while [ "$(systemctl is-system-running 2>/dev/null)" != "running" ] && [ "$(systemctl is-system-running 2>/dev/null)" != "degraded" ]; do :; done'
sleep 30 sleep 30
ip="$(lxc list -c n4 -f csv | grep '^ncp' | cut -d ',' -f2)" ip="$("$LXC" list -c n4 -f csv | grep '^ncp' | cut -d ',' -f2)"
ip="${ip/% *}" ip="${ip/% *}"
echo "${ip} nextcloudpi.local" | sudo tee /etc/hosts echo "${ip} nextcloudpi.local" | sudo tee /etc/hosts
- name: Test LXD Image - name: Test LXD Image
working-directory: ./tests working-directory: ./tests
run: | run: |
lxc exec ncp -- bash -c 'tail -f /var/log/ncp.log' |& awk '{ print "NCP::" $0 }' & "$LXC" exec ncp -- bash -c 'tail -f /var/log/ncp.log' |& awk '{ print "NCP::" $0 }' &
python activation_tests.py --no-gui "nextcloudpi.local" 443 4443 || { python activation_tests.py --no-gui "nextcloudpi.local" 443 4443 || {
echo "Activation test failed!" echo "Activation test failed!"
echo "Geckodriver logs:" echo "Geckodriver logs:"
tail -n 20 geckodriver.log >&2 || true tail -n 20 geckodriver.log >&2 || true
echo "================" echo "================"
echo "ncp.log: " echo "ncp.log: "
lxc exec ncp -- "tail -n20 /var/log/ncp.log" || true "$LXC" exec ncp -- "tail -n20 /var/log/ncp.log" || true
echo "================" echo "================"
echo "nextcloud log: " echo "nextcloud log: "
datadir="$(lxc exec ncp -- ncc config:system:get datadirectory)" datadir="$("$LXC" exec ncp -- ncc config:system:get datadirectory)"
lxc exec ncp -- cat "$datadir/nextcloud.log" || true "$LXC" exec ncp -- cat "$datadir/nextcloud.log" || true
exit 1 exit 1
} }
python system_tests.py --non-interactive || { python system_tests.py --non-interactive || {
@ -391,11 +429,11 @@ jobs:
tail -n 20 geckodriver.log >&2 || true tail -n 20 geckodriver.log >&2 || true
echo "================" echo "================"
echo "ncp.log: " echo "ncp.log: "
lxc exec ncp -- "tail -n20 /var/log/ncp.log" || true "$LXC" exec ncp -- "tail -n20 /var/log/ncp.log" || true
echo "================" echo "================"
echo "nextcloud log: " echo "nextcloud log: "
datadir="$(lxc exec ncp -- ncc config:system:get datadirectory)" datadir="$("$LXC" exec ncp -- ncc config:system:get datadirectory)"
lxc exec ncp -- cat "$datadir/nextcloud.log" || true "$LXC" exec ncp -- cat "$datadir/nextcloud.log" || true
exit 1 exit 1
} }
lxc stop ncp lxc stop ncp

View File

@ -31,15 +31,20 @@ prepare_dirs # tmp cache output
## BUILD NCP ## BUILD NCP
lxc delete -f ncp 2>/dev/null || true debian_version="$(. etc/library.sh > /dev/null 2>&1; echo "${RELEASE%%-security}")"
LXC_CREATE=(lxc init -p default)
LXC_CMD=lxc
[[ "$USE_INCUS" == "yes" ]] && LXC_CMD=incus
$LXC_CMD delete -f ncp 2>/dev/null || true
LXC_CREATE=($LXC_CMD init -p default)
[[ -n "$LXD_EXTRA_PROFILE" ]] && LXC_CREATE+=(-p "$LXD_EXTRA_PROFILE") [[ -n "$LXD_EXTRA_PROFILE" ]] && LXC_CREATE+=(-p "$LXD_EXTRA_PROFILE")
if [[ -n "$LXD_ARCH" ]] && [[ "$LXD_ARCH" != "x86" ]] if [[ -n "$LXD_ARCH" ]] && [[ "$LXD_ARCH" != "x86" ]]
then then
echo "Building for architecture: $LXD_ARCH" echo "Building for architecture: $LXD_ARCH"
LXC_CREATE+=("images:debian/bullseye/$LXD_ARCH") LXC_CREATE+=("images:debian/${debian_version}/$LXD_ARCH")
else else
LXC_CREATE+=('images:debian/bullseye') LXC_CREATE+=("images:debian/${debian_version}")
fi fi
LXC_CREATE+=(ncp) LXC_CREATE+=(ncp)
"${LXC_CREATE[@]}" "${LXC_CREATE[@]}"
@ -56,19 +61,20 @@ LXC_CREATE+=(ncp)
# fi # fi
#fi #fi
systemd-run --user --scope -p "Delegate=yes" lxc start ncp -q || \ set -x
sudo systemd-run --scope -p "Delegate=yes" lxc start ncp -q systemd-run --user --scope -p "Delegate=yes" $LXC_CMD start ncp -q || \
lxc config device add ncp buildcode disk source="$(pwd)" path=/build sudo systemd-run --scope -p "Delegate=yes" $LXC_CMD start ncp -q
lxc exec ncp -- bash -c 'while [ "$(systemctl is-system-running 2>/dev/null)" != "running" ] && [ "$(systemctl is-system-running 2>/dev/null)" != "degraded" ]; do :; done' $LXC_CMD config device add ncp buildcode disk source="$(pwd)" path=/build
lxc exec ncp -- bash -c 'CODE_DIR=/build DBG=x bash /build/install.sh' $LXC_CMD exec ncp -- bash -c 'while [ "$(systemctl is-system-running 2>/dev/null)" != "running" ] && [ "$(systemctl is-system-running 2>/dev/null)" != "degraded" ]; do :; done'
lxc exec ncp -- bash -c 'source /build/etc/library.sh; run_app_unsafe /build/post-inst.sh' $LXC_CMD exec ncp -- bash -c 'CODE_DIR=/build DBG=x bash /build/install.sh'
lxc exec ncp -- bash -c "echo '$(basename "$IMG")' > /usr/local/etc/ncp-baseimage" $LXC_CMD exec ncp -- bash -c 'source /build/etc/library.sh; run_app_unsafe /build/post-inst.sh'
lxc stop ncp $LXC_CMD exec ncp -- bash -c "echo '$(basename "$IMG")' > /usr/local/etc/ncp-baseimage"
lxc config device remove ncp buildcode $LXC_CMD stop ncp
lxc publish -q ncp -f --alias ncp/"${version}" $LXC_CMD config device remove ncp buildcode
$LXC_CMD publish -q ncp -f --alias ncp/"${version}"
## pack ## pack
[[ " $* " =~ .*" --pack ".* ]] && lxc image export -q ncp/"${version}" "$TAR" [[ " $* " =~ .*" --pack ".* ]] && $LXC_CMD image export -q ncp/"${version}" "$TAR"
exit 0 exit 0

View File

@ -335,43 +335,6 @@ function generate_changelog()
sed 's|* \[tag: |\n[|' > changelog.md sed 's|* \[tag: |\n[|' > changelog.md
} }
function upload_ftp()
{
local IMGNAME="$1"
echo -e "\n\e[1m[ Upload FTP ]\e[0m"
echo "* $IMGNAME..."
[[ -f torrent/"$IMGNAME"/"$IMGNAME".tar.bz2 ]] || { echo "No image file found, abort"; return 1; }
[[ "$FTPPASS" == "" ]] && { echo "No FTPPASS variable found, skip upload"; return 0; }
cd torrent
ftp -np ftp.ownyourbits.com <<EOF
user root@ownyourbits.com $FTPPASS
mkdir testing
mkdir testing/$IMGNAME
cd testing/$IMGNAME
binary
rm $IMGNAME.torrent
put $IMGNAME.torrent
bye
EOF
cd -
cd torrent/$IMGNAME
ftp -np ftp.ownyourbits.com <<EOF
user root@ownyourbits.com $FTPPASS
cd testing/$IMGNAME
binary
rm $IMGNAME.tar.bz2
put $IMGNAME.tar.bz2
rm md5sum
put md5sum
bye
EOF
ret=$?
cd -
return $ret
}
upload_images() upload_images()
{ {

View File

@ -59,6 +59,10 @@ files_must_not_exist = [
'/.ncp-image', '/.ncp-image',
] ]
lxc_command = 'lxc'
if 'USE_INCUS' in os.environ and os.environ['USE_INCUS'] == 'yes':
lxc_command = 'incus'
class tc: class tc:
"terminal colors" "terminal colors"
@ -226,8 +230,13 @@ def test_autoupdates():
return False return False
set_cohorte_id(99) set_cohorte_id(99)
handle_error(run(pre_cmd + ['/usr/local/bin/ncp-check-version'], stdout=PIPE, stderr=PIPE)) chk_version = handle_error(run(pre_cmd + ['/usr/local/bin/ncp-check-version'], stdout=PIPE, stderr=PIPE))
result = handle_error(run(pre_cmd + ['cat', '/var/run/.ncp-latest-version'], stdout=PIPE, stderr=PIPE)) try:
result = handle_error(run(pre_cmd + ['cat', '/var/run/.ncp-latest-version'], stdout=PIPE, stderr=PIPE))
except ProcessExecutionException as e:
print("stderr:", chk_version.stderr)
print("stdout:", chk_version.stdout)
raise e
if 'v99.99.99' not in result.stdout: if 'v99.99.99' not in result.stdout:
print(f"{tc.red}error{tc.normal} Expected latest detected version to be v99.99.99, was {result.stdout}") print(f"{tc.red}error{tc.normal} Expected latest detected version to be v99.99.99, was {result.stdout}")
return False return False
@ -291,7 +300,7 @@ if __name__ == "__main__":
# detect if we are running this in a LXC instance # detect if we are running this in a LXC instance
try: try:
lxc_running = run(['lxc', 'info', 'ncp'], stdout=PIPE, check = True) lxc_running = run([lxc_command, 'info', 'ncp'], stdout=PIPE, check = True)
except: except:
lxc_running = False lxc_running = False
@ -319,7 +328,7 @@ if __name__ == "__main__":
# LXC method # LXC method
elif lxc_running: elif lxc_running:
print( tc.brown + "* local LXC instance detected" + tc.normal) print( tc.brown + "* local LXC instance detected" + tc.normal)
pre_cmd = ['lxc', 'exec', 'ncp', '--'] pre_cmd = [lxc_command, 'exec', 'ncp', '--']
elif systemd_container_running: elif systemd_container_running:
pre_cmd = ['systemd-run', '--wait', '-P', '--machine=ncp'] pre_cmd = ['systemd-run', '--wait', '-P', '--machine=ncp']