From d9c09b66f0f74e58cf1fbb1b48a94e11d007b102 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 4 Jun 2023 13:08:05 +0200 Subject: [PATCH] Use pi-hole/ftl-build:ftl-build-buildx containers Signed-off-by: DL6ER --- .github/Dockerfile | 32 +++++++++++++++++++++++ .github/workflows/build.yml | 52 +++++++++++++++++++------------------ test/run.sh | 4 +++ 3 files changed, 63 insertions(+), 25 deletions(-) create mode 100644 .github/Dockerfile diff --git a/.github/Dockerfile b/.github/Dockerfile new file mode 100644 index 00000000..8c538f79 --- /dev/null +++ b/.github/Dockerfile @@ -0,0 +1,32 @@ +FROM ghcr.io/pi-hole/ftl-build:ftl-build-buildx AS builder + +WORKDIR /app + +COPY . /app + +ARG CI_ARCH="linux/amd64" +ENV CI_ARCH ${CI_ARCH} +ARG GIT_BRANCH="test" +ENV GIT_BRANCH ${GIT_BRANCH} +ARG GIT_TAG="test" +ENV GIT_TAG ${GIT_TAG} + +# Build FTL +# Remove possible old build files +RUN rm -rf cmake && \ +# Build FTL + bash build.sh "-DSTATIC=${STATIC}" && \ +# Run binary architecture tests + bash test/arch_test.sh && \ +# Run full test suite + bash test/run.sh && \ +# Move FTL binary to root directory + cd / &&\ + mv /app/pihole-FTL . && \ +# Create tarball of API docs + tar -C /app/src/api/docs/content/ -czvf /api-docs.tar.gz . + +# Create final image containing only the FTL binary and API docs +FROM scratch AS result +COPY --from=builder /pihole-FTL /pihole-FTL +COPY --from=builder /api-docs.tar.gz /api-docs.tar.gz diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c58c6a9b..245b8503 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -51,7 +51,6 @@ jobs: build: runs-on: ubuntu-latest needs: smoke-tests - container: ghcr.io/pi-hole/ftl-build:v2.0 strategy: fail-fast: false matrix: @@ -61,13 +60,13 @@ jobs: - platform: linux/386 bin_name: pihole-FTL-386 - platform: linux/arm/v6 - bin_name: pi-hole-FTL-armv6 + bin_name: pihole-FTL-armv6 - platform: linux/arm/v7 - bin_name: pi-hole-FTL-armv7 + bin_name: pihole-FTL-armv7 - platform: linux/arm64/v8 - bin_name: pi-hole-FTL-arm64 + bin_name: pihole-FTL-arm64 - platform: linux/riscv64 - bin_name: pi-hole-FTL-riscv64 + bin_name: pihole-FTL-riscv64 env: CI_ARCH: ${{ matrix.platform }} @@ -78,15 +77,15 @@ jobs: - name: Checkout code uses: actions/checkout@v3.5.2 - - - name: "Fix ownership of repository" - run: chown -R root . - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 + uses: docker/setup-buildx-action@v2.5.0 - - name: Build and push - uses: docker/build-push-action@v3 + name: Print directory contents + run: ls -l + - + name: Build and test FTL in ftl-build container (QEMU) + uses: docker/build-push-action@v4.0.0 with: # tags: ghcr.io/pi-hole/ftl-build:v2.0 platforms: ${{ matrix.platform }} @@ -94,36 +93,39 @@ jobs: pull: true # Do not push anything push: false - # Load into daemon for subsequent steps - load: true + context: . + target: result + file: .github/Dockerfile + outputs: | + type=tar,dest=build.tar + build-args: | + "CI_ARCH=${{ matrix.platform }}" + "GIT_BRANCH=${{ needs.smoke-tests.outputs.GIT_BRANCH }}" + "GIT_TAG=${{ needs.smoke-tests.outputs.GIT_TAG }}" - - name: "Build" - run: | - bash build.sh "-DSTATIC=${STATIC}" + name: List files in current directory + run: ls -l - - name: "Binary checks" + name: Extract FTL binary from container run: | - bash test/arch_test.sh - - - name: "Test binaries" - run: | - bash test/run.sh + tar -xf build.tar pihole-FTL - name: "Generate checksum file" run: | mv pihole-FTL "${{ matrix.bin_name }}" sha1sum pihole-FTL-* > ${{ matrix.bin_name }}.sha1 - - name: Store binary artifacts for deployoment + name: Store binary artifacts for later deployoment if: github.event_name != 'pull_request' uses: actions/upload-artifact@v3.1.2 with: name: tmp-storage path: '${{ matrix.bin_name }}*' - - name: Tar documentation files + name: Extract documentation files from container if: github.event_name != 'pull_request' && matrix.platform == 'linux/amd64' - run: tar -C src/api/docs/content/ -czvf api-docs.tar.gz . + run: | + tar -xf build.tar api-docs.tar.gz - name: Upload documentation artifacts for deployoment if: github.event_name != 'pull_request' && matrix.platform == 'linux/amd64' diff --git a/test/run.sh b/test/run.sh index 2574e34d..6f6454ed 100755 --- a/test/run.sh +++ b/test/run.sh @@ -133,5 +133,9 @@ umask "$OLDUMASK" # Remove copied file rm /home/pihole/pihole-FTL +# Stop local powerDNS resolver +killall pdns_server +killall pdns_recursor + # Exit with return code of bats tests exit $RET