From 3a4cff071a0c09c5f4a6b319cdb10724de119e86 Mon Sep 17 00:00:00 2001 From: znerol Date: Sat, 6 Jan 2024 17:05:26 +0100 Subject: [PATCH 1/5] Build cffi and pyyaml from source --- .github/workflows/container-test.yml | 41 ++++++++++++++++++++++++++++ Dockerfile | 27 ++++++++++++++---- 2 files changed, 62 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/container-test.yml diff --git a/.github/workflows/container-test.yml b/.github/workflows/container-test.yml new file mode 100644 index 0000000..1a266c2 --- /dev/null +++ b/.github/workflows/container-test.yml @@ -0,0 +1,41 @@ +--- +name: Build and test container image + +# yamllint disable-line rule:truthy +on: + push: + branches: + - main + tags: + - v* + pull_request: + branches: + - main + +jobs: + deploy: + runs-on: ubuntu-latest + + permissions: + contents: read + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: false + platforms: linux/arm64,linux/amd64 + tags: prometheus-pve-exporter:develop + + - name: Container image smoketest + run: docker run -it --rm prometheus-pve-exporter:develop --help diff --git a/Dockerfile b/Dockerfile index eca6f3f..2f9dd7d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,30 @@ -FROM alpine:3.19.0 -RUN apk update && apk upgrade +FROM alpine:3.19.0 as base -RUN apk add --no-cache \ +FROM base as build +RUN apk update && apk add --no-cache \ + build-base \ ca-certificates \ + libffi-dev \ + py3-build \ py3-pip \ - python3 + python3 \ + python3-dev \ + yaml-dev ADD . /src/prometheus-pve-exporter +WORKDIR /src/prometheus-pve-exporter +RUN python3 -m pip wheel -w dist --no-binary "cffi" --no-binary "pyyaml" -r requirements.txt && \ + python3 -m build . + +FROM base +RUN apk update && apk add --no-cache \ + ca-certificates \ + py3-pip \ + python3 + +COPY --from=build /src/prometheus-pve-exporter/dist /src/prometheus-pve-exporter/dist RUN python3 -m venv /opt/prometheus-pve-exporter && \ - /opt/prometheus-pve-exporter/bin/pip install -r /src/prometheus-pve-exporter/requirements.txt && \ - /opt/prometheus-pve-exporter/bin/pip install /src/prometheus-pve-exporter && \ + /opt/prometheus-pve-exporter/bin/pip install /src/prometheus-pve-exporter/dist/*.whl && \ ln -s /opt/prometheus-pve-exporter/bin/pve_exporter /usr/bin/pve_exporter && \ rm -rf /src/prometheus-pve-exporter /root/.cache From 5aa928d9d1212c05ef2c780f703c6a7557aed685 Mon Sep 17 00:00:00 2001 From: znerol Date: Sat, 6 Jan 2024 17:12:51 +0100 Subject: [PATCH 2/5] Add path filter for container-test github action --- .github/workflows/container-test.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/container-test.yml b/.github/workflows/container-test.yml index 1a266c2..7f84726 100644 --- a/.github/workflows/container-test.yml +++ b/.github/workflows/container-test.yml @@ -6,11 +6,13 @@ on: push: branches: - main - tags: - - v* pull_request: branches: - main + paths: + - 'Dockerfile' + - 'requirements.txt' + - 'setup.py' jobs: deploy: From c406091c2cae874694c293ff1eea942a59e1eb7d Mon Sep 17 00:00:00 2001 From: znerol Date: Sat, 6 Jan 2024 17:20:53 +0100 Subject: [PATCH 3/5] Remove spurious flags from docker smoketest cmd --- .github/workflows/container-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/container-test.yml b/.github/workflows/container-test.yml index 7f84726..8982702 100644 --- a/.github/workflows/container-test.yml +++ b/.github/workflows/container-test.yml @@ -40,4 +40,4 @@ jobs: tags: prometheus-pve-exporter:develop - name: Container image smoketest - run: docker run -it --rm prometheus-pve-exporter:develop --help + run: docker run --rm prometheus-pve-exporter:develop --help From 9c37fc25f8139a0a8adb3725af752fe4403ed9a2 Mon Sep 17 00:00:00 2001 From: znerol Date: Sat, 6 Jan 2024 17:29:48 +0100 Subject: [PATCH 4/5] Load result into local docker engine --- .github/workflows/container-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/container-test.yml b/.github/workflows/container-test.yml index 8982702..5cfa0de 100644 --- a/.github/workflows/container-test.yml +++ b/.github/workflows/container-test.yml @@ -35,7 +35,7 @@ jobs: uses: docker/build-push-action@v5 with: context: . - push: false + load: true platforms: linux/arm64,linux/amd64 tags: prometheus-pve-exporter:develop From 9460ca61a3a3a72b27b705ae08bc9e4f0525e462 Mon Sep 17 00:00:00 2001 From: znerol Date: Sat, 6 Jan 2024 17:57:11 +0100 Subject: [PATCH 5/5] Use matrix to run separate builds for each arch --- .github/workflows/container-test.yml | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/.github/workflows/container-test.yml b/.github/workflows/container-test.yml index 5cfa0de..5fd9ba4 100644 --- a/.github/workflows/container-test.yml +++ b/.github/workflows/container-test.yml @@ -15,7 +15,17 @@ on: - 'setup.py' jobs: - deploy: + test: + strategy: + matrix: + include: + - platform: 'linux/arm64' + tag: prometheus-pve-exporter:develop-arm64 + smoketest: false + - platform: 'linux/amd64' + tag: prometheus-pve-exporter:develop-amd64 + smoketest: true + runs-on: ubuntu-latest permissions: @@ -31,13 +41,14 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - name: Build Docker image + - name: Build Docker image (all architectures) uses: docker/build-push-action@v5 with: context: . load: true - platforms: linux/arm64,linux/amd64 - tags: prometheus-pve-exporter:develop + platforms: ${{ matrix.platform }} + tags: ${{ matrix.tag }} - name: Container image smoketest - run: docker run --rm prometheus-pve-exporter:develop --help + if: ${{ matrix.smoketest }} + run: docker run --rm ${{ matrix.tag }} --help