mirror of
https://code.lenaisten.de/Lenaisten/advent22.git
synced 2026-02-25 02:20:17 +00:00
🚧 api: re-scaffolding
- remove legacy "poetry.lock", "main.py" - flesh out launch.json to use only "fastapi-cli" - remove unneeded lines from "settings.json" - rework main "Dockerfile" for "uv" compliance - update ".dockerignore"
This commit is contained in:
parent
67eebecd39
commit
d0a7daf7be
6 changed files with 50 additions and 2017 deletions
|
|
@ -11,14 +11,17 @@
|
|||
**/.dockerignore
|
||||
|
||||
# found in python and JS dirs
|
||||
**/__pycache__
|
||||
**/node_modules
|
||||
**/.pytest_cache
|
||||
**/__pycache__/
|
||||
**/node_modules/
|
||||
**/.pytest_cache/
|
||||
**/.ruff_cache/
|
||||
**/.venv/
|
||||
|
||||
# env files
|
||||
**/.env
|
||||
**/.env.local
|
||||
**/.env.*.local
|
||||
api/api.conf
|
||||
|
||||
# log files
|
||||
**/npm-debug.log*
|
||||
|
|
|
|||
125
Dockerfile
125
Dockerfile
|
|
@ -1,52 +1,6 @@
|
|||
ARG NODE_VERSION=24
|
||||
ARG PYTHON_VERSION=3.14-slim
|
||||
|
||||
#############
|
||||
# build api #
|
||||
#############
|
||||
|
||||
ARG PYTHON_VERSION
|
||||
FROM python:${PYTHON_VERSION} AS build-api
|
||||
|
||||
# env setup
|
||||
WORKDIR /usr/local/src/advent22_api
|
||||
ENV \
|
||||
PATH="/root/.local/bin:${PATH}"
|
||||
|
||||
# install poetry with export plugin
|
||||
RUN set -ex; \
|
||||
\
|
||||
python -m pip --no-cache-dir install --upgrade pip wheel; \
|
||||
\
|
||||
apt-get update; apt-get install --yes --no-install-recommends \
|
||||
curl \
|
||||
; rm -rf /var/lib/apt/lists/*; \
|
||||
\
|
||||
curl -sSL https://install.python-poetry.org | python3 -; \
|
||||
poetry self add poetry-plugin-export;
|
||||
|
||||
# build dependency wheels
|
||||
COPY api/pyproject.toml api/poetry.lock ./
|
||||
RUN set -ex; \
|
||||
\
|
||||
# # buildtime dependencies
|
||||
# apt-get update; apt-get install --yes --no-install-recommends \
|
||||
# build-essential \
|
||||
# ; rm -rf /var/lib/apt/lists/*; \
|
||||
\
|
||||
# generate requirements.txt
|
||||
poetry export \
|
||||
--format requirements.txt \
|
||||
--output requirements.txt; \
|
||||
\
|
||||
python3 -m pip --no-cache-dir wheel \
|
||||
--wheel-dir ./dist \
|
||||
--requirement requirements.txt;
|
||||
|
||||
# build advent22_api wheel
|
||||
COPY api ./
|
||||
RUN poetry build --format wheel --output ./dist
|
||||
|
||||
############
|
||||
# build ui #
|
||||
############
|
||||
|
|
@ -71,59 +25,60 @@ RUN set -ex; \
|
|||
# exclude webpack-bundle-analyzer output
|
||||
rm -f /tmp/advent22_ui/html/report.html;
|
||||
|
||||
######################
|
||||
# python preparation #
|
||||
######################
|
||||
|
||||
ARG PYTHON_VERSION
|
||||
FROM python:${PYTHON_VERSION} AS uvicorn-gunicorn
|
||||
|
||||
# where credit is due ...
|
||||
LABEL maintainer="Sebastián Ramirez <tiangolo@gmail.com>"
|
||||
WORKDIR /usr/local/share/uvicorn-gunicorn
|
||||
|
||||
# install uvicorn-gunicorn
|
||||
COPY ./scripts/mini-tiangolo ./
|
||||
|
||||
RUN set -ex; \
|
||||
chmod +x start.sh; \
|
||||
python3 -m pip --no-cache-dir install gunicorn;
|
||||
|
||||
CMD ["/usr/local/share/uvicorn-gunicorn/start.sh"]
|
||||
|
||||
###########
|
||||
# web app #
|
||||
###########
|
||||
|
||||
FROM uvicorn-gunicorn AS production
|
||||
ARG PYTHON_VERSION
|
||||
FROM python:${PYTHON_VERSION} AS production
|
||||
|
||||
# env setup
|
||||
ENV \
|
||||
PRODUCTION_MODE="true" \
|
||||
PORT="8000" \
|
||||
MODULE_NAME="advent22_api.app"
|
||||
ENV \
|
||||
PATH="/usr/local/share/advent22_api/.venv/bin:$PATH" \
|
||||
UV_COMPILE_BYTECODE=1 \
|
||||
UV_NO_DEV=1 \
|
||||
PRODUCTION_MODE="true"
|
||||
EXPOSE 8000
|
||||
|
||||
WORKDIR /opt/advent22
|
||||
VOLUME [ "/opt/advent22" ]
|
||||
# install advent22_api deps
|
||||
WORKDIR /usr/local/share/advent22_api
|
||||
|
||||
COPY --from=build-api /usr/local/src/advent22_api/dist /usr/local/share/advent22_api.dist
|
||||
RUN set -ex; \
|
||||
# remove example app
|
||||
rm -rf /app; \
|
||||
RUN --mount=from=ghcr.io/astral-sh/uv,source=/uv,target=/bin/uv \
|
||||
--mount=type=cache,target=/root/.cache/uv \
|
||||
--mount=type=bind,source=api/uv.lock,target=uv.lock \
|
||||
--mount=type=bind,source=api/pyproject.toml,target=pyproject.toml \
|
||||
\
|
||||
# # runtime dependencies
|
||||
# apt-get update; apt-get install --yes --no-install-recommends \
|
||||
# ; rm -rf /var/lib/apt/lists/*; \
|
||||
uv sync \
|
||||
--locked \
|
||||
--no-install-project \
|
||||
--no-editable \
|
||||
;
|
||||
|
||||
# install advent22_api
|
||||
COPY api ./
|
||||
RUN --mount=from=ghcr.io/astral-sh/uv,source=/uv,target=/bin/uv \
|
||||
--mount=type=cache,target=/root/.cache/uv \
|
||||
\
|
||||
# install advent22_api wheels
|
||||
python3 -m pip --no-cache-dir install --no-deps /usr/local/share/advent22_api.dist/*.whl; \
|
||||
\
|
||||
# prepare data directory
|
||||
chown nobody:nogroup ./
|
||||
uv sync \
|
||||
--locked \
|
||||
--no-editable \
|
||||
;
|
||||
|
||||
CMD [ \
|
||||
"fastapi", "run", \
|
||||
"--host", "0.0.0.0", \
|
||||
"--port", "8000", \
|
||||
"--entrypoint", "advent22_api.app:app", \
|
||||
"--workers", "$(nproc)" \
|
||||
]
|
||||
|
||||
# add prepared advent22_ui
|
||||
COPY --from=build-ui /tmp/advent22_ui /usr/local/share/advent22_ui
|
||||
|
||||
# prepare data directory
|
||||
WORKDIR /opt/advent22
|
||||
VOLUME [ "/opt/advent22" ]
|
||||
RUN chown -R nobody:nogroup ./
|
||||
|
||||
# run as unprivileged user
|
||||
USER nobody
|
||||
|
|
|
|||
22
api/.vscode/launch.json
vendored
22
api/.vscode/launch.json
vendored
|
|
@ -4,20 +4,6 @@
|
|||
// Weitere Informationen finden Sie unter https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
// {
|
||||
// "name": "Main Module",
|
||||
// "type": "debugpy",
|
||||
// "request": "launch",
|
||||
// "module": "advent22_api.main",
|
||||
// "pythonArgs": [
|
||||
// "-Xfrozen_modules=off",
|
||||
// ],
|
||||
// "env": {
|
||||
// "PYDEVD_DISABLE_FILE_VALIDATION": "1",
|
||||
// "WEBDAV__CACHE_TTL": "30",
|
||||
// },
|
||||
// "justMyCode": true,
|
||||
// },
|
||||
{
|
||||
"name": "FastAPI CLI (dev)",
|
||||
"type": "debugpy",
|
||||
|
|
@ -25,10 +11,10 @@
|
|||
"module": "fastapi",
|
||||
"args": [
|
||||
"dev",
|
||||
"--entrypoint",
|
||||
"advent22_api.app:app",
|
||||
"--reload-dir",
|
||||
"${workspaceFolder}/advent22_api",
|
||||
"--host", "0.0.0.0",
|
||||
"--port", "8000",
|
||||
"--entrypoint", "advent22_api.app:app",
|
||||
"--reload-dir", "${workspaceFolder}/advent22_api",
|
||||
],
|
||||
"env": {
|
||||
"WEBDAV__CACHE_TTL": "30",
|
||||
|
|
|
|||
13
api/.vscode/settings.json
vendored
13
api/.vscode/settings.json
vendored
|
|
@ -10,21 +10,8 @@
|
|||
},
|
||||
},
|
||||
|
||||
// "python.analysis.autoImportCompletions": true,
|
||||
// "python.analysis.importFormat": "relative",
|
||||
// "python.analysis.fixAll": [
|
||||
// "source.convertImportFormat",
|
||||
// "source.unusedImports",
|
||||
// ],
|
||||
// "python.analysis.typeCheckingMode": "basic",
|
||||
// "python.analysis.diagnosticMode": "workspace",
|
||||
|
||||
"python.testing.unittestEnabled": false,
|
||||
"python.testing.pytestEnabled": true,
|
||||
"python.testing.pytestArgs": [
|
||||
"--import-mode=importlib",
|
||||
"test",
|
||||
],
|
||||
|
||||
"ty.diagnosticMode": "workspace",
|
||||
"ruff.nativeServer": "on",
|
||||
|
|
|
|||
|
|
@ -1,22 +0,0 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import uvicorn
|
||||
|
||||
from .core.settings import SETTINGS
|
||||
|
||||
|
||||
def main() -> None:
|
||||
"""
|
||||
If the `main` script is run, `uvicorn` is used to run the app.
|
||||
"""
|
||||
|
||||
uvicorn.run(
|
||||
app="advent22_api.app:app",
|
||||
host="0.0.0.0",
|
||||
port=8000,
|
||||
reload=not SETTINGS.production_mode,
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
1876
api/poetry.lock
generated
1876
api/poetry.lock
generated
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue