Skip to content

Commit

Permalink
Dockerize dev pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
makukha committed Nov 19, 2024
1 parent 1e22a50 commit f5973f7
Show file tree
Hide file tree
Showing 17 changed files with 200 additions and 1,665 deletions.
5 changes: 0 additions & 5 deletions .dev/Brewfile

This file was deleted.

74 changes: 74 additions & 0 deletions .dev/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
FROM python:3.13-bookworm AS base
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
--mount=type=bind,from=dattached/bootstrap,dst=/b \
<<EOT
apt-get update
bash /b/debian-apt-install-devtools.sh
apt-get install -y build-essential gdb lcov pkg-config \
libbz2-dev libffi-dev libgdbm-dev libgdbm-compat-dev liblzma-dev \
libncurses5-dev libreadline6-dev libsqlite3-dev libssl-dev \
lzma lzma-dev tk-dev uuid-dev zlib1g-dev libmpdec-dev
curl https://pyenv.run | sh
ln -s /root/.pyenv/bin/pyenv /usr/local/bin
pyenv update
rm -rf /tmp/* /var/tmp/*
EOT

FROM base AS py27
RUN pyenv install 2.7

FROM base AS py35
RUN pyenv install 3.5

FROM base AS py36
RUN pyenv install 3.6

FROM base AS py37
RUN pyenv install 3.7

FROM base AS py38
RUN pyenv install 3.8

FROM base AS py39
RUN pyenv install 3.9

FROM base AS py310
RUN pyenv install 3.10

FROM base AS py311
RUN pyenv install 3.11

FROM base AS py312
RUN pyenv install 3.12

FROM base AS py314
RUN pyenv install 3.14.0a1


FROM base AS dev
RUN --mount=type=bind,from=py27,src=/root/.pyenv,dst=/tmp/py27 \
--mount=type=bind,from=py35,src=/root/.pyenv,dst=/tmp/py35 \
--mount=type=bind,from=py36,src=/root/.pyenv,dst=/tmp/py36 \
--mount=type=bind,from=py37,src=/root/.pyenv,dst=/tmp/py37 \
--mount=type=bind,from=py38,src=/root/.pyenv,dst=/tmp/py38 \
--mount=type=bind,from=py39,src=/root/.pyenv,dst=/tmp/py39 \
--mount=type=bind,from=py310,src=/root/.pyenv,dst=/tmp/py310 \
--mount=type=bind,from=py311,src=/root/.pyenv,dst=/tmp/py311 \
--mount=type=bind,from=py312,src=/root/.pyenv,dst=/tmp/py312 \
--mount=type=bind,from=py314,src=/root/.pyenv,dst=/tmp/py314 \
<<EOT
mkdir -p /root/.pyenv/versions
cp -a /tmp/py*/versions/* /root/.pyenv/versions
pyenv install --skip-existing 2.7 3.5 3.6 3.7 3.8 3.9 3.10 3.11 3.12 3.14.0a1
EOT
COPY .dev/requirements.*.txt /tmp/
RUN --mount=type=cache,dst=/root/.cache/pip \
--mount=type=cache,dst=/root/.cache/uv \
<<EOT
pip install uv
uv pip install --system -r /tmp/requirements.dev.txt -r /tmp/requirements.doc.txt
EOT
ENV VIRTUALENV_DISCOVERY=pyenv
WORKDIR /project
EXPOSE 8000
6 changes: 0 additions & 6 deletions .dev/alacritty.sh

This file was deleted.

14 changes: 14 additions & 0 deletions .dev/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
services:
dev:
build:
context: ..
dockerfile: .dev/Dockerfile
target: dev
hostname: caseutil
command: bash -c 'task --list; bash -i'
stdin_open: true
tty: true
ports:
- '8000:8000'
volumes:
- ..:/project
9 changes: 9 additions & 0 deletions .dev/requirements.dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# static
mypy
ruff
# tests
genbadge[coverage,tests]
tox
virtualenv-pyenv
# release
bump-my-version
2 changes: 2 additions & 0 deletions .dev/requirements.doc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mkdocs
mkdocs-material
6 changes: 6 additions & 0 deletions .dev/terminal.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

BASEDIR=$(dirname "$0")
NAME=$(basename "$(realpath $BASEDIR/..)")

alacritty --hold --working-directory $BASEDIR/.. --title $NAME &
15 changes: 2 additions & 13 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
Brewfile.lock.json
build/
dist/
.idea/
.pdm-build/
.pdm-python
*.egg-info
__pycache__/
.task/
tmp/
.tox/
.venv/

# OS generated
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
2 changes: 1 addition & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ mkdocs:

python:
install:
- requirements: docs/requirements.txt
- requirements: .dev/requirements.doc.txt
38 changes: 0 additions & 38 deletions .ruff.toml

This file was deleted.

127 changes: 31 additions & 96 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -1,97 +1,41 @@
version: '3'

vars:
GITHUB_REPO: makukha/caseutil
GET_PYTHON_VERSIONS: tox --listenvs | sed -e 's/^py//' | xargs echo
env:
COMPOSE_FILE: .dev/compose.yaml

tasks:

# init
# dev environment

init:
desc: Initialize dev environment.
dev:
desc: Enter dev container.
cmds:
- task: init:homebrew
- task: init:python
- task: init:python-env
- task: dev:build
- docker compose run --service-ports --rm dev

init:homebrew:
internal: true
dir: .dev
sources: [Brewfile]
env:
HOMEBREW_BUNDLE_NO_LOCK: 1
cmds:
- brew bundle

init:python:
dev:build:
internal: true
sources:
- tox.ini
vars:
PYTHON_VERSIONS:
sh: tox --listenvs | sed -ne 's/^py\([23]\)\.\{0,1\}\([0-9].*\)/\1.\2/p' | sort -mu | tr '\n' ' '
cmds:
- cmd: pyenv install --skip-existing {{.ITEM}}
for: {var: PYTHON_VERSIONS}

init:python-env:
internal: true
status:
- test -e .venv
- .dev/*
cmds:
- pyenv install --skip-existing $(pyenv local)
- pdm venv create $(pyenv prefix $(pyenv local))
- docker compose build

# install
# dev commands

install:
desc: Install dev environment.
cmds:
- task: install:python-dependencies
- task: install:python-package

install:python-dependencies:
internal: true
sources: [pyproject.toml]
cmds:
- pdm lock --update-reuse
- pdm install --check --dev --no-self

install:python-package:
internal: true
sources: [src/**/*.*]
cmds:
- pdm install --check --dev

