Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build cffi and pyyaml from source #222

Merged
merged 5 commits into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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