Skip to content

Commit

Permalink
build-sd-images.yml: Setup test environment
Browse files Browse the repository at this point in the history
Signed-off-by: Tobias Knöppler <[email protected]>
  • Loading branch information
theCalcaholic committed Sep 3, 2024
1 parent 31d5ed9 commit 8d9c987
Show file tree
Hide file tree
Showing 2 changed files with 290 additions and 281 deletions.
247 changes: 128 additions & 119 deletions .github/workflows/build-sd-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,120 +22,120 @@ on:
value: "${{ jobs.build.outputs.artifact_file }}"

jobs:
build:
runs-on: ubuntu-20.04
env:
VERSION: "${{ inputs.git_ref }}"
LOG_GUEST: "\\033[1;34mGUEST::\\033[0m"
LOG_NCP: "\\033[1;36m~NCP::\\033[0m"
LOG_CICD: "\\033[1;35mCICD::\\033[0m"
LOG_TEST: "\\033[1;33mTEST::\\033[0m"
LOG_DIAG: "\\033[1;31mDIAG::\\033[0m"
defaults:
run:
shell: bash
outputs:
artifact_file: ${{ env.ARTIFACT_FILE }}
artifact_name: ${{ github.run_id }}-${{ inputs.board_id }}-image
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
# build:
# runs-on: ubuntu-20.04
# env:
# VERSION: "${{ inputs.git_ref }}"
# LOG_GUEST: "\\033[1;34mGUEST::\\033[0m"
# LOG_NCP: "\\033[1;36m~NCP::\\033[0m"
# LOG_CICD: "\\033[1;35mCICD::\\033[0m"
# LOG_TEST: "\\033[1;33mTEST::\\033[0m"
# LOG_DIAG: "\\033[1;31mDIAG::\\033[0m"
# defaults:
# run:
# shell: bash
# outputs:
# artifact_file: ${{ env.ARTIFACT_FILE }}
# artifact_name: ${{ github.run_id }}-${{ inputs.board_id }}-image
# steps:
# - name: Set up QEMU
# uses: docker/setup-qemu-action@v3
## - name: Set up QEMU
## run: |
## sudo apt-get update
## sudo apt-get install -y binfmt-support
## curl -L -o /tmp/qemu.sh 'https://raw.githubusercontent.com/qemu/qemu/master/scripts/qemu-binfmt-conf.sh'
## bash /tmp/qemu.sh --debian
## sudo systemctl disable apparmor
## docker run --rm --privileged tonistiigi/binfmt:latest --install all
## docker run --rm --privileged multiarch/qemu-user-static:register --reset --credential yes
## sudo mkdir -p /etc/binfmt
## for conf in qemu-{aarch64,arm}-static.conf
## do
## sed 's/:F$/:OC/' /usr/lib/binfmt.d/$conf | sudo tee /etc/binfmt/$conf
## done
# - name: Checkout code
# uses: actions/checkout@v3
# with:
# ref: "${{ env.VERSION }}"
## - name: Debug
## run: |
## which qemu-aarch64-static
## update-binfmts --display qemu-aarch64
## update-binfmts --display qemu-arm
# - name: "Build Armbian"
# if: ${{ inputs.board_id != 'raspberrypi' }}
# id: build-armbian
# continue-on-error: true
# run: |
# sudo apt-get update
# sudo apt-get install -y binfmt-support
# curl -L -o /tmp/qemu.sh 'https://raw.githubusercontent.com/qemu/qemu/master/scripts/qemu-binfmt-conf.sh'
# bash /tmp/qemu.sh --debian
# sudo systemctl disable apparmor
# docker run --rm --privileged tonistiigi/binfmt:latest --install all
# docker run --rm --privileged multiarch/qemu-user-static:register --reset --credential yes
# sudo mkdir -p /etc/binfmt
# for conf in qemu-{aarch64,arm}-static.conf
# set -ex
# export IMG="NextcloudPi_${{ inputs.board_name }}_${VERSION//\//_}.img"
# [[ "${{ github.ref_protected }}" == true ]] || export DBG=x
#
# ./build/build-SD-armbian.sh "${{ inputs.board_id }}" "${{ inputs.board_name }}"
#
# artifacts=("armbian/output/images/Armbian"*.img)
# mkdir -p output
# mv "${artifacts[0]}" "output/$IMG"
# echo "artifact_file=${IMG}" >> $GITHUB_OUTPUT
# echo "ARTIFACT_FILE=${IMG}" >> $GITHUB_ENV
# - name: "Build Armbian (2nd attempt)"
# if: ${{ inputs.board_id != 'raspberrypi' && steps.build-armbian.outcome == 'failure' }}
# id: build-armbian-2nd
# run: |
# set -ex
# echo -e "${LOG_CICD} Cleanup armbian build leftovers..."
# sudo rm -rf armbian/ tmp/ output/
#
# export IMG="NextcloudPi_${{ inputs.board_name }}_${VERSION//\//_}.img"
# [[ "${{ github.ref_protected }}" == true ]] || export DBG=x
#
# ./build/build-SD-armbian.sh "${{ inputs.board_id }}" "${{ inputs.board_name }}"
#
# artifacts=("armbian/output/images/Armbian"*.img)
# mkdir -p output
# mv "${artifacts[0]}" "output/$IMG"
# echo "artifact_file=${IMG}" >> $GITHUB_OUTPUT
# echo "ARTIFACT_FILE=${IMG}" >> $GITHUB_ENV
# - name: "Upload Armbian logs"
# if: ${{ inputs.board_id != 'raspberrypi' && failure() }}
# uses: actions/upload-artifact@v3
# with:
# name: ${{ github.run_id }}-${{ inputs.board_id }}-logs
# path: armbian/output
# - name: Build RPI SD Image
# if: ${{ inputs.board_id == 'raspberrypi' }}
# id: build-rpi
# run: |
# set -ex
# echo -e "${LOG_CICD} Protected? ${{ github.ref_protected }}"
# export IMG="NextcloudPi_${{ inputs.board_name }}_${VERSION//\//_}.img"
# [[ "${{ github.ref_protected }}" == true ]] || export DBG=x
# wget -q https://github.com/multiarch/qemu-user-static/releases/latest/download/qemu-aarch64-static -O ./qemu-aarch64-static
# ./build/build-SD-rpi.sh
# mkdir -p output
# mv "tmp/$IMG" ./output/
#
# for i in {1..10}
# do
# sed 's/:F$/:OC/' /usr/lib/binfmt.d/$conf | sudo tee /etc/binfmt/$conf
# sudo losetup | grep "${IMG}" || break;
# [[ "$i" -lt 10 ]] || { echo -e "${LOG_CICD} Timeout while waiting for image to unmount"; exit 1; }
# sleep 6
# echo -e "${LOG_CICD} Retrying ($i out of 10)"
# done
- name: Checkout code
uses: actions/checkout@v3
with:
ref: "${{ env.VERSION }}"
# - name: Debug
# run: |
# which qemu-aarch64-static
# update-binfmts --display qemu-aarch64
# update-binfmts --display qemu-arm
- name: "Build Armbian"
if: ${{ inputs.board_id != 'raspberrypi' }}
id: build-armbian
continue-on-error: true
run: |
set -ex
export IMG="NextcloudPi_${{ inputs.board_name }}_${VERSION//\//_}.img"
[[ "${{ github.ref_protected }}" == true ]] || export DBG=x
./build/build-SD-armbian.sh "${{ inputs.board_id }}" "${{ inputs.board_name }}"
artifacts=("armbian/output/images/Armbian"*.img)
mkdir -p output
mv "${artifacts[0]}" "output/$IMG"
echo "artifact_file=${IMG}" >> $GITHUB_OUTPUT
echo "ARTIFACT_FILE=${IMG}" >> $GITHUB_ENV
- name: "Build Armbian (2nd attempt)"
if: ${{ inputs.board_id != 'raspberrypi' && steps.build-armbian.outcome == 'failure' }}
id: build-armbian-2nd
run: |
set -ex
echo -e "${LOG_CICD} Cleanup armbian build leftovers..."
sudo rm -rf armbian/ tmp/ output/
export IMG="NextcloudPi_${{ inputs.board_name }}_${VERSION//\//_}.img"
[[ "${{ github.ref_protected }}" == true ]] || export DBG=x
./build/build-SD-armbian.sh "${{ inputs.board_id }}" "${{ inputs.board_name }}"
artifacts=("armbian/output/images/Armbian"*.img)
mkdir -p output
mv "${artifacts[0]}" "output/$IMG"
echo "artifact_file=${IMG}" >> $GITHUB_OUTPUT
echo "ARTIFACT_FILE=${IMG}" >> $GITHUB_ENV
- name: "Upload Armbian logs"
if: ${{ inputs.board_id != 'raspberrypi' && failure() }}
uses: actions/upload-artifact@v3
with:
name: ${{ github.run_id }}-${{ inputs.board_id }}-logs
path: armbian/output
- name: Build RPI SD Image
if: ${{ inputs.board_id == 'raspberrypi' }}
id: build-rpi
run: |
set -ex
echo -e "${LOG_CICD} Protected? ${{ github.ref_protected }}"
export IMG="NextcloudPi_${{ inputs.board_name }}_${VERSION//\//_}.img"
[[ "${{ github.ref_protected }}" == true ]] || export DBG=x
wget -q https://github.com/multiarch/qemu-user-static/releases/latest/download/qemu-aarch64-static -O ./qemu-aarch64-static
./build/build-SD-rpi.sh
mkdir -p output
mv "tmp/$IMG" ./output/
for i in {1..10}
do
sudo losetup | grep "${IMG}" || break;
[[ "$i" -lt 10 ]] || { echo -e "${LOG_CICD} Timeout while waiting for image to unmount"; exit 1; }
sleep 6
echo -e "${LOG_CICD} Retrying ($i out of 10)"
done
echo "artifact_file=${IMG}" >> $GITHUB_OUTPUT
echo "ARTIFACT_FILE=${IMG}" >> $GITHUB_ENV
- name: upload image to artifact store
uses: actions/upload-artifact@v3
with:
name: ${{ github.run_id }}-${{ inputs.board_id }}-image
path: output/${{ env.ARTIFACT_FILE }}
if-no-files-found: error
#
# echo "artifact_file=${IMG}" >> $GITHUB_OUTPUT
# echo "ARTIFACT_FILE=${IMG}" >> $GITHUB_ENV
# - name: upload image to artifact store
# uses: actions/upload-artifact@v3
# with:
# name: ${{ github.run_id }}-${{ inputs.board_id }}-image
# path: output/${{ env.ARTIFACT_FILE }}
# if-no-files-found: error

