|
| 1 | + |
| 2 | +# TEKST-WEB BUILDER IMAGE |
| 3 | + |
| 4 | +FROM node:22.15.0-alpine3.20 AS web-builder |
| 5 | +WORKDIR /tekst |
| 6 | +COPY Tekst-Web/ . |
| 7 | +RUN npm install && npm run build-only -- --base=./ |
| 8 | + |
| 9 | + |
| 10 | +# PYTHON ALPINE BASE IMAGE |
| 11 | + |
| 12 | +FROM python:3.13-alpine3.21 AS py-base |
| 13 | +ENV PYTHONFAULTHANDLER=1 \ |
| 14 | + PYTHONHASHSEED=random \ |
| 15 | + PYTHONUNBUFFERED=1 \ |
| 16 | + PYTHONDONTWRITEBYTECODE=1 \ |
| 17 | + PIP_DEFAULT_TIMEOUT=100 \ |
| 18 | + PIP_DISABLE_PIP_VERSION_CHECK=1 \ |
| 19 | + PIP_NO_CACHE_DIR=1 \ |
| 20 | + PIP_ROOT_USER_ACTION=ignore |
| 21 | + |
| 22 | + |
| 23 | +# TEKST-API BUILDER IMAGE |
| 24 | + |
| 25 | +FROM py-base AS api-builder |
| 26 | +WORKDIR "/tekst" |
| 27 | + |
| 28 | +COPY --from=ghcr.io/astral-sh/uv:0.6.16 /uv /uvx /bin/ |
| 29 | +COPY Tekst-API/tekst/ ./tekst/ |
| 30 | +COPY Tekst-API/uv.lock* \ |
| 31 | + Tekst-API/pyproject.toml \ |
| 32 | + Tekst-API/README.md \ |
| 33 | + Tekst-API/LICENSE \ |
| 34 | + ./ |
| 35 | + |
| 36 | +RUN uv run pip install --upgrade \ |
| 37 | + pip \ |
| 38 | + setuptools \ |
| 39 | + wheel |
| 40 | + |
| 41 | +RUN uv export \ |
| 42 | + --locked \ |
| 43 | + --no-group dev \ |
| 44 | + --no-hashes \ |
| 45 | + --no-progress \ |
| 46 | + --format requirements-txt \ |
| 47 | + --output-file requirements.txt |
| 48 | + |
| 49 | +RUN uv run pip wheel \ |
| 50 | + --requirement requirements.txt \ |
| 51 | + --wheel-dir deps |
| 52 | + |
| 53 | +RUN uv build --wheel |
| 54 | + |
| 55 | + |
| 56 | +# FINAL PRODUCTION IMAGE |
| 57 | + |
| 58 | +FROM py-base AS prod |
| 59 | +ENV FASTAPI_ENV=production |
| 60 | +WORKDIR "/tekst" |
| 61 | + |
| 62 | +RUN set -x && \ |
| 63 | + addgroup -S tekst && \ |
| 64 | + adduser -S tekst -G tekst |
| 65 | + |
| 66 | +RUN apk update && \ |
| 67 | + apk add --no-cache curl caddy |
| 68 | + |
| 69 | +HEALTHCHECK \ |
| 70 | + --interval=2m \ |
| 71 | + --timeout=5s \ |
| 72 | + --retries=3 \ |
| 73 | + --start-period=30s \ |
| 74 | + CMD curl http://localhost:8000/status || exit 1 |
| 75 | + |
| 76 | +COPY --from=api-builder /tekst/deps/ api/deps/ |
| 77 | +COPY --from=api-builder /tekst/dist/ api/dist/ |
| 78 | +COPY --from=web-builder /tekst/dist/ /var/www/html/ |
| 79 | + |
| 80 | +RUN chown -R tekst:tekst /var/www/html/ |
| 81 | + |
| 82 | +RUN python3 -m pip install \ |
| 83 | + --no-index \ |
| 84 | + --find-links api/deps/ \ |
| 85 | + api/dist/*.whl && \ |
| 86 | + rm -rf api |
| 87 | + |
| 88 | +RUN python3 -m pip install \ |
| 89 | + "uvicorn[standard]==0.32.0" \ |
| 90 | + "gunicorn==23.0.0" |
| 91 | + |
| 92 | +COPY docker/caddy/Caddyfile /etc/caddy/Caddyfile |
| 93 | +COPY docker/gunicorn/gunicorn_conf.py /etc/gunicorn/ |
| 94 | +COPY docker/entrypoint.sh /usr/local/bin/ |
| 95 | + |
| 96 | +VOLUME /var/www/tekst/static/ |
| 97 | +EXPOSE 80 |
| 98 | +USER tekst |
| 99 | + |
| 100 | +ENTRYPOINT ["entrypoint.sh"] |
| 101 | +CMD ["gunicorn", "tekst.app:app", "--config", "/etc/gunicorn/gunicorn_conf.py"] |
0 commit comments