Skip to content

Commit

Permalink
feat(docker): add docker and skaffold support
Browse files Browse the repository at this point in the history
  • Loading branch information
miragecentury committed Jul 25, 2024
1 parent 3a7d9bb commit f1376f7
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 1 deletion.
51 changes: 51 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
FROM docker.io/library/python:3.12.4-slim-bullseye as base
# hadolint shell=/bin/sh

# Prepare OS
ENV DEBIAN_FRONTEND=noninteractive \
LC_ALL=C.UTF-8 \
SHELL=/bin/bash

COPY docker/apt.conf /etc/apt/apt.conf.d/apt.conf

# Update OS
# hadolint ignore=DL3013
RUN \
set -eux && \
apt-get update && \
apt-get upgrade -V && \
pip install --no-cache-dir --upgrade pip && \
# Clean (General)
find /var/log -mtime -1 -type f -exec truncate -s 0 {} \; && \
rm -rf \
/var/lib/apt/lists/* \
/var/cache/debconf/* \
/var/log/*.gz \
/var/log/*.log

ARG UID=1000
ARG GID=1000

# Prepare filesystem
RUN groupadd -g "${GID}" pythongroup && \
useradd -l -u "${UID}" -g "${GID}" -d /opt/app -s /sbin/nologin pythonuser && \
usermod -L pythonuser && \
mkdir -p /opt/app/build && mkdir -p /opt/app/build/wheels && \
chown -R pythonuser:pythongroup /opt/app

USER ${UID}

WORKDIR /opt/app

COPY --chown=pythonuser:pythongroup pyproject.toml /opt/app/pyproject.toml
COPY --chown=pythonuser:pythongroup build/wheels build/wheels

RUN pip install \
--no-cache-dir \
--progress-bar off \
/opt/app/build/wheels/*.whl && \
rm -rf /opt/app/build

ENTRYPOINT [ "python3", "-m", "python_poetry_empty" ]

CMD ["execute"]
7 changes: 7 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: "3"

services:
python-poetry-empty:
build:
context: .
dockerfile: Dockerfile
7 changes: 7 additions & 0 deletions docker/apt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
APT::Get::Assume-Yes "true";
APT::Get::allow-change-held-packages "true";
APT::Install-Recommends "false";
APT::Get::AutomaticRemove "1";
APT::Get::Purge "1";
Dpkg::Progress "0";
Dpkg::Progress-Fancy "0";
4 changes: 3 additions & 1 deletion scripts/setup_dev_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Poetry setup
poetry env use python3.12
poetry install --with test,dev
poetry install --with test
poetry update --sync

# Pre-commit setup
Expand All @@ -13,3 +13,5 @@ PATH="./src:./tests:\$PATH"
PYTHONPATH="./src:./tests:\$PYTHONPATH"
EOF

mkdir -p build/wheels
45 changes: 45 additions & 0 deletions skaffold.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
apiVersion: skaffold/v4beta11
kind: Config
metadata:
name: python-poetry-empty
build:
hooks:
before:
- command: ["pre-commit", "run", "--all-files"]

after: []
artifacts:
- image: python-poetry-empty
hooks:
before:
- command: ["mkdir", "-p", "build/wheels"]
- command: ["poetry","export", "--no-interaction", "--format=requirements.txt", "--output=build/requirements.txt"]
- command: ["poetry","build", "--no-interaction", "--format=wheel", "--output=build/wheels"]
- command:
- "pip"
- "wheel"
- "--no-cache-dir"
- "--prefer-binary"
- "--require-hashes"
- "-r"
- "build/requirements.txt"
- --cache-dir
- "build/.pip-cache"
- "-w"
- "build/wheels"
context: .
runtimeType: python
docker:
cacheFrom:
- docker.io/library/python:3.12.4-slim-bullseye
dockerfile: "Dockerfile"
buildArgs:
DEV: "false"
local:
push: false
useBuildkit: true
deploy:
docker:
useCompose: false
images:
- python-poetry-empty

0 comments on commit f1376f7

Please sign in to comment.