diff --git a/.github/workflows/docker-build.yaml b/.github/workflows/docker-build.yaml new file mode 100644 index 0000000..33432ff --- /dev/null +++ b/.github/workflows/docker-build.yaml @@ -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 }} diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml deleted file mode 100644 index 7c1cf63..0000000 --- a/.github/workflows/docker.yaml +++ /dev/null @@ -1,17 +0,0 @@ -name: Docker - -on: - push: - branches: - - main - tags: - - "*" - pull_request: - -jobs: - docker: - uses: janw/workflows/.github/workflows/docker.yaml@main - with: - build-platforms: linux/amd64,linux/arm64/v8 - skip-hadolint: true - tag-latest: true diff --git a/.github/workflows/linters.yaml b/.github/workflows/linters.yaml index cff58ef..33a9387 100644 --- a/.github/workflows/linters.yaml +++ b/.github/workflows/linters.yaml @@ -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 @@ -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 diff --git a/Dockerfile b/Dockerfile index 65a4494..23762a4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 " + +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" ]