Skip to content

Commit

Permalink
Merge remote-tracking branch 'structure-local/py-ci-cli' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
rpatterson committed May 8, 2023
2 parents 53aadc4 + 9ed94c6 commit 28d2c1c
Show file tree
Hide file tree
Showing 33 changed files with 805 additions and 438 deletions.
10 changes: 6 additions & 4 deletions .env.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,22 @@
COMPOSE_PATH_SEPARATOR=:
COMPOSE_FILE=./docker-compose.yml:./gitlab-runner/docker-compose.yml:./docker-compose-servarr.yml:./docker-compose.override.yml

# Capture local values specific to this checkout
# Capture local values specific to this checkout:
TZ=${TZ}
PUID=${PUID}
PGID=${PGID}
# Absolute path of the git repo checkout, useful where relative paths can't be used
# Absolute path of the git repo checkout, useful where relative paths can't be used:
CHECKOUT_DIR=${CHECKOUT_DIR}
# Build host variables
# Build host variables:
DOCKER_GID=${DOCKER_GID}
# Release variables

# Release variables:
DOCKER_USER=${DOCKER_USER}
# Best to create and use a token. Note that the token must have the `admin`/"Read,
# Write, Delete" scope, aka "ACCESS PERMISSIONS":
# https://hub.docker.com/settings/security?generateToken=true
DOCKER_PASS=${DOCKER_PASS}

# Project host credentials used here and in CI/CD to support local testing/debugging:
CI_REGISTRY_PASSWORD=${CI_REGISTRY_PASSWORD}
PROJECT_GITHUB_PAT=${PROJECT_GITHUB_PAT}
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ target/
celerybeat-schedule

# dotenv
.env
/.env

# virtualenv
venv/
Expand Down
2 changes: 1 addition & 1 deletion .prospector.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pylint:
# run: true
# FIXME: I confirmed the package is installed but couldn't get to work:
# Cannot run tool pyroma as support was not installed.
# Please install by running 'pip install prospector[with_pyroma]'
# Please install by running 'pip3 install prospector[with_pyroma]'
# pyroma:
# run: true

Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ If there's not already `an issue/ticket`_ for the changes you'll be making, crea
Regardless, take note of the issue/ticket number, e.g. ``#123``. Then create a
branch/fork off of the ``develop`` branch::

$ git switch -c feat-123-foo-bar origin/develop
$ git switch -c feat-123-foo-bar --track origin/develop

This project uses `towncrier`_ to manage it's release notes, AKA changelog and thus
requires at least one `news fragment`_ before merging back into ``develop``. The VCS
Expand Down
111 changes: 87 additions & 24 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,44 @@
#
# SPDX-License-Identifier: MIT

## Container image for use by end users

## Image layers shared between all variants.

# Stay as close to a vanilla Python environment as possible
ARG PYTHON_MINOR=3.10
FROM python:${PYTHON_MINOR}
FROM python:${PYTHON_MINOR} AS base
# Defensive shell options:
SHELL ["/bin/bash", "-eu", "-o", "pipefail", "-c"]

# Least volatile layers first:
# https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys
LABEL org.opencontainers.image.url="https://gitlab.com/rpatterson/prunerr"
LABEL org.opencontainers.image.documentation="https://gitlab.com/rpatterson/prunerr"
LABEL org.opencontainers.image.source="https://gitlab.com/rpatterson/prunerr"
LABEL org.opencontainers.image.title="Prunerr"
LABEL org.opencontainers.image.description="Remove Servarr download client items to preserve disk space according to rules."
LABEL org.opencontainers.image.licenses="MIT"
LABEL org.opencontainers.image.authors="Ross Patterson <me@rpatterson.net>"
LABEL org.opencontainers.image.vendor="rpatterson.net"
LABEL org.opencontainers.image.base.name="docker.io/library/python:${PYTHON_MINOR}"

# Find the same home directory even when run as another user, e.g. `root`.
ENV HOME="/home/prunerr"
ENTRYPOINT [ "entrypoint" ]
CMD [ "prunerr", "daemon" ]

# Put the `ENTRYPOINT` on the `$PATH`
COPY [ "./bin/entrypoint", "/usr/local/bin/entrypoint" ]

# Install OS packages needed for the image `ENDPOINT`:
RUN \
rm -f /etc/apt/apt.conf.d/docker-clean && \
echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' \
>"/etc/apt/apt.conf.d/keep-cache"
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt-get update && \
apt-get install --no-install-recommends -y gosu=1.12-1+b6
# Put the `ENTRYPOINT` on the `$PATH`
COPY [ "./bin/entrypoint", "/usr/local/bin/entrypoint" ]
apt-get install --no-install-recommends -y "gosu=1.12-1+b6"

WORKDIR "/usr/local/src/prunerr/"
# Install dependencies with fixed versions in a separate layer to optimize build times
Expand All @@ -26,32 +48,73 @@ ARG PYTHON_ENV=py310
COPY [ "./requirements/${PYTHON_ENV}/user.txt", "./requirements/${PYTHON_ENV}/" ]
# hadolint ignore=DL3042
RUN --mount=type=cache,target=/root/.cache,sharing=locked \
pip install -r "./requirements/${PYTHON_ENV}/user.txt"
pip3 install -r "./requirements/${PYTHON_ENV}/user.txt"

# Build-time `LABEL`s
ARG VERSION=
LABEL org.opencontainers.image.version=${VERSION}


## Container image for use by end users.

# Stay as close to a vanilla environment as possible:
FROM base AS user
# Defensive shell options:
SHELL ["/bin/bash", "-eu", "-o", "pipefail", "-c"]

# Least volatile layers first:
WORKDIR "/home/prunerr/"

# Install this package in the most common/standard Python way while still being able to
# build the image locally.
ARG PYTHON_WHEEL
COPY [ "${PYTHON_WHEEL}", "${PYTHON_WHEEL}" ]
# hadolint ignore=DL3013,DL3042
RUN --mount=type=cache,target=/root/.cache,sharing=locked \
pip install "${PYTHON_WHEEL}" && \
pip3 install "${PYTHON_WHEEL}" && \
rm -rfv "./dist/"

# Find the same configuration file even when run as another user, e.g. `root`.
ENV HOME="/home/prunerr/"
WORKDIR "/home/prunerr/"
ENTRYPOINT [ "entrypoint" ]
CMD [ "prunerr", "daemon" ]

# https://github.com/opencontainers/image-spec/blob/main/annotations.md#pre-defined-annotation-keys
LABEL org.opencontainers.image.url="https://gitlab.com/rpatterson/prunerr"
LABEL org.opencontainers.image.documentation="https://gitlab.com/rpatterson/prunerr"
LABEL org.opencontainers.image.source="https://gitlab.com/rpatterson/prunerr"
LABEL org.opencontainers.image.title="Prunerr"
## Container image for use by developers.

# Stay as close to the end user image as possible for build cache efficiency:
FROM base AS devel
# Defensive shell options:
SHELL ["/bin/bash", "-eu", "-o", "pipefail", "-c"]

# Least volatile layers first:
LABEL org.opencontainers.image.title="Prunerr Development"
LABEL org.opencontainers.image.description="Remove Servarr download client items to preserve disk space according to rules."
LABEL org.opencontainers.image.licenses="MIT"
LABEL org.opencontainers.image.authors="Ross Patterson <me@rpatterson.net>"
LABEL org.opencontainers.image.vendor="rpatterson.net"
LABEL org.opencontainers.image.base.name="docker.io/library/python:${PYTHON_MINOR}"
# Build-time `LABEL`s
ARG VERSION=
LABEL org.opencontainers.image.version=${VERSION}

# Activate the Python virtual environment
ENV VIRTUAL_ENV="/usr/local/src/prunerr/.tox/${PYTHON_ENV}"
ENV PATH="${VIRTUAL_ENV}/bin:${PATH}"
# Remain in the checkout `WORKDIR` and make the build tools the default
# command to run.
WORKDIR "/usr/local/src/prunerr/"
# Have to use the shell form of `CMD` because we need variable substitution:
# hadolint ignore=DL3025
CMD tox -e "${PYTHON_ENV}"

# Then add everything that might contribute to efficient development.

# Simulate the parts of the host install process from `./Makefile` needed for
# development in the image:
COPY [ "./build-host/requirements.txt.in", "./build-host/" ]
# hadolint ignore=DL3042
RUN --mount=type=cache,target=/root/.cache,sharing=locked \
mkdir -pv "${HOME}/.local/var/log/" && \
pip3 install -r "./build-host/requirements.txt.in" | \
tee -a "${HOME}/.local/var/log/prunerr-host-install.log"

# Match local development tool chain and avoid time consuming redundant package
# installs. Initialize the `$ tox -e py3##` Python virtual environment to install this
# package and all the development tools into the image:
COPY [ \
"./requirements/${PYTHON_ENV}/test.txt", \
"./requirements/${PYTHON_ENV}/devel.txt", \
"./requirements/${PYTHON_ENV}/" \
]
COPY [ "./tox.ini", "./" ]
RUN --mount=type=cache,target=/root/.cache,sharing=locked \
tox --no-recreate-pkg --skip-pkg-install --notest -e "${PYTHON_ENV}"
70 changes: 0 additions & 70 deletions Dockerfile.devel

This file was deleted.

0 comments on commit 28d2c1c

Please sign in to comment.