|
1 | 1 | # syntax=docker/dockerfile:experimental |
2 | | - |
3 | | -FROM python:3.8-slim AS dev |
4 | | - |
5 | | -# Install development tools: compilers, curl, fish, git, ssh, and starship. |
6 | | -RUN apt-get update && \ |
7 | | - apt-get install --no-install-recommends --yes build-essential curl git fish ssh && \ |
8 | | - chsh --shell /usr/bin/fish && \ |
9 | | - sh -c "$(curl -fsSL https://starship.rs/install.sh)" -- "--yes" && \ |
10 | | - mkdir -p ~/.config/fish/completions/ && \ |
11 | | - echo "set fish_greeting" >> ~/.config/fish/config.fish && \ |
12 | | - echo "starship init fish | source" >> ~/.config/fish/config.fish && \ |
13 | | - rm -rf /var/lib/apt/lists/* |
| 2 | +FROM python:3.8-slim AS base |
14 | 3 |
|
15 | 4 | # Configure Python to print tracebacks on crash [1], and to not buffer stdout and stderr [2]. |
16 | 5 | # [1] https://docs.python.org/3/using/cmdline.html#envvar-PYTHONFAULTHANDLER |
17 | 6 | # [2] https://docs.python.org/3/using/cmdline.html#envvar-PYTHONUNBUFFERED |
18 | 7 | ENV PYTHONFAULTHANDLER 1 |
19 | 8 | ENV PYTHONUNBUFFERED 1 |
20 | 9 |
|
| 10 | +# Install Poetry. |
| 11 | +ENV POETRY_VERSION 1.1.13 |
| 12 | +RUN --mount=type=cache,id=poetry,target=/root/.cache/ pip install poetry==$POETRY_VERSION |
| 13 | + |
| 14 | +# Create and activate a virtual environment. |
| 15 | +RUN python -m venv /opt/app-env |
| 16 | +ENV PATH /opt/app-env/bin:$PATH |
| 17 | +ENV VIRTUAL_ENV /opt/app-env |
| 18 | + |
21 | 19 | # Set the working directory. |
22 | 20 | WORKDIR /app/ |
23 | 21 |
|
24 | | -# Install base development environment with Poetry and Poe the Poet. |
25 | | -ENV PATH /root/.local/bin/:$PATH |
26 | | -RUN --mount=type=cache,target=/root/.cache \ |
27 | | - pip install --no-input --upgrade pip poethepoet && \ |
28 | | - curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | python - && \ |
29 | | - poetry config virtualenvs.create false && \ |
30 | | - poetry completions fish > ~/.config/fish/completions/poetry.fish && \ |
31 | | - poe _fish_completion > ~/.config/fish/completions/poe.fish |
32 | | - |
33 | | -# Let Poe the Poet know it doesn't need to activate the Python environment. |
34 | | -ENV POETRY_ACTIVE 1 |
| 22 | +FROM base as dev |
35 | 23 |
|
36 | | -# Enable Poetry to publish to PyPI [1]. |
37 | | -# [1] https://pythonspeed.com/articles/build-secrets-docker-compose/ |
38 | | -ARG POETRY_PYPI_TOKEN_PYPI |
39 | | -ENV POETRY_PYPI_TOKEN_PYPI $POETRY_PYPI_TOKEN_PYPI |
| 24 | +# Install development tools: compilers, curl, git, gpg, ssh, starship, vim, and zsh. |
| 25 | +RUN rm /etc/apt/apt.conf.d/docker-clean |
| 26 | +RUN --mount=type=cache,id=apt-cache,target=/var/cache/apt/ \ |
| 27 | + --mount=type=cache,id=apt-lib,target=/var/lib/apt/ \ |
| 28 | + apt-get update && \ |
| 29 | + apt-get install --no-install-recommends --yes build-essential curl git gnupg ssh vim zsh zsh-antigen && \ |
| 30 | + chsh --shell /usr/bin/zsh && \ |
| 31 | + sh -c "$(curl -fsSL https://starship.rs/install.sh)" -- "--yes" && \ |
| 32 | + echo 'source /usr/share/zsh-antigen/antigen.zsh' >> ~/.zshrc && \ |
| 33 | + echo 'antigen bundle zsh-users/zsh-autosuggestions' >> ~/.zshrc && \ |
| 34 | + echo 'antigen apply' >> ~/.zshrc && \ |
| 35 | + echo 'eval "$(starship init zsh)"' >> ~/.zshrc && \ |
| 36 | + zsh -c 'source ~/.zshrc' |
| 37 | + |
| 38 | +# Install the development Python environment. |
| 39 | +COPY .pre-commit-config.yaml poetry.lock* pyproject.toml /app/ |
| 40 | +RUN --mount=type=cache,id=poetry,target=/root/.cache/ \ |
| 41 | + mkdir -p src/graphchain/ && touch src/graphchain/__init__.py && touch README.md && \ |
| 42 | + poetry install --no-interaction && \ |
| 43 | + mkdir -p /var/lib/poetry/ && cp poetry.lock /var/lib/poetry/ && \ |
| 44 | + git init && pre-commit install --install-hooks && \ |
| 45 | + mkdir -p /var/lib/git/ && cp .git/hooks/commit-msg .git/hooks/pre-commit /var/lib/git/ |
40 | 46 |
|
41 | | -FROM dev as ci |
| 47 | +FROM base as ci |
42 | 48 |
|
43 | | -# Install the Python environment. |
| 49 | +# Install the run time Python environment. |
44 | 50 | # TODO: Replace `--no-dev` with `--without test` when Poetry 1.2.0 is released. |
45 | 51 | COPY poetry.lock pyproject.toml /app/ |
46 | | -RUN --mount=type=cache,target=/root/.cache \ |
| 52 | +RUN --mount=type=cache,id=poetry,target=/root/.cache/ \ |
47 | 53 | mkdir -p src/graphchain/ && touch src/graphchain/__init__.py && touch README.md && \ |
48 | 54 | poetry install --no-dev --no-interaction |
0 commit comments