# build

build:
desc: Build all.
desc: Install package system-wide.
cmds:
- task: build:docs-requirements
- task: build:test-readme
- uv pip install --system -e .

# docs

build:docs-requirements:
internal: true
sources: [pyproject.toml]
generates: [docs/requirements.txt]
cmds:
- pdm export --dev --group docs --no-hashes > docs/requirements.txt

run:docs:
docs:
desc: Serve local MkDocs.
cmds:
- mkdocs serve

# lint, format

lint:
desc: Run linters.
cmds:
- pdm run mypy src
- mypy src
- ruff check
- ruff format --check

Expand All @@ -100,44 +44,35 @@ tasks:
cmds:
- ruff format

# test
version:
desc: Bump project version. Use task version -- patch|minor|major|...
cmds:
- bump-my-version bump {{.CLI_ARGS}}

build:test-readme:
internal: true
sources: [README.md]
generates: [tests/test_readme.txt]
publish:
desc: Publish package on PyPi.
preconditions:
- test $(git rev-parse --abbrev-ref HEAD) = main
cmds:
- sed -ne '/^```doctest/,/^```/{/^```doctest/d; s/^```//; p;}' README.md
> tests/test_readme.txt
- uv build --no-sources
- uv publish

# dev testing

test:
desc: Run tests.
deps: [install, build, lint]
deps: [lint, install]
cmds:
- tox run

test:main:
desc: Run tests in main environment.
deps: [install, build]
deps: [install]
cmds:
- tox run -m main

test:debug:
desc: Run tests and open debugger on errors.
deps: [install, build]
cmds:
- pdm run pytest --pdb {{.CLI_ARGS}}

# version, publish

version:
desc: Bump project version. Use task version -- patch|minor|major|...
cmds:
- pdm run bump-my-version bump {{.CLI_ARGS}}

publish:
desc: Publish package on PyPi.
preconditions:
- test $(git rev-parse --abbrev-ref HEAD) = main
deps: [install]
cmds:
- pdm publish
- pytest --pdb {{.CLI_ARGS}}
33 changes: 0 additions & 33 deletions docs/requirements.txt

This file was deleted.

Loading

0 comments on commit f5973f7

Please sign in to comment.