nextcloudpi/.github/workflows/build-docker.yml
Tobias Knöppler 3e7fb6a2da
build-docker.yml: Fix debugging artifact ownership
Signed-off-by: Tobias Knöppler <6317548+theCalcaholic@users.noreply.github.com>
2023-01-20 00:46:21 +01:00

504 lines
22 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# https://www.docker.com/blog/docker-v2-github-action-is-now-ga/
# https://www.docker.com/blog/multi-arch-build-and-images-the-simple-way/
# https://docs.github.com/en/actions/guides/publishing-docker-images
name: 'Docker Integration Tests and Release'
on:
workflow_call:
inputs:
git_ref:
required: true
type: string
arch:
required: false
type: string
default: 'x86'
push:
branches:
- master
- devel
pull_request:
branches:
- master
- devel
- release/*
jobs:
build:
if: ${{ github.repository == 'nextcloud/nextcloudpi' }}
runs-on: ubuntu-latest
env:
VERSION: "${{ inputs.git_ref || github.ref }}"
ARCH: "${{ inputs.arch || 'x86' }}"
LOG_DCKR: "\\033[1;34mDCKR::\\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"
steps:
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Checkout code
uses: actions/checkout@v3
with:
ref: "${{ env.VERSION }}"
- name: Login to docker
run: |
echo "${{ secrets.DOCKER_PASSWORD_INTERNAL }}" | docker login -u "${{ secrets.DOCKER_LOGIN_INTERNAL }}" --password-stdin
- name: Build images
id: build-container
run: |
./build/build-docker.sh "${ARCH?}"
docker tag "ownyourbits/nextcloudpi-${ARCH?}:latest" "thecalcaholic/ncp-internal-${ARCH?}:${{ github.run_id }}"
testing_image="ownyourbits/nextcloudpi-${ARCH?}:latest"
[[ "${ARCH?}" == "x86" ]] || testing_image="ownyourbits/ncp-qemu-fix-${ARCH?}:latest"
docker tag "${testing_image}" "thecalcaholic/ncp-internal-${ARCH?}:${{ github.run_id }}-testing"
docker push "thecalcaholic/ncp-internal-${ARCH?}:${{ github.run_id }}"
docker push "thecalcaholic/ncp-internal-${ARCH?}:${{ github.run_id }}-testing"
update-test:
needs: []
#- build
runs-on: ubuntu-latest
env:
VERSION: "${{ inputs.git_ref || github.ref }}"
ARCH: "${{ inputs.arch || 'x86' }}"
LOG_DCKR: "\\033[1;34mDCKR::\\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"
CHECK_OK: "\\033[1;32m✓\\033[0m"
CHECK_FAILED: "\\033[1;31m\\033[0m"
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Login to docker
run: |
echo "${{ secrets.DOCKER_PASSWORD_INTERNAL }}" | docker login -u "${{ secrets.DOCKER_LOGIN_INTERNAL }}" --password-stdin
- name: Start ncp container
run: |
docker volume create ncdata
mkdir -p /home/runner/work/data-exports/ncdata1
mkdir -p /home/runner/work/data-exports/ncdata2
docker run -d --rm -p 8443:443 -p 4443:4443 -v /home/runner/work/data-exports/ncdata1:/data-export -v "ncdata:/data" --name nextcloudpi thecalcaholic/ncp-internal-${ARCH?}:3962168407-testing localhost
#docker run -d --rm -v /home/runner/work/data-exports/ncdata2:/data-export --name nextcloudpinovolume thecalcaholic/ncp-internal-${ARCH?}:3962168407-testing localhost
- name: Checkout code
uses: actions/checkout@v3
with:
ref: "${{ env.VERSION }}"
- name: Setup Firefox
uses: browser-actions/setup-firefox@latest
- name: Setup GeckoDriver
uses: ChlodAlejandro/setup-geckodriver@latest
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Selenium
run: pip install selenium
- name: Wait for container startup
run: |
set -e
docker logs nextcloudpi |& awk "{ print \"${LOG_DCKR} \" \$0 }"
echo -e "${LOG_DCKR} =========="
docker logs -f nextcloudpi |& awk "{ print \"${LOG_DCKR} \" \$0 }" &
attempt=0
stage=0
success=false
for attempt in {1..15}
do
echo -e "${LOG_CICD} Waiting for container startup (attempt $attempt/30)..."
redis_pw="$(docker exec nextcloudpi bash -c ". /usr/local/etc/library.sh; get_nc_config_value 'redis\"][\"password'")"
redis_socket="$(docker exec nextcloudpi bash -c ". /usr/local/etc/library.sh; get_nc_config_value 'redis\"][\"host'")"
if [[ "$stage" == "0" ]] && docker logs nextcloudpi 2> /dev/null | grep '^Init done' > /dev/null
then
stage=1
elif [[ "$(docker exec nextcloudpi ncc maintenance:mode)" =~ .*disabled.* ]] \
&& docker exec nextcloudpi ncc status \
&& docker exec nextcloudpi redis-cli -s "$redis_socket" -a "$redis_pw" set redisready yes \
&& docker exec nextcloudpi redis-cli -s "$redis_socket" -a "$redis_pw" get redisready \
&& curl -k https://localhost:8443/activate/
then
echo -e "${LOG_CICD} Startup successful"
success=true
break
fi
sleep 5
done
echo -e "${LOG_CICD} Timeout reached."
echo -e "${LOG_CICD} Manually starting apache..."
docker exec nextcloudpi apache2ctl -k stop
sleep 60
while true
do
docker exec nextcloudpi apache2ctl -e debug -X -DFOREGROUND || continue
break
done
docker exec nextcloudpi bash -c 'cp -ra /data/* /data-export/'
docker exec nextcloudpi bash -c 'cp -ra /data/.[!.]* /data-export' || true
#docker exec nextcloudpinovolume bash -c 'cp -ra /data/* /data-export/'
#docker exec nextcloudpinovolume bash -c 'cp -ra /data/.[!.]* /data-export' || true
mkdir data-exports
sudo tar caf ./data-exports/ncdata_exports.tar /home/runner/work/data-exports
sudo chown runner: ./data-exports/ncdata_exports.tar
[[ "$success" == "true" ]] || exit 1
- name: Upload debugging artifacts
if: ${{ always() }}
uses: actions/upload-artifact@v3
with:
name: ${{ github.run_id }}-docker-${{ env.ARCH }}-volume-troubleshooting
path: data-exports
- name: Integration Tests
working-directory: ./tests
run: |
docker logs nextcloudpi |& awk "{ print \"${LOG_DCKR} \" \$0 }"
echo -e "${LOG_DCKR} =========="
docker logs -f nextcloudpi |& awk "{ print \"${LOG_DCKR} \" \$0 }" &
docker exec nextcloudpi bash -c 'tail -f /var/log/ncp.log' |& awk "{ print \"${LOG_NCP} \" \$0 }" &
cmd=(python activation_tests.py --no-gui localhost 8443 4443)
[[ "${ARCH?}" == "x86" ]] || { sleep 60; cmd+=(--timeout 300); }
success=false
for attempt in {1..10}
do
echo -e "${LOG_CICD} == Activation Tests (attempt $attempt/10) =="
"${cmd[@]}" |& awk "{ print \"${LOG_TEST} \" \$0 }"
[[ ${PIPESTATUS[0]} -eq 0 ]] || {
tail -n 20 geckodriver.log >&2 |& awk "{ print \"${LOG_DIAG} \" \$0 }" || true
echo -e "${LOG_CICD} Activation test (attempt $attempt/10) failed!"
docker exec nextcloudpi bash /usr/local/bin/ncp-diag |& awk "{ print \"${LOG_DIAG} \" \$0 }" || true
sleep 12
continue
}
success=true
break
done
[[ "$success" == "true" ]] || {
echo -e "${LOG_CICD} Activation test failed in all attempts!"
exit 1
}
echo -e "${LOG_CICD} Activation test successful"
- name: Start new container
run: |
docker stop nextcloudpi
docker run -d -v " /home/runner/work/data-exports/ncdata1:/data" --rm -p 8443:443 -p 4443:4443 -e NOBACKUP=true --name nextcloudpi thecalcaholic/ncp-internal-${ARCH?}:3955102274-testing localhost
- name: Wait for container startup
run: |
set -e
docker logs nextcloudpi |& awk "{ print \"${LOG_DCKR} \" \$0 }"
echo -e "${LOG_DCKR} =========="
docker logs -f nextcloudpi |& awk "{ print \"${LOG_DCKR} \" \$0 }" &
attempt=0
stage=0
for attempt in {1..200}
do
echo -e "${LOG_CICD} Waiting for container startup (attempt $attempt/30)..."
redis_pw="$(docker exec nextcloudpi bash -c ". /usr/local/etc/library.sh; get_nc_config_value 'redis\"][\"password'")"
redis_socket="$(docker exec nextcloudpi bash -c ". /usr/local/etc/library.sh; get_nc_config_value 'redis\"][\"host'")"
if [[ "$stage" == "0" ]] && docker logs nextcloudpi 2> /dev/null | grep '^Init done' > /dev/null
then
stage=1
elif [[ "$(docker exec nextcloudpi ncc maintenance:mode)" =~ .*disabled.* ]] \
&& docker exec nextcloudpi ncc status \
&& docker exec nextcloudpi redis-cli -s "$redis_socket" -a "$redis_pw" set redisready yes \
&& docker exec nextcloudpi redis-cli -s "$redis_socket" -a "$redis_pw" get redisready \
&& curl -k https://localhost:8443/activate/
then
echo -e "${LOG_CICD} Startup successful"
break
elif [[ "$attempt" -ge 30 ]]
then
echo -e "${LOG_CICD} Timeout reached."
exit 1
fi
attempt=$((attempt + 1))
sleep 5
done
echo "Wait one more minute..."
sleep 60
- name: Update Nextcloud
run: |
set -e
docker logs nextcloudpi |& awk "{ print \"${LOG_DCKR} \" \$0 }"
echo -e "${LOG_DCKR} =========="
docker logs -f nextcloudpi |& awk "{ print \"${LOG_DCKR} \" \$0 }" &
current_nc_version="$(docker exec nextcloudpi ncc status | grep "version:" | awk '{ print $3 }')"
latest_nc_version="$(docker exec nextcloudpi cat /usr/local/etc/ncp.cfg | jq -r '.nextcloud_version')"
if [[ "$current_nc_version" == "$latest_nc_version".* ]]
then
echo -e "${LOG_CICD} Nextcloud is up to date - skipping NC update test."
else
docker exec nextcloudpi bash -c "DBG=x ncp-update-nc ${latest_nc_version?}" |& awk "{ print \"${LOG_DCKR} \" \$0 }"
[[ ${PIPESTATUS[0]} -eq 0 ]] || {
echo -e "${LOG_CICD} Nextcloud Update failed"
echo -e "${LOG_CICD} Creating error report..."
docker exec nextcloudpi bash /usr/local/bin/ncp-report > error-report.txt
docker exec nextcloudpi bash /usr/local/bin/ncp-diag |& awk "{ print \"${LOG_DIAG} \" \$0 }"
exit 1
}
fi
- name: Wait for update completion
run: |
set -e
docker logs nextcloudpi |& awk "{ print \"${LOG_DCKR} \" \$0 }"
echo -e "${LOG_DCKR} =========="
docker logs -f nextcloudpi |& awk "{ print \"${LOG_DCKR} \" \$0 }" &
attempt=0
for attempt in {1..30}
do
echo -e "${LOG_CICD} Waiting for update completion (attempt $attempt/30)..."
redis_pw="$(docker exec nextcloudpi bash -c ". /usr/local/etc/library.sh; get_nc_config_value 'redis\"][\"password'")"
redis_socket="$(docker exec nextcloudpi bash -c ". /usr/local/etc/library.sh; get_nc_config_value 'redis\"][\"host'")"
if [[ "$(docker exec nextcloudpi ncc maintenance:mode)" =~ .*disabled.* ]] \
&& docker exec nextcloudpi ncc status \
&& docker exec nextcloudpi redis-cli -s "$redis_socket" -a "$redis_pw" set redisready yes \
&& docker exec nextcloudpi redis-cli -s "$redis_socket" -a "$redis_pw" get redisready
then
echo -e "${LOG_CICD} Startup successful"
break
elif [[ "$attempt" -ge 30 ]]
then
echo -e "${LOG_CICD} Timeout reached."
exit 1
fi
attempt=$((attempt + 1))
sleep 5
done
- name: Integration Tests
working-directory: ./tests
run: |
docker logs nextcloudpi |& awk "{ print \"${LOG_DCKR} \" \$0 }"
echo -e "${LOG_DCKR} =========="
docker logs -f nextcloudpi |& awk "{ print \"${LOG_DCKR} \" \$0 }" &
docker exec nextcloudpi bash -c 'tail -f /var/log/ncp.log' |& awk "{ print \"${LOG_NCP} \" \$0 }" &
[[ "${ARCH?}" == "x86" ]] || sleep 240
sleep 20
success=false
for attempt in {1..5}
do
echo -e "${LOG_CICD} == System Tests (attempt $attempt/5) =="
python system_tests.py --no-ping --non-interactive |& awk "{ print \"${LOG_TEST} \" \$0 }"
[[ ${PIPESTATUS[0]} -eq 0 ]] || {
echo -e "${LOG_CICD} System test (attempt $attempt) failed!"
sleep 12
continue
}
success=true
break
done
[[ "$success" == "true" ]] || {
echo -e "${LOG_CICD} System test failed in all attempts!"
echo -e "${LOG_CICD} Creating error report..."
docker exec nextcloudpi bash /usr/local/bin/ncp-report > error-report.txt
exit 1
}
echo -e "${LOG_CICD} System test successful"
success=false
for attempt in {1..3}
do
echo -e "${LOG_CICD} == Nextcloud Tests (attempt $attempt/5) =="
python nextcloud_tests.py --no-gui localhost 8443 4443 |& awk "{ print \"${LOG_TEST} \" \$0 }"
[[ ${PIPESTATUS[0]} -eq 0 ]] || {
tail -n 20 geckodriver.log |& awk "{ print \"${LOG_DIAG} \" \$0 }" || true
echo -e "${LOG_CICD} Nextcloud test (attempt $attempt/3) failed!"
sleep 12
continue
}
success=true
break
done
[[ "$success" == "true" ]] || {
echo -e "${LOG_CICD} Nextcloud test failed in all attempts!"
echo -e "${LOG_CICD} Creating error report..."
docker exec nextcloudpi bash /usr/local/bin/ncp-report > error-report.txt
echo -e "${LOG_CICD} done."
exit 1
}
echo -e "${LOG_CICD} Nextcloud test successful"
docker exec nextcloudpi bash /usr/local/bin/ncp-diag |& awk "{ print \"${LOG_DIAG} \" \$0 }"
- name: "Upload error report"
if: ${{ failure() }}
uses: actions/upload-artifact@v3
with:
name: ${{ github.run_id }}-docker-${{ env.ARCH }}-update-test-error-report
path: tests/error-report.txt
test:
needs:
- build
runs-on: ubuntu-latest
env:
VERSION: "${{ inputs.git_ref || github.ref }}"
ARCH: "${{ inputs.arch || 'x86' }}"
LOG_DCKR: "\\033[1;34mDCKR::\\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"
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Login to docker
run: |
echo "${{ secrets.DOCKER_PASSWORD_INTERNAL }}" | docker login -u "${{ secrets.DOCKER_LOGIN_INTERNAL }}" --password-stdin
- name: Start ncp container
run: |
docker run -d --rm -p 8443:443 -p 4443:4443 --name nextcloudpi thecalcaholic/ncp-internal-${ARCH?}:${{ github.run_id }}-testing localhost
- name: Checkout code
uses: actions/checkout@v3
with:
ref: "${{ env.VERSION }}"
- name: Setup Firefox
uses: browser-actions/setup-firefox@latest
- name: Setup GeckoDriver
uses: ChlodAlejandro/setup-geckodriver@latest
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Selenium
run: pip install selenium
- name: Wait for container startup
run: |
set -e
docker logs nextcloudpi |& awk "{ print \"${LOG_DCKR} \" \$0 }"
echo -e "${LOG_DCKR} =========="
docker logs -f nextcloudpi |& awk "{ print \"${LOG_DCKR} \" \$0 }" &
attempt=0
stage=0
for attempt in {1..30}
do
echo -e "${LOG_CICD} Waiting for container startup (attempt $attempt/30)..."
redis_pw="$(docker exec nextcloudpi bash -c ". /usr/local/etc/library.sh; get_nc_config_value 'redis\"][\"password'")"
redis_socket="$(docker exec nextcloudpi bash -c ". /usr/local/etc/library.sh; get_nc_config_value 'redis\"][\"host'")"
if [[ "$stage" == "0" ]] && docker logs nextcloudpi 2> /dev/null | grep '^Init done' > /dev/null
then
stage=1
elif [[ "$(docker exec nextcloudpi ncc maintenance:mode)" =~ .*disabled.* ]] \
&& docker exec nextcloudpi ncc status \
&& docker exec nextcloudpi redis-cli -s "$redis_socket" -a "$redis_pw" set redisready yes \
&& docker exec nextcloudpi redis-cli -s "$redis_socket" -a "$redis_pw" get redisready \
&& curl -k https://localhost:8443/activate/
then
echo -e "${LOG_CICD} Startup successful"
break
elif [[ "$attempt" -ge 30 ]]
then
echo -e "${LOG_CICD} Timeout reached."
exit 1
fi
attempt=$((attempt + 1))
sleep 5
done
- name: Integration Tests
working-directory: ./tests
run: |
docker logs nextcloudpi |& awk "{ print \"${LOG_DCKR} \" \$0 }"
echo -e "${LOG_DCKR} =========="
docker logs -f nextcloudpi |& awk "{ print \"${LOG_DCKR} \" \$0 }" &
docker exec nextcloudpi bash -c 'tail -f /var/log/ncp.log' |& awk "{ print \"${LOG_NCP} \" \$0 }" &
cmd=(python activation_tests.py --no-gui localhost 8443 4443)
[[ "${ARCH?}" == "x86" ]] || { sleep 60; cmd+=(--timeout 300); }
success=false
for attempt in {1..10}
do
echo -e "${LOG_CICD} == Activation Tests (attempt $attempt/10) =="
"${cmd[@]}" |& awk "{ print \"${LOG_TEST} \" \$0 }"
[[ ${PIPESTATUS[0]} -eq 0 ]] || {
tail -n 20 geckodriver.log >&2 |& awk "{ print \"${LOG_DIAG} \" \$0 }" || true
echo -e "${LOG_CICD} Activation test (attempt $attempt/10) failed!"
docker exec nextcloudpi bash /usr/local/bin/ncp-diag |& awk "{ print \"${LOG_DIAG} \" \$0 }" || true
sleep 12
continue
}
success=true
break
done
[[ "$success" == "true" ]] || {
echo -e "${LOG_CICD} Activation test failed in all attempts!"
exit 1
}
echo -e "${LOG_CICD} Activation test successful"
success=false
for attempt in {1..5}
do
echo -e "${LOG_CICD} == System Tests (attempt $attempt/5) =="
python system_tests.py --no-ping --non-interactive |& awk "{ print \"${LOG_TEST} \" \$0 }"
[[ ${PIPESTATUS[0]} -eq 0 ]] || {
echo -e "${LOG_CICD} System test (attempt $attempt) failed!"
sleep 12
continue
}
success=true
break
done
[[ "$success" == "true" ]] || {
echo -e "${LOG_CICD} System test failed in all attempts!"
exit 1
}
echo -e "${LOG_CICD} System test successful"
success=false
for attempt in {1..5}
do
echo -e "${LOG_CICD} == Nextcloud Tests (attempt $attempt/5) =="
python nextcloud_tests.py --no-gui localhost 8443 4443 |& awk "{ print \"${LOG_TEST} \" \$0 }"
[[ ${PIPESTATUS[0]} -eq 0 ]] || {
tail -n 20 geckodriver.log >&2 |& awk "{ print \"${LOG_DIAG} \" \$0 }" || true
echo -e "${LOG_CICD} Nextcloud test (attempt $attempt/3) failed!"
sleep 12
continue
}
success=true
break
done
[[ "$success" == "true" ]] || {
echo -e "${LOG_CICD} Nextcloud test failed in all attempts!"
echo -e "${LOG_CICD} Creating error report..."
docker exec nextcloudpi bash /usr/local/bin/ncp-report > error-report.txt
echo -e "${LOG_CICD} done."
exit 1
}
echo -e "${LOG_CICD} Nextcloud test successful"
docker exec nextcloudpi bash /usr/local/bin/ncp-diag |& awk "{ print \"${LOG_DIAG} \" \$0 }" || true
- name: "Upload error report"
if: ${{ failure() }}
uses: actions/upload-artifact@v3
with:
name: ${{ github.run_id }}-docker-${{ env.ARCH }}-install-test-error-report
path: tests/error-report.txt