Skip to content

Commit

Permalink
Build cffi and pyyaml from source (#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
znerol authored Jan 7, 2024
1 parent 8cb048c commit 1d396dc
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 6 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/container-test.yml
Original file line number Diff line number Diff line change
@@ -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
27 changes: 21 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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

Expand Down

0 comments on commit 1d396dc

Please sign in to comment.