|
1 | 1 | # Dockerfile for uWSGI wrapped Giftless Git LFS Server |
| 2 | +# Shared build ARGs among stages |
| 3 | +ARG WORKDIR=/app |
| 4 | +ARG VENV="$WORKDIR/.venv" |
2 | 5 |
|
3 | 6 | ### --- Build Depdendencies --- |
4 | | - |
5 | | -FROM python:3.12 as builder |
6 | | -MAINTAINER "Shahar Evron <[email protected]>" |
7 | | - |
8 | | -# Build wheels for uWSGI and all requirements |
9 | | -RUN DEBIAN_FRONTEND=noninteractive apt-get update \ |
10 | | - && apt-get install -y build-essential libpcre3 libpcre3-dev git |
11 | | -RUN pip install -U pip |
12 | | -RUN mkdir /wheels |
13 | | - |
| 7 | +FROM python:3.12 AS builder |
14 | 8 | ARG UWSGI_VERSION=2.0.23 |
15 | | -RUN pip wheel -w /wheels uwsgi==$UWSGI_VERSION |
16 | | - |
17 | | -COPY requirements/main.txt /requirements.txt |
18 | | -RUN pip wheel -w /wheels -r /requirements.txt |
19 | | - |
20 | | -### --- Build Final Image --- |
21 | | - |
22 | | -FROM python:3.12-slim |
23 | | - |
24 | | -RUN DEBIAN_FRONTEND=noninteractive apt-get update \ |
25 | | - && apt-get install -y libpcre3 libxml2 tini git \ |
26 | | - && apt-get clean \ |
27 | | - && apt -y autoremove |
28 | | - |
29 | | -RUN mkdir /app |
30 | | - |
31 | | -# Install dependencies |
32 | | -COPY --from=builder /wheels /wheels |
33 | | -RUN pip install /wheels/*.whl |
34 | | - |
35 | | -# Copy project code |
36 | | -COPY . /app |
37 | | -RUN pip install -e /app |
38 | | - |
39 | | -ARG USER_NAME=giftless |
40 | | -ARG STORAGE_DIR=/lfs-storage |
41 | | -ENV GIFTLESS_TRANSFER_ADAPTERS_basic_options_storage_options_path $STORAGE_DIR |
42 | | - |
43 | | -RUN useradd -d /app $USER_NAME |
44 | | -RUN mkdir $STORAGE_DIR |
45 | | -RUN chown $USER_NAME $STORAGE_DIR |
46 | | - |
47 | | -# Pip-install some common WSGI middleware modules |
| 9 | +# Common WSGI middleware modules to be pip-installed |
48 | 10 | # These are not required in every Giftless installation but are common enough |
49 | 11 | ARG EXTRA_PACKAGES="wsgi_cors_middleware" |
| 12 | +# expose shared ARGs |
| 13 | +ARG WORKDIR |
| 14 | +ARG VENV |
| 15 | + |
| 16 | +# Set WORKDIR (also creates the dir) |
| 17 | +WORKDIR $WORKDIR |
| 18 | + |
| 19 | +# Install packages to build wheels for uWSGI and other requirements |
| 20 | +RUN set -eux ;\ |
| 21 | + export DEBIAN_FRONTEND=noninteractive ;\ |
| 22 | + apt-get update ;\ |
| 23 | + apt-get install -y --no-install-recommends build-essential libpcre3 libpcre3-dev git ;\ |
| 24 | + rm -rf /var/lib/apt/lists/* |
| 25 | + |
| 26 | +# Create virtual env to store dependencies, "activate" it |
| 27 | +RUN python -m venv --upgrade-deps "$VENV" |
| 28 | +ENV VIRTUAL_ENV="$VENV" PATH="$VENV/bin:$PATH" |
| 29 | + |
| 30 | +# Set a couple pip-related settings |
| 31 | +# Wait a bit longer for slow connections |
| 32 | +ENV PIP_TIMEOUT=100 |
| 33 | +# Don't nag about newer pip |
| 34 | +ENV PIP_DISABLE_PIP_VERSION_CHECK=1 |
| 35 | +# Don't cache pip packages |
| 36 | +ENV PIP_NO_CACHE_DIR=1 |
| 37 | +# Require activated virtual environment |
| 38 | +ENV PIP_REQUIRE_VIRTUALENV=1 |
| 39 | +# Eventual python cache files go here (not to be copied) |
| 40 | +ENV PYTHONPYCACHEPREFIX=/tmp/__pycache__ |
| 41 | + |
| 42 | +# Install runtime dependencies |
| 43 | +RUN --mount=target=/build-ctx \ |
| 44 | + pip install -r /build-ctx/requirements/main.txt |
| 45 | +RUN pip install uwsgi==$UWSGI_VERSION |
| 46 | +# Install extra packages into the virtual env |
50 | 47 | RUN pip install ${EXTRA_PACKAGES} |
51 | 48 |
|
52 | | -WORKDIR /app |
| 49 | +# Copy project contents necessary for an editable install |
| 50 | +COPY .git .git/ |
| 51 | +COPY giftless giftless/ |
| 52 | +COPY pyproject.toml . |
| 53 | +# Editable-install the giftless package (add a kind of a project path reference in site-packages) |
| 54 | +# To detect the package version dynamically, setuptools-scm needs the git binary |
| 55 | +RUN pip install -e . |
53 | 56 |
|
54 | | -ENV UWSGI_MODULE "giftless.wsgi_entrypoint" |
| 57 | +### --- Build Final Image --- |
| 58 | +FROM python:3.12-slim AS final |
| 59 | +LABEL org.opencontainers.image.authors= "Shahar Evron <[email protected]>" |
55 | 60 |
|
| 61 | +ARG USER_NAME=giftless |
| 62 | +# Writable path for local LFS storage |
| 63 | +ARG STORAGE_DIR=/lfs-storage |
| 64 | +# Set to true to add a runtime dockerhub deprecation warning |
56 | 65 | ARG IS_DOCKERHUB |
57 | | -# Override default docker entrypoint for dockerhub |
58 | | -RUN --mount=target=/build-ctx set -e ;\ |
59 | | - if [ "$IS_DOCKERHUB" = true ]; then \ |
60 | | - cp /build-ctx/scripts/docker-entrypoint-dockerhub.sh scripts/docker-entrypoint.sh ;\ |
| 66 | +# expose shared ARGs |
| 67 | +ARG WORKDIR |
| 68 | +ARG VENV |
| 69 | + |
| 70 | +# Set WORKDIR (also creates the dir) |
| 71 | +WORKDIR $WORKDIR |
| 72 | + |
| 73 | +# Create a user and set local storage write permissions |
| 74 | +RUN set -eux ;\ |
| 75 | + useradd -d "$WORKDIR" "$USER_NAME" ;\ |
| 76 | + mkdir "$STORAGE_DIR" ;\ |
| 77 | + chown "$USER_NAME" "$STORAGE_DIR" |
| 78 | + |
| 79 | +# Install runtime dependencies |
| 80 | +RUN set -eux ;\ |
| 81 | + export DEBIAN_FRONTEND=noninteractive ;\ |
| 82 | + apt-get update ;\ |
| 83 | + apt-get install -y libpcre3 libxml2 tini ;\ |
| 84 | + rm -rf /var/lib/apt/lists/* |
| 85 | + |
| 86 | +# Use the virtual env with dependencies from builder stage |
| 87 | +COPY --from=builder "$VENV" "$VENV" |
| 88 | +ENV VIRTUAL_ENV="$VENV" PATH="$VENV/bin:$PATH" |
| 89 | +# Copy project source back into the same path referenced by the editable install |
| 90 | +COPY --from=builder "$WORKDIR/giftless" "giftless" |
| 91 | + |
| 92 | +# Copy desired docker-entrypoint |
| 93 | +RUN --mount=target=/build-ctx set -eux ;\ |
| 94 | + target_de=scripts/docker-entrypoint.sh ;\ |
| 95 | + mkdir -p "$(dirname "$target_de")" ;\ |
| 96 | + if [ "${IS_DOCKERHUB:-}" = true ]; then \ |
| 97 | + cp /build-ctx/scripts/docker-entrypoint-dockerhub.sh "$target_de" ;\ |
| 98 | + else \ |
| 99 | + cp /build-ctx/scripts/docker-entrypoint.sh "$target_de" ;\ |
61 | 100 | fi |
62 | 101 |
|
| 102 | +# Set runtime properties |
63 | 103 | USER $USER_NAME |
| 104 | +ENV GIFTLESS_TRANSFER_ADAPTERS_basic_options_storage_options_path="$STORAGE_DIR" |
| 105 | +ENV UWSGI_MODULE="giftless.wsgi_entrypoint" |
64 | 106 |
|
65 | 107 | ENTRYPOINT ["tini", "--", "scripts/docker-entrypoint.sh"] |
66 | 108 | CMD ["uwsgi", "-s", "127.0.0.1:5000", "-M", "-T", "--threads", "2", "-p", "2", \ |
|
0 commit comments