Skip to content

Commit 37c6a90

Browse files

File tree

1 file changed

+149
-1
lines changed

1 file changed

+149
-1
lines changed

Dockerfile

Lines changed: 0 additions & 1 deletion
This file was deleted.

Dockerfile

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
# syntax=docker/dockerfile:1.1.7-experimental
2+
#############################################
3+
# Tox testsuite for multiple python version #
4+
#############################################
5+
FROM advian/tox-base:alpine-3.18 as tox
6+
ARG PYTHON_VERSIONS="3.11"
7+
ARG POETRY_VERSION="1.5.1"
8+
RUN export RESOLVED_VERSIONS=`pyenv_resolve $PYTHON_VERSIONS` \
9+
&& echo RESOLVED_VERSIONS=$RESOLVED_VERSIONS \
10+
&& for pyver in $RESOLVED_VERSIONS; do pyenv install -s $pyver; done \
11+
&& pyenv global $RESOLVED_VERSIONS \
12+
&& poetry self update $POETRY_VERSION || pip install -U poetry==$POETRY_VERSION \
13+
&& pip install -U tox \
14+
&& apk add --no-cache \
15+
git \
16+
&& true
17+
18+
######################
19+
# Base builder image #
20+
######################
21+
FROM python:3.13.0b1-alpine3.18 as builder_base
22+
23+
ENV \
24+
# locale
25+
LC_ALL=C.UTF-8 \
26+
# python:
27+
PYTHONFAULTHANDLER=1 \
28+
PYTHONUNBUFFERED=1 \
29+
PYTHONHASHSEED=random \
30+
# pip:
31+
PIP_NO_CACHE_DIR=off \
32+
PIP_DISABLE_PIP_VERSION_CHECK=on \
33+
PIP_DEFAULT_TIMEOUT=100 \
34+
# poetry:
35+
POETRY_VERSION=1.5.1
36+
37+
38+
RUN apk add --no-cache \
39+
curl \
40+
git \
41+
bash \
42+
build-base \
43+
libffi-dev \
44+
linux-headers \
45+
openssl \
46+
openssl-dev \
47+
tini \
48+
openssh-client \
49+
cargo \
50+
# githublab ssh
51+
&& mkdir -p -m 0700 ~/.ssh && ssh-keyscan gitlab.com github.com | sort > ~/.ssh/known_hosts \
52+
# Installing `poetry` package manager:
53+
&& curl -sSL https://install.python-poetry.org | python3 - \
54+
&& echo 'export PATH="/root/.local/bin:$PATH"' >>/root/.profile \
55+
&& export PATH="/root/.local/bin:$PATH" \
56+
&& true
57+
58+
SHELL ["/bin/bash", "-lc"]
59+
60+
61+
# Copy only requirements, to cache them in docker layer:
62+
WORKDIR /pysetup
63+
COPY ./poetry.lock ./pyproject.toml /pysetup/
64+
# Install basic requirements (utilizing an internal docker wheelhouse if available)
65+
RUN --mount=type=ssh pip3 install wheel virtualenv \
66+
&& poetry export -f requirements.txt --without-hashes -o /tmp/requirements.txt \
67+
&& pip3 wheel --wheel-dir=/tmp/wheelhouse -r /tmp/requirements.txt \
68+
&& virtualenv /.venv && source /.venv/bin/activate && echo 'source /.venv/bin/activate' >>/root/.profile \
69+
&& pip3 install --no-deps --find-links=/tmp/wheelhouse/ /tmp/wheelhouse/*.whl \
70+
&& true
71+
72+
73+
####################################
74+
# Base stage for production builds #
75+
####################################
76+
FROM builder_base as production_build
77+
# Copy entrypoint script
78+
COPY ./docker/entrypoint.sh /docker-entrypoint.sh
79+
# Only files needed by production setup
80+
COPY ./poetry.lock ./pyproject.toml ./README.rst ./src /app/
81+
WORKDIR /app
82+
# Build the wheel package with poetry and add it to the wheelhouse
83+
RUN --mount=type=ssh source /.venv/bin/activate \
84+
&& poetry build -f wheel --no-interaction --no-ansi \
85+
&& cp dist/*.whl /tmp/wheelhouse \
86+
&& chmod a+x /docker-entrypoint.sh \
87+
&& true
88+
89+
90+
#########################
91+
# Main production build #
92+
#########################
93+
FROM python:3.13.0b1-alpine3.18 as production
94+
COPY --from=production_build /tmp/wheelhouse /tmp/wheelhouse
95+
COPY --from=production_build /docker-entrypoint.sh /docker-entrypoint.sh
96+
WORKDIR /app
97+
# Install system level deps for running the package (not devel versions for building wheels)
98+
# and install the wheels we built in the previous step. generate default config
99+
RUN --mount=type=ssh apk add --no-cache \
100+
git \
101+
bash \
102+
tini \
103+
&& chmod a+x /docker-entrypoint.sh \
104+
&& WHEELFILE=`echo /tmp/wheelhouse/rmcli-*.whl` \
105+
&& pip3 install --find-links=/tmp/wheelhouse/ "$WHEELFILE"[all] \
106+
&& rm -rf /tmp/wheelhouse/ \
107+
# Do whatever else you need to
108+
&& true
109+
ENTRYPOINT ["/sbin/tini", "--", "/docker-entrypoint.sh"]
110+
111+
112+
#####################################
113+
# Base stage for development builds #
114+
#####################################
115+
FROM builder_base as devel_build
116+
# Install deps
117+
WORKDIR /pysetup
118+
RUN --mount=type=ssh source /.venv/bin/activate \
119+
&& poetry install --no-interaction --no-ansi \
120+
&& true
121+
122+
123+
#0############
124+
# Run tests #
125+
#############
126+
FROM devel_build as test
127+
COPY . /app
128+
WORKDIR /app
129+
ENTRYPOINT ["/sbin/tini", "--", "docker/entrypoint-test.sh"]
130+
# Re run install to get the service itself installed
131+
RUN --mount=type=ssh source /.venv/bin/activate \
132+
&& poetry install --no-interaction --no-ansi \
133+
&& docker/pre_commit_init.sh \
134+
&& true
135+
136+
137+
###########
138+
# Hacking #
139+
###########
140+
FROM devel_build as devel_shell
141+
# Copy everything to the image
142+
COPY . /app
143+
WORKDIR /app
144+
RUN apk add --no-cache zsh \
145+
&& sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" \
146+
&& echo "source /root/.profile" >>/root/.zshrc \
147+
&& pip3 install git-up \
148+
&& true
149+
ENTRYPOINT ["/bin/zsh", "-l"]

0 commit comments

Comments
 (0)