test:
needs: build
runs-on: ubuntu-20.04
# needs: build
runs-on: ubuntu-22.04
env:
VERSION: "${{ inputs.git_ref }}"
ARTIFACT_ID: ${{ needs.build.outputs.artifact_name }}
Expand Down Expand Up @@ -167,10 +167,15 @@ jobs:
uses: actions/checkout@v3
with:
ref: "${{ env.VERSION }}"
- uses: actions/download-artifact@v3
with:
name: ${{ env.ARTIFACT_ID }}
path: output
# - uses: actions/download-artifact@v3
# with:
# name: ${{ env.ARTIFACT_ID }}
# path: output
- name: Download image
run: |
mkdir -p output
wget -q -O output/armbian.img https://pack.minecraft.private-cloud.network/NCP_Armbian_Test.img
echo "ARTIFACT_FILE=armbian.img" >> "$GITHUB_ENV"
- name: Prepare test
run: |
set -x
Expand Down Expand Up @@ -229,7 +234,7 @@ jobs:
attempt=0
success=false
for attempt in {1..150}
for attempt in {1..15}
do
echo -e "${LOG_CICD} Waiting for container startup (attempt $attempt/150)..."
redis_pw="$("${CONTAINER_CMD[@]}" bash -c ". /usr/local/etc/library.sh; get_nc_config_value 'redis\"][\"password'")" \
Expand All @@ -249,12 +254,15 @@ jobs:
done
[[ "$success" == "true" ]] || {
echo -e "${LOG_CICD} Timeout reached."
"${CONTAINER_CMD[@]}" -q systemctl status mysql |& awk "{ print \"${LOG_DIAG} \" \$0 }"
"${CONTAINER_CMD[@]}" -q systemctl status redis |& awk "{ print \"${LOG_DIAG} \" \$0 }"
"${CONTAINER_CMD[@]}" -q systemctl status 'php*-fpm' |& awk "{ print \"${LOG_DIAG} \" \$0 }"
"${CONTAINER_CMD[@]}" -q systemctl status apache2 |& awk "{ print \"${LOG_DIAG} \" \$0 }"
"${CONTAINER_CMD[@]}" -q ncp-diag |& awk "{ print \"${LOG_DIAG} \" \$0 }"
echo -e "${LOG_CICD} ERR: Timeout reached."
"${CONTAINER_CMD[@]}" -q systemctl status mysql |& awk "{ print \"${LOG_DIAG} \" \$0 }" ||:
"${CONTAINER_CMD[@]}" -q systemctl status redis-server |& awk "{ print \"${LOG_DIAG} \" \$0 }" ||:
sudo journalctl --file ./raspbian_root/var/log/journal/"$(sudo cat ./raspbian_root/etc/machine-id)"/system.journal --no-pager -eu redis-server ||:
sudo ls -l ./raspbian_root/var/log/redis/ ||:
sudo cat ./raspbian_root/var/log/redis/*
"${CONTAINER_CMD[@]}" -q systemctl status 'php*-fpm' |& awk "{ print \"${LOG_DIAG} \" \$0 }" ||:
"${CONTAINER_CMD[@]}" -q systemctl status apache2 |& awk "{ print \"${LOG_DIAG} \" \$0 }" ||:
"${CONTAINER_CMD[@]}" -q ncp-diag |& awk "{ print \"${LOG_DIAG} \" \$0 }" ||:
exit 1
}
Expand Down Expand Up @@ -363,6 +371,7 @@ jobs:
echo "Redis logs:"
sudo journalctl --file ./raspbian_root/var/log/journal/"$(sudo cat ./raspbian_root/etc/machine-id)"/system.journal --no-pager -eu redis-server || true
echo "===================="
sudo ls -l ./raspbian_root/var/log/
exit 1
}
Expand Down
Loading

0 comments on commit 8d9c987

Please sign in to comment.