- Change test dockerfile base to alpine, too (Alpine all the things!)

- Tweak build-and-test.sh to allow tests to run against more platforms using buildx
- Split GHA out into two seperate files. One for tests on pull requests, another for build and merge on push to `development-v6` (add other branches in later)

Signed-off-by: Adam Warner <me@adamwarner.co.uk>
This commit is contained in:
Adam Warner 2023-07-24 18:03:13 +01:00
parent a317129a41
commit 6b5332be47
No known key found for this signature in database
5 changed files with 42 additions and 22 deletions

View File

@ -5,14 +5,13 @@ on:
push:
branches:
- development-v6
pull_request:
env:
dockerhub: ${{ secrets.DOCKERHUB_NAMESPACE }}/pihole
ghcr: ghcr.io/${{ github.repository_owner }}/pihole
jobs:
build-and-test:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
@ -30,8 +29,6 @@ jobs:
steps:
- name: Checkout Repo
uses: actions/checkout@v3
with:
ref: development-v6
- name: Docker meta (Docker Hub and GitHub Container Registry)
id: meta
@ -46,7 +43,6 @@ jobs:
development-v6
- name: Login to DockerHub and GitHub Container Registry
if: github.event_name != 'pull_request'
uses: ./.github/actions/login-repo
with:
docker_username: ${{ secrets.DOCKERHUB_USER }}
@ -57,7 +53,7 @@ jobs:
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: all
platforms: ${{ matrix.platform}}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
@ -72,7 +68,7 @@ jobs:
CONTAINER=${{ matrix.container }}
labels: ${{ steps.meta.outputs.labels }}
outputs: |
type=image,name=${{ env[matrix.registry] }},push-by-digest=${{ github.event_name != 'pull_request' }},name-canonical=true,push=${{ github.event_name != 'pull_request' }}
type=image,name=${{ env[matrix.registry] }},push-by-digest=true,name-canonical=true,push=true
- name: Export digests
run: |
@ -92,14 +88,13 @@ jobs:
# If we would push immediately above, the individual runners would overwrite each other's images
# https://docs.docker.com/build/ci/github-actions/multi-platform/#distribute-build-across-multiple-runners
merge-and-deploy:
if: github.event_name != 'pull_request'
strategy:
fail-fast: false
matrix:
registry: [dockerhub, ghcr]
runs-on: ubuntu-latest
needs:
- build-and-test
- build
steps:
- name: Checkout Repo
uses: actions/checkout@v3

30
.github/workflows/build-and-test.yml vendored Normal file
View File

@ -0,0 +1,30 @@
name: Build and Test (development-v6)
on:
pull_request:
jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
# Official docker images for docker are only available for amd64 and arm64
# TODO: Look at: https://github.com/docker-library/official-images#architectures-other-than-amd64
# Is testing on all platforms really necessary?
platform: [linux/amd64, linux/arm64/v8]
steps:
- name: Checkout Repo
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: ${{ matrix.platform}}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Run Tests
run: |
echo "Building image to test"
PLATFORM=${{ matrix.platform}} ./build-and-test.sh

View File

@ -8,9 +8,10 @@ fi
GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD | sed "s/\//-/g")
GIT_TAG=$(git describe --tags --exact-match 2> /dev/null || true)
GIT_TAG="${GIT_TAG:-$GIT_BRANCH}"
PLATFORM="${PLATFORM:-linux/amd64}"
# generate and build dockerfile
docker build --tag image_pipenv --file test/Dockerfile test/
docker buildx build --load --platform=${PLATFORM} --tag image_pipenv --file test/Dockerfile test/
docker run --rm \
--volume /var/run/docker.sock:/var/run/docker.sock \
--volume "$(pwd):/$(pwd)" \

View File

@ -1,18 +1,12 @@
FROM python:3.10-slim-bullseye
FROM python:3.10-alpine3.18
# Only works for docker CLIENT (bind mounted socket)
COPY --from=docker:20.10.17 /usr/local/bin/docker /usr/local/bin/
COPY --from=docker:24-cli /usr/local/bin/docker /usr/local/bin/
ARG packages
RUN apt-get update && \
apt-get install -y python3-dev curl gcc make \
libffi-dev libssl-dev ${packages} \
&& rm -rf /var/lib/apt/lists/* \
RUN apk add --no-cache \
curl \
&& pip3 install --no-cache-dir -U pip pipenv
RUN curl -L https://github.com/docker/compose/releases/download/2.10.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose && \
chmod +x /usr/local/bin/docker-compose
COPY ./cmd.sh /usr/local/bin/
COPY Pipfile* /root/
WORKDIR /root

View File

@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/usr/bin/env sh
set -eux
docker build ./src --tag pihole:${GIT_TAG} --no-cache
@ -9,4 +9,4 @@ python -m black ./test/tests/
# TODO: Add junitxml output and have something consume it
# 2 parallel max b/c race condition with docker fixture (I think?)
py.test -vv -n 2 ./test/tests/
py.test -vv -n auto ./test/tests/