Skip to content

Commit

Permalink
testing
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Warner <me@adamwarner.co.uk>
  • Loading branch information
PromoFaux committed Jul 23, 2023
1 parent 3b5cf34 commit 94d68b2
Show file tree
Hide file tree
Showing 7 changed files with 201 additions and 551 deletions.
242 changes: 130 additions & 112 deletions .github/workflows/test-and-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,133 +12,151 @@ env:
ghcr: ghcr.io/${{ github.repository_owner }}/pihole

jobs:
build-and-test:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
registry: [dockerhub, ghcr]
platform: [linux/amd64, linux/386, linux/arm/v6, linux/arm/v7, linux/arm64/v8]
container: [3.18]
include:
- registry: dockerhub
platform: linux/riscv64
container: edge
- registry: ghcr
platform: linux/riscv64
container: edge
platform: [linux/amd64, linux/386, linux/arm/v6, linux/arm/v7, linux/arm64/v8, linux/riscv64]
steps:
- name: Checkout Repo
uses: actions/checkout@v3
with:
ref: development-v6
- 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
# build:
# if: github.event_name != 'pull_request'
# runs-on: ubuntu-latest
# strategy:
# fail-fast: false
# matrix:
# registry: [dockerhub, ghcr]
# platform: [linux/amd64, linux/386, linux/arm/v6, linux/arm/v7, linux/arm64/v8]
# container: [3.18]
# include:
# - registry: dockerhub
# platform: linux/riscv64
# container: edge
# - registry: ghcr
# platform: linux/riscv64
# container: edge
# steps:
# - name: Checkout Repo
# uses: actions/checkout@v3

- name: Docker meta (Docker Hub and GitHub Container Registry)
id: meta
uses: docker/metadata-action@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
images: |
${{ env[matrix.registry] }}
flavor: |
latest=false
tags: |
development-v6
# - name: Docker meta (Docker Hub and GitHub Container Registry)
# id: meta
# uses: docker/metadata-action@v4
# with:
# github-token: ${{ secrets.GITHUB_TOKEN }}
# images: |
# ${{ env[matrix.registry] }}
# flavor: |
# latest=false
# tags: |
# 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 }}
docker_password: ${{ secrets.DOCKERHUB_PASS }}
ghcr_username: ${{ github.repository_owner }}
ghcr_password: ${{ secrets.GITHUB_TOKEN }}
# - 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 }}
# docker_password: ${{ secrets.DOCKERHUB_PASS }}
# ghcr_username: ${{ github.repository_owner }}
# ghcr_password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: all
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
# - 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: Build container and push by digest (${{ matrix.registry }})
id: build
uses: docker/build-push-action@v4
with:
context: ./src/
platforms: ${{ matrix.platform }}
build-args: |
PIHOLE_DOCKER_TAG=${{ steps.meta.outputs.version }}
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' }}
# - name: Build container and push by digest (${{ matrix.registry }})
# id: build
# uses: docker/build-push-action@v4
# with:
# context: ./src/
# platforms: ${{ matrix.platform }}
# build-args: |
# PIHOLE_DOCKER_TAG=${{ steps.meta.outputs.version }}
# 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' }}

- name: Export digests
run: |
mkdir -p /tmp/digests/${{ matrix.registry }}
digest_docker="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${{ matrix.registry }}/${digest_docker#sha256:}"
# - name: Export digests
# run: |
# mkdir -p /tmp/digests/${{ matrix.registry }}
# digest_docker="${{ steps.build.outputs.digest }}"
# touch "/tmp/digests/${{ matrix.registry }}/${digest_docker#sha256:}"

- name: Upload digest
uses: actions/upload-artifact@v3
with:
name: digests
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1
# - name: Upload digest
# uses: actions/upload-artifact@v3
# with:
# name: digests
# path: /tmp/digests/*
# if-no-files-found: error
# retention-days: 1

# Merge all the digests into a single file
# 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
steps:
- name: Checkout Repo
uses: actions/checkout@v3
# # Merge all the digests into a single file
# # 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
# steps:
# - name: Checkout Repo
# uses: actions/checkout@v3

- name: Download digests
uses: actions/download-artifact@v3
with:
name: digests
path: /tmp/digests
# - name: Download digests
# uses: actions/download-artifact@v3
# with:
# name: digests
# path: /tmp/digests

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v2

- name: Login to DockerHub and GitHub Container Registry
uses: ./.github/actions/login-repo
with:
docker_username: ${{ secrets.DOCKERHUB_USER }}
docker_password: ${{ secrets.DOCKERHUB_PASS }}
ghcr_username: ${{ github.repository_owner }}
ghcr_password: ${{ secrets.GITHUB_TOKEN }}
# - name: Login to DockerHub and GitHub Container Registry
# uses: ./.github/actions/login-repo
# with:
# docker_username: ${{ secrets.DOCKERHUB_USER }}
# docker_password: ${{ secrets.DOCKERHUB_PASS }}
# ghcr_username: ${{ github.repository_owner }}
# ghcr_password: ${{ secrets.GITHUB_TOKEN }}

- name: Docker meta (Docker Hub and GitHub Container Registry)
id: meta
uses: docker/metadata-action@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
images: |
${{ env[matrix.registry] }}
flavor: |
latest=false
tags: |
development-v6
# - name: Docker meta (Docker Hub and GitHub Container Registry)
# id: meta
# uses: docker/metadata-action@v4
# with:
# github-token: ${{ secrets.GITHUB_TOKEN }}
# images: |
# ${{ env[matrix.registry] }}
# flavor: |
# latest=false
# tags: |
# development-v6

- name: Create manifest list and push (${{ matrix.registry }})
working-directory: /tmp/digests/${{ matrix.registry }}
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env[matrix.registry] }}@sha256:%s ' *)
# - name: Create manifest list and push (${{ matrix.registry }})
# working-directory: /tmp/digests/${{ matrix.registry }}
# run: |
# docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
# $(printf '${{ env[matrix.registry] }}@sha256:%s ' *)

- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env[matrix.registry] }}:${{ steps.meta.outputs.version }}
# - name: Inspect image
# run: |
# docker buildx imagetools inspect ${{ env[matrix.registry] }}:${{ steps.meta.outputs.version }}
3 changes: 2 additions & 1 deletion build-and-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)" \
Expand Down
12 changes: 3 additions & 9 deletions test/Dockerfile
Original file line number Diff line number Diff line change
@@ -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/

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
Expand Down
4 changes: 2 additions & 2 deletions test/cmd.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/usr/bin/env sh
set -eux

docker build ./src --tag pihole:${GIT_TAG} --no-cache
Expand All @@ -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/

0 comments on commit 94d68b2

Please sign in to comment.