Skip to content

Commit

Permalink
fix: Restore and modernize docker build (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
janw authored Oct 12, 2024
1 parent a646e7d commit deb0e58
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 27 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/docker-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Docker Build

on:
pull_request:
push:
branches:
- "main"
tags:
- "v*"

jobs:
docker-build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: "ghcr.io/${{ github.repository }}"
tags: |
type=ref,event=pr
type=semver,pattern=v{{major}}
type=semver,pattern=v{{version}}
type=raw,value=edge,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
- name: Set up Docker Buildx # cspell: disable-line
uses: docker/setup-buildx-action@v2 # cspell: disable-line

- name: Login to Github Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
id: docker_build
uses: docker/build-push-action@v4
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64/v8

- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
17 changes: 0 additions & 17 deletions .github/workflows/docker.yaml

This file was deleted.

3 changes: 2 additions & 1 deletion .github/workflows/linters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:

- name: Set up python environment
uses: actions/setup-python@v5
id: setup-python
with:
cache: poetry
python-version: 3.x
Expand All @@ -31,7 +32,7 @@ jobs:
uses: actions/cache/restore@v4
with:
path: ~/.cache/pre-commit
key: pre-commit-v0|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}
key: pre-commit-v0|${{ steps.setup-python.outputs.python-version }}|${{ hashFiles('.pre-commit-config.yaml') }}

- id: pre-commit
shell: bash
Expand Down
42 changes: 33 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,38 @@
# syntax=docker/dockerfile:1
FROM python:3.11-slim
FROM python:3.12-slim AS venv

WORKDIR /
RUN --mount=type=bind,target=/src \
set -e; \
apt-get update -y; \
apt-get install -y --no-install-recommends tini libsndfile1; \
LABEL maintainer="Jan Willhaus <[email protected]>"

ENV PYTHONUNBUFFERED=1
ENV POETRY_VERSION=1.8.2

WORKDIR /src
COPY pyproject.toml poetry.lock ./

RUN set -e; \
pip install -U --no-cache-dir pip "poetry~=$POETRY_VERSION"; \
python -m venv /venv; \
. /venv/bin/activate; \
poetry install \
--no-interaction \
--no-directory \
--no-root \
--only main

FROM python:3.12-slim

ENV PATH=/venv/bin:$PATH

RUN set -e; \
apt-get update; \
apt-get install -y --no-install-recommends 'tini=0.19.*' 'libsndfile1=1.*'; \
apt-get clean; \
rm -rf /var/lib/apt/lists/*; \
pip install --no-cache-dir /src
rm -rf /var/lib/apt/lists/*

COPY --from=venv /venv /venv
COPY ./drmeter /drmeter

VOLUME [ "/archive" ]

ENTRYPOINT [ "tini", "--", "drmeter" ]
ENTRYPOINT [ "tini", "--", "python", "-m", "drmeter"]
CMD [ "--help" ]

0 comments on commit deb0e58

Please sign in to comment.