Add local build infrastructure

Add support for persistent data in container
This commit is contained in:
Ethan Paul 2023-10-15 18:14:59 -04:00
parent e3f0800f5d
commit 8da0315319
Signed by: enpaul
GPG Key ID: 07F53B438281D181
3 changed files with 116 additions and 17 deletions

View File

@ -1,5 +1,8 @@
FROM docker.io/library/python:3.11 AS build
# ======================================================
# Stage 1: Build BorgBackup wheel
FROM docker.io/library/python:3.11 AS build-borg
# Install borg build dependencies
RUN apt update --yes
RUN apt install --yes \
libacl1-dev \
@ -12,44 +15,79 @@ RUN apt install --yes \
pkg-config \
python3-pkgconfig \
libfuse3-dev
RUN python -m pip install \
Cython==3.0.3 \
pkgconfig==1.5.5 \
--disable-pip-version-check \
--upgrade
# remember to add borg user to fuse group in final container
# Build borg dist wheel
COPY . /source
RUN cd /source/borgbackup && python -m pip wheel .[pyfuse3] \
WORKDIR /source/borgbackup
RUN python -m pip wheel .[pyfuse3] \
--wheel-dir /wheels \
--prefer-binary \
--disable-pip-version-check
FROM docker.io/library/python:3.11-slim AS final
# ======================================================
# Stage 2: Build local repo resources
FROM docker.io/library/python:3.11 as build-drone
ENV POETRY_HOME /poetry
RUN curl -o /install-poetry.py -sSL https://install.python-poetry.org
RUN python /install-poetry.py --yes
COPY . /source
WORKDIR /source
RUN ${POETRY_HOME}/bin/poetry export \
--format requirements.txt \
--output /requirements.txt \
--without-hashes
RUN python -m pip wheel \
--wheel-dir /wheels \
--requirement /requirements.txt \
--disable-pip-version-check \
--no-cache-dir
# ======================================================
# Stage 3: Final distribution image
FROM docker.io/library/python:3.11-slim AS publish
RUN apt update --yes && \
apt install openssh-clients --yes && \
apt install openssh-client --yes && \
apt clean all && \
mkdir /repo /data && \
useradd borg --uid 1000 --gid 1000 && \
chown --recursive borg:borg /repo
mkdir /repo /data /keys && \
useradd borg --uid 1000 --home-dir /home/borg --create-home && \
chown --recursive borg:borg /repo && \
chown --recursive borg:borg /keys && \
chmod --recursive 0600 /keys
VOLUME ["/repo", "/data"]
COPY --from=build /wheels /wheels
COPY --from=build-borg /wheels /wheels/borg
COPY --from=build-drone /wheels /wheels/drone
COPY --from=build-drone /requirements.txt /wheels/drone.txt
RUN python -m pip install borgbackup[pyfuse3] \
--upgrade \
--pre \
--no-index \
--no-cache-dir \
--find-links /wheels \
--find-links /wheels/borg \
--disable-pip-version-check && \
rm -rf /install/
python -m pip install \
--requirement /wheels/drone.txt \
--upgrade \
--pre \
--no-index \
--no-cache-dir \
--find-links /wheels/drone \
--disable-pip-version-check && \
rm -rf /wheels/
WORKDIR /repo
VOLUME ["/repo", "/data", "/keys"]
USER 1000:1000
ENTRYPOINT ["/usr/local/bin/borg"]
ENTRYPOINT ["/bin/bash"]

48
poetry.lock generated Normal file
View File

@ -0,0 +1,48 @@
# This file is automatically @generated by Poetry 1.6.1 and should not be changed by hand.
[[package]]
name = "plumbum"
version = "1.8.2"
description = "Plumbum: shell combinators library"
optional = false
python-versions = ">=3.6"
files = [
{file = "plumbum-1.8.2-py3-none-any.whl", hash = "sha256:3ad9e5f56c6ec98f6f7988f7ea8b52159662ea9e915868d369dbccbfca0e367e"},
{file = "plumbum-1.8.2.tar.gz", hash = "sha256:9e6dc032f4af952665f32f3206567bc23b7858b1413611afe603a3f8ad9bfd75"},
]
[package.dependencies]
pywin32 = {version = "*", markers = "platform_system == \"Windows\" and platform_python_implementation != \"PyPy\""}
[package.extras]
dev = ["paramiko", "psutil", "pytest (>=6.0)", "pytest-cov", "pytest-mock", "pytest-timeout"]
docs = ["sphinx (>=4.0.0)", "sphinx-rtd-theme (>=1.0.0)"]
ssh = ["paramiko"]
[[package]]
name = "pywin32"
version = "306"
description = "Python for Window Extensions"
optional = false
python-versions = "*"
files = [
{file = "pywin32-306-cp310-cp310-win32.whl", hash = "sha256:06d3420a5155ba65f0b72f2699b5bacf3109f36acbe8923765c22938a69dfc8d"},
{file = "pywin32-306-cp310-cp310-win_amd64.whl", hash = "sha256:84f4471dbca1887ea3803d8848a1616429ac94a4a8d05f4bc9c5dcfd42ca99c8"},
{file = "pywin32-306-cp311-cp311-win32.whl", hash = "sha256:e65028133d15b64d2ed8f06dd9fbc268352478d4f9289e69c190ecd6818b6407"},
{file = "pywin32-306-cp311-cp311-win_amd64.whl", hash = "sha256:a7639f51c184c0272e93f244eb24dafca9b1855707d94c192d4a0b4c01e1100e"},
{file = "pywin32-306-cp311-cp311-win_arm64.whl", hash = "sha256:70dba0c913d19f942a2db25217d9a1b726c278f483a919f1abfed79c9cf64d3a"},
{file = "pywin32-306-cp312-cp312-win32.whl", hash = "sha256:383229d515657f4e3ed1343da8be101000562bf514591ff383ae940cad65458b"},
{file = "pywin32-306-cp312-cp312-win_amd64.whl", hash = "sha256:37257794c1ad39ee9be652da0462dc2e394c8159dfd913a8a4e8eb6fd346da0e"},
{file = "pywin32-306-cp312-cp312-win_arm64.whl", hash = "sha256:5821ec52f6d321aa59e2db7e0a35b997de60c201943557d108af9d4ae1ec7040"},
{file = "pywin32-306-cp37-cp37m-win32.whl", hash = "sha256:1c73ea9a0d2283d889001998059f5eaaba3b6238f767c9cf2833b13e6a685f65"},
{file = "pywin32-306-cp37-cp37m-win_amd64.whl", hash = "sha256:72c5f621542d7bdd4fdb716227be0dd3f8565c11b280be6315b06ace35487d36"},
{file = "pywin32-306-cp38-cp38-win32.whl", hash = "sha256:e4c092e2589b5cf0d365849e73e02c391c1349958c5ac3e9d5ccb9a28e017b3a"},
{file = "pywin32-306-cp38-cp38-win_amd64.whl", hash = "sha256:e8ac1ae3601bee6ca9f7cb4b5363bf1c0badb935ef243c4733ff9a393b1690c0"},
{file = "pywin32-306-cp39-cp39-win32.whl", hash = "sha256:e25fd5b485b55ac9c057f67d94bc203f3f6595078d1fb3b458c9c28b7153a802"},
{file = "pywin32-306-cp39-cp39-win_amd64.whl", hash = "sha256:39b61c15272833b5c329a2989999dcae836b1eed650252ab1b7bfbe1d59f30f4"},
]
[metadata]
lock-version = "2.0"
python-versions = "^3.11"
content-hash = "d325ef96be40a06d5754949589d90e6fee27a3589e5a20b05313c90f98c840c0"

13
pyproject.toml Normal file
View File

@ -0,0 +1,13 @@
[tool.poetry]
name = "borgdrone"
version = "0.0.0"
description = "Scripting to support the BorgDrone container"
authors = ["Ethan Paul <24588726+enpaul@users.noreply.github.com>"]
license = "GNU-3"
readme = "README.md"
[tool.poetry.dependencies]
python = "^3.11"
plumbum = "^1.8.2"