forked from redimp/otterwiki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
90 lines (86 loc) · 3.15 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#
# compile stage
#
FROM debian:12.7-slim AS compile-stage
LABEL maintainer="Ralph Thesen <[email protected]>"
# install python environment
RUN --mount=target=/var/cache/apt,type=cache,sharing=locked \
rm /etc/apt/apt.conf.d/docker-clean && \
apt-get update -y && \
apt-get upgrade -y && \
apt-get install -y --no-install-recommends python3.11 python3.11-venv \
python3-pip libjpeg-dev zlib1g-dev build-essential python3-dev
# prepare environment
RUN python3 -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
# upgrade pip and install requirements not in otterwiki
RUN --mount=type=cache,target=/root/.cache \
pip install -U pip wheel toml
# copy src files
COPY pyproject.toml MANIFEST.in README.md LICENSE /src/
WORKDIR /src
# install requirements
RUN --mount=type=cache,target=/root/.cache \
python -c 'import toml; print("\n".join(toml.load("./pyproject.toml")["project"]["dependencies"]));' > requirements.txt && \
pip install -r requirements.txt
# copy otterwiki source and tests
COPY otterwiki /src/otterwiki
COPY tests /src/tests
# install the otterwiki
RUN pip install .
#
# test stage
#
FROM compile-stage AS test-stage
# install git (not needed for compiling)
RUN --mount=target=/var/lib/apt/lists,type=cache,sharing=locked \
apt-get update -y && apt-get install -y --no-install-recommends git
# install the dev environment
RUN --mount=type=cache,target=/root/.cache \
pip install '.[dev]'
RUN --mount=type=cache,target=/root/.cache \
tox
# configure tox as default command when the test-stage is executed
CMD ["tox"]
#
# production stage
#
FROM debian:12.7-slim
# arg for marking dev images
ARG GIT_TAG
ENV GIT_TAG=$GIT_TAG
# environment variables (I'm not sure if anyone ever would modify this)
ENV OTTERWIKI_SETTINGS=/app-data/settings.cfg
ENV OTTERWIKI_REPOSITORY=/app-data/repository
# install supervisord and python
RUN --mount=target=/var/cache/apt,type=cache,sharing=locked \
apt-get -y update && \
apt-get upgrade -y && \
apt-get install -y --no-install-recommends \
nginx supervisor git \
python3.11 python3-wheel python3-venv libpython3.11 \
uwsgi uwsgi-plugin-python3 \
&& ln -sf /dev/stdout /var/log/nginx/access.log \
&& ln -sf /dev/stderr /var/log/nginx/error.log \
&& rm -rf /var/lib/apt/lists/*
# copy virtual environment
COPY --from=compile-stage /opt/venv /opt/venv
# Make sure we use the virtualenv:
ENV PATH="/opt/venv/bin:$PATH"
# create directories
RUN mkdir -p /app-data /app/otterwiki
VOLUME /app-data
RUN chown -R www-data:www-data /app-data
# copy static files for nginx
COPY otterwiki/static /app/otterwiki/static
# copy supervisord configs (nginx is configured in the entrypoint.sh)
COPY docker/uwsgi.ini /app/uwsgi.ini
COPY docker/supervisord.conf /etc/supervisor/conf.d/
COPY --chmod=0755 docker/stop-supervisor.sh /etc/supervisor/
# Copy the entrypoint that will generate Nginx additional configs
COPY --chmod=0755 ./docker/entrypoint.sh /entrypoint.sh
# configure the entrypoint
ENTRYPOINT ["/entrypoint.sh"]
# and the default command: supervisor which takes care of nginx and uWSGI
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"]
# vim:set et ts=8 sts=4 sw=4 ai fenc=utf-8: