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
|
**/.dockerignore
|
||||||
|
|
||||||
# found in python and JS dirs
|
# found in python and JS dirs
|
||||||
**/__pycache__
|
**/__pycache__/
|
||||||
**/node_modules
|
**/node_modules/
|
||||||
**/.pytest_cache
|
**/.pytest_cache/
|
||||||
|
**/.ruff_cache/
|
||||||
|
**/.venv/
|
||||||
|
|
||||||
# env files
|
# env files
|
||||||
**/.env
|
**/.env
|
||||||
**/.env.local
|
**/.env.local
|
||||||
**/.env.*.local
|
**/.env.*.local
|
||||||
|
api/api.conf
|
||||||
|
|
||||||
# log files
|
# log files
|
||||||
**/npm-debug.log*
|
**/npm-debug.log*
|
||||||
|
|
|
||||||
123
Dockerfile
123
Dockerfile
|
|
@ -1,52 +1,6 @@
|
||||||
ARG NODE_VERSION=24
|
ARG NODE_VERSION=24
|
||||||
ARG PYTHON_VERSION=3.14-slim
|
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 #
|
# build ui #
|
||||||
############
|
############
|
||||||
|
|
@ -71,59 +25,60 @@ RUN set -ex; \
|
||||||
# exclude webpack-bundle-analyzer output
|
# exclude webpack-bundle-analyzer output
|
||||||
rm -f /tmp/advent22_ui/html/report.html;
|
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 #
|
# web app #
|
||||||
###########
|
###########
|
||||||
|
|
||||||
FROM uvicorn-gunicorn AS production
|
ARG PYTHON_VERSION
|
||||||
|
FROM python:${PYTHON_VERSION} AS production
|
||||||
|
|
||||||
# env setup
|
# env setup
|
||||||
ENV \
|
ENV \
|
||||||
PRODUCTION_MODE="true" \
|
PATH="/usr/local/share/advent22_api/.venv/bin:$PATH" \
|
||||||
PORT="8000" \
|
UV_COMPILE_BYTECODE=1 \
|
||||||
MODULE_NAME="advent22_api.app"
|
UV_NO_DEV=1 \
|
||||||
|
PRODUCTION_MODE="true"
|
||||||
EXPOSE 8000
|
EXPOSE 8000
|
||||||
|
|
||||||
WORKDIR /opt/advent22
|
# install advent22_api deps
|
||||||
VOLUME [ "/opt/advent22" ]
|
WORKDIR /usr/local/share/advent22_api
|
||||||
|
|
||||||
COPY --from=build-api /usr/local/src/advent22_api/dist /usr/local/share/advent22_api.dist
|
RUN --mount=from=ghcr.io/astral-sh/uv,source=/uv,target=/bin/uv \
|
||||||
RUN set -ex; \
|
--mount=type=cache,target=/root/.cache/uv \
|
||||||
# remove example app
|
--mount=type=bind,source=api/uv.lock,target=uv.lock \
|
||||||
rm -rf /app; \
|
--mount=type=bind,source=api/pyproject.toml,target=pyproject.toml \
|
||||||
\
|
\
|
||||||
# # runtime dependencies
|
uv sync \
|
||||||
# apt-get update; apt-get install --yes --no-install-recommends \
|
--locked \
|
||||||
# ; rm -rf /var/lib/apt/lists/*; \
|
--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
|
uv sync \
|
||||||
python3 -m pip --no-cache-dir install --no-deps /usr/local/share/advent22_api.dist/*.whl; \
|
--locked \
|
||||||
\
|
--no-editable \
|
||||||
# prepare data directory
|
;
|
||||||
chown nobody:nogroup ./
|
|
||||||
|
CMD [ \
|
||||||
|
"fastapi", "run", \
|
||||||
|
"--host", "0.0.0.0", \
|
||||||
|
"--port", "8000", \
|
||||||
|
"--entrypoint", "advent22_api.app:app", \
|
||||||
|
"--workers", "$(nproc)" \
|
||||||
|
]
|
||||||
|
|
||||||
# add prepared advent22_ui
|
# add prepared advent22_ui
|
||||||
COPY --from=build-ui /tmp/advent22_ui /usr/local/share/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
|
# run as unprivileged user
|
||||||
USER nobody
|
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
|
// Weitere Informationen finden Sie unter https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
"version": "0.2.0",
|
"version": "0.2.0",
|
||||||
"configurations": [
|
"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)",
|
"name": "FastAPI CLI (dev)",
|
||||||
"type": "debugpy",
|
"type": "debugpy",
|
||||||
|
|
@ -25,10 +11,10 @@
|
||||||
"module": "fastapi",
|
"module": "fastapi",
|
||||||
"args": [
|
"args": [
|
||||||
"dev",
|
"dev",
|
||||||
"--entrypoint",
|
"--host", "0.0.0.0",
|
||||||
"advent22_api.app:app",
|
"--port", "8000",
|
||||||
"--reload-dir",
|
"--entrypoint", "advent22_api.app:app",
|
||||||
"${workspaceFolder}/advent22_api",
|
"--reload-dir", "${workspaceFolder}/advent22_api",
|
||||||
],
|
],
|
||||||
"env": {
|
"env": {
|
||||||
"WEBDAV__CACHE_TTL": "30",
|
"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.unittestEnabled": false,
|
||||||
"python.testing.pytestEnabled": true,
|
"python.testing.pytestEnabled": true,
|
||||||
"python.testing.pytestArgs": [
|
|
||||||
"--import-mode=importlib",
|
|
||||||
"test",
|
|
||||||
],
|
|
||||||
|
|
||||||
"ty.diagnosticMode": "workspace",
|
"ty.diagnosticMode": "workspace",
|
||||||
"ruff.nativeServer": "on",
|
"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