diff --git a/.github/workflows/container-test.yml b/.github/workflows/container-test.yml new file mode 100644 index 0000000..5fd9ba4 --- /dev/null +++ b/.github/workflows/container-test.yml @@ -0,0 +1,54 @@ +--- +name: Build and test container image + +# yamllint disable-line rule:truthy +on: + push: + branches: + - main + pull_request: + branches: + - main + paths: + - 'Dockerfile' + - 'requirements.txt' + - 'setup.py' + +jobs: + 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: + 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 (all architectures) + uses: docker/build-push-action@v5 + with: + context: . + load: true + platforms: ${{ matrix.platform }} + tags: ${{ matrix.tag }} + + - name: Container image smoketest + if: ${{ matrix.smoketest }} + run: docker run --rm ${{ matrix.tag }} --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