Skip to content

Commit 98be022

Browse files
committed
build-docker.yml: Add integration tests for docker images and only push
on success - build/docker/, build/build-docker.sh: Migrate to multistage docker images - tests/: Fix tests for GH workflow scenarios
2 parents bc13877 + 0f05c01 commit 98be022

File tree

17 files changed

+824
-246
lines changed

17 files changed

+824
-246
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Create Test VM
2+
description: Create NCP instance for testing in the Hetzner cloud
3+
inputs:
4+
version:
5+
description: version (git rev / tag / branch) to install
6+
required: true
7+
uid:
8+
description: A unique ID for labeling/naming generated resources
9+
required: true
10+
hcloud_token:
11+
description: A auth token for Hetzner cloud
12+
required: true
13+
server_type:
14+
description: Server type to use for hetzner servers
15+
required: true
16+
default: "cx11"
17+
18+
outputs:
19+
server_address:
20+
description: Adress of the test instance
21+
snapshot_id:
22+
description: ID of the generated postinstall snapshot
23+
test_server_id:
24+
description: ID of the created test server
25+
runs:
26+
using: docker
27+
image: docker://thecalcaholic/ncp-test-automation
28+
29+
env:
30+
HCLOUD_TOKEN: ${{ inputs.hcloud_token }}
31+
UID: ${{ inputs.uid }}
32+
SERVER_TYPE: ${{ inputs.server_type }}
33+
args:
34+
- /ncp-test-automation/bin/actions/create-test-instance.sh
35+
- ${{ inputs.version }}

.github/workflows/build-docker.yml

+147
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
# https://www.docker.com/blog/docker-v2-github-action-is-now-ga/
2+
# https://www.docker.com/blog/multi-arch-build-and-images-the-simple-way/
3+
# https://docs.github.com/en/actions/guides/publishing-docker-images
4+
5+
name: 'Docker Integration Tests and Release'
6+
7+
on:
8+
push:
9+
branches:
10+
- "*"
11+
tags:
12+
- 'v*'
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
strategy:
18+
matrix:
19+
arch:
20+
- x86
21+
- armhf
22+
- arm64
23+
fail-fast: false
24+
steps:
25+
- name: Setup Docker Buildx
26+
uses: docker/setup-buildx-action@v1
27+
28+
- name: Set up QEMU
29+
uses: docker/setup-qemu-action@v1
30+
31+
- name: Checkout code
32+
uses: actions/checkout@v3
33+
34+
- name: Login to docker
35+
run: |
36+
echo "${{ secrets.DOCKER_PASSWORD_INTERNAL }}" | docker login -u "${{ secrets.DOCKER_LOGIN_INTERNAL }}" --password-stdin
37+
38+
- name: Build images
39+
id: build-container
40+
run: |
41+
./build/build-docker.sh "${{ matrix.arch }}"
42+
docker tag "ownyourbits/nextcloudpi-${{ matrix.arch }}:latest" "thecalcaholic/ncp-internal-${{ matrix.arch }}:${{ github.run_id }}"
43+
docker push "thecalcaholic/ncp-internal-${{ matrix.arch }}:${{ github.run_id }}"
44+
45+
test:
46+
needs:
47+
- build
48+
runs-on: ubuntu-latest
49+
50+
strategy:
51+
matrix:
52+
arch:
53+
- armhf
54+
- x86
55+
- arm64
56+
fail-fast: false
57+
steps:
58+
- name: Set up QEMU
59+
uses: docker/setup-qemu-action@v1
60+
61+
- name: Login to docker
62+
run: |
63+
echo "${{ secrets.DOCKER_PASSWORD_INTERNAL }}" | docker login -u "${{ secrets.DOCKER_LOGIN_INTERNAL }}" --password-stdin
64+
- name: Start ncp container
65+
run: |
66+
docker run -d --rm -p 8443:443 -p 4443:4443 --name nextcloudpi thecalcaholic/ncp-internal-${{ matrix.arch }}:${{ github.run_id }}
67+
68+
- name: Checkout code
69+
uses: actions/checkout@v3
70+
71+
- name: Setup Firefox
72+
uses: browser-actions/setup-firefox@latest
73+
- name: Setup GeckoDriver
74+
uses: browser-actions/setup-geckodriver@latest
75+
- name: Setup Selenium
76+
run: pip install selenium
77+
78+
- name: Integration Tests
79+
working-directory: ./tests
80+
run: |
81+
python activation_tests.py --no-gui localhost 8443 4443 || {
82+
tail -n 20 geckodriver.log >&2 || true
83+
echo "======================="
84+
echo "Activation test failed!"
85+
echo "Container logs:"
86+
echo "==========================================="
87+
docker logs nextcloudpi
88+
echo "Last lines of ncp.log:"
89+
echo "==========================================="
90+
docker exec nextcloudpi tail /var/log/ncp.log;
91+
exit 1
92+
}
93+
echo "Activation test successful"
94+
python system_tests.py --no-ping --non-interactive || {
95+
echo "System test failed!"
96+
exit 1
97+
}
98+
echo "System test successful"
99+
python nextcloud_tests.py --no-gui localhost 8443 4443 || {
100+
tail -n 20 geckodriver.log >&2 || true
101+
echo "======================="
102+
echo "Nextcloud test failed!"
103+
echo "Container logs:"
104+
echo "==========================================="
105+
docker logs nextcloudpi
106+
echo "Last lines of ncp.log:"
107+
echo "==========================================="
108+
docker exec nextcloudpi tail /var/log/ncp.log;
109+
exit 1
110+
}
111+
echo "Nextcloud test successful"
112+
113+
release:
114+
needs:
115+
- test
116+
if: ${{ github.event_name == 'push' && github.github.ref_type == 'tag' }}
117+
runs-on: ubuntu-latest
118+
steps:
119+
- name: Login to DockerHub
120+
uses: docker/login-action@v1
121+
with:
122+
username: ${{ secrets.DOCKERHUB_USERNAME }}
123+
password: ${{ secrets.DOCKERHUB_TOKEN }}
124+
125+
- name: Create manifest and push as tag to docker hub
126+
run: |
127+
. ./build/buildlib.sh
128+
129+
for arch in x86 armhf arm64
130+
do
131+
docker pull "thecalcaholic/ncp-internal-${arch}:${{ github.run_id }}"
132+
docker tag "thecalcaholic/ncp-internal-${arch}:${{ github.run_id }}" "ownyourbits/nextcloudpi-${arch}:${version?}"
133+
done
134+
135+
docker manifest create ownyourbits/nextcloudpi:${version?} \
136+
ownyourbits/nextcloudpi-armhf:${version?} \
137+
ownyourbits/nextcloudpi-x86:${version?} \
138+
ownyourbits/nextcloudpi-arm64:${version?}
139+
docker manifest push ownyourbits/nextcloudpi:${version?}
140+
141+
- name: Create manifest and push as latest to docker hub
142+
run: |
143+
docker manifest create ownyourbits/nextcloudpi:latest \
144+
ownyourbits/nextcloudpi-armhf:latest \
145+
ownyourbits/nextcloudpi-x86:latest \
146+
ownyourbits/nextcloudpi-arm64:latest
147+
docker manifest push ownyourbits/nextcloudpi:latest

0 commit comments

Comments
 (0)