Compare commits
No commits in common. "eb3985d6a9907f65ac1ff2e189c7430784903cc3" and "67eebecd39b5b4ae44c914124ac41472a3ca46d6" have entirely different histories.
eb3985d6a9
...
67eebecd39
7 changed files with 2019 additions and 52 deletions
|
|
@ -11,17 +11,14 @@
|
||||||
**/.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,6 +1,52 @@
|
||||||
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 #
|
||||||
############
|
############
|
||||||
|
|
@ -25,60 +71,59 @@ 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 #
|
||||||
###########
|
###########
|
||||||
|
|
||||||
ARG PYTHON_VERSION
|
FROM uvicorn-gunicorn AS production
|
||||||
FROM python:${PYTHON_VERSION} AS production
|
|
||||||
|
|
||||||
# env setup
|
# env setup
|
||||||
ENV \
|
ENV \
|
||||||
PATH="/usr/local/share/advent22_api/.venv/bin:$PATH" \
|
PRODUCTION_MODE="true" \
|
||||||
UV_COMPILE_BYTECODE=1 \
|
PORT="8000" \
|
||||||
UV_NO_DEV=1 \
|
MODULE_NAME="advent22_api.app"
|
||||||
PRODUCTION_MODE="true"
|
|
||||||
EXPOSE 8000
|
EXPOSE 8000
|
||||||
|
|
||||||
# install advent22_api deps
|
WORKDIR /opt/advent22
|
||||||
WORKDIR /usr/local/share/advent22_api
|
VOLUME [ "/opt/advent22" ]
|
||||||
|
|
||||||
RUN --mount=from=ghcr.io/astral-sh/uv,source=/uv,target=/bin/uv \
|
COPY --from=build-api /usr/local/src/advent22_api/dist /usr/local/share/advent22_api.dist
|
||||||
--mount=type=cache,target=/root/.cache/uv \
|
RUN set -ex; \
|
||||||
--mount=type=bind,source=api/uv.lock,target=uv.lock \
|
# remove example app
|
||||||
--mount=type=bind,source=api/pyproject.toml,target=pyproject.toml \
|
rm -rf /app; \
|
||||||
\
|
\
|
||||||
uv sync \
|
# # runtime dependencies
|
||||||
--locked \
|
# apt-get update; apt-get install --yes --no-install-recommends \
|
||||||
--no-install-project \
|
# ; rm -rf /var/lib/apt/lists/*; \
|
||||||
--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 \
|
|
||||||
\
|
\
|
||||||
uv sync \
|
# install advent22_api wheels
|
||||||
--locked \
|
python3 -m pip --no-cache-dir install --no-deps /usr/local/share/advent22_api.dist/*.whl; \
|
||||||
--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
|
||||||
|
|
|
||||||
|
|
@ -46,10 +46,10 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
// Use 'postCreateCommand' to run commands after the container is created.
|
// Use 'postCreateCommand' to run commands after the container is created.
|
||||||
"postCreateCommand": "uv tool install uv-upx",
|
// "postCreateCommand": "sudo /usr/local/py-utils/bin/poetry self add poetry-plugin-up",
|
||||||
|
|
||||||
// Use 'postStartCommand' to run commands after the container is started.
|
// Use 'postStartCommand' to run commands after the container is started.
|
||||||
"postStartCommand": "uv tool upgrade uv-upx && uv sync"
|
"postStartCommand": "uv sync"
|
||||||
|
|
||||||
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
||||||
// "forwardPorts": [],
|
// "forwardPorts": [],
|
||||||
|
|
|
||||||
22
api/.vscode/launch.json
vendored
22
api/.vscode/launch.json
vendored
|
|
@ -4,6 +4,20 @@
|
||||||
// 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",
|
||||||
|
|
@ -11,10 +25,10 @@
|
||||||
"module": "fastapi",
|
"module": "fastapi",
|
||||||
"args": [
|
"args": [
|
||||||
"dev",
|
"dev",
|
||||||
"--host", "0.0.0.0",
|
"--entrypoint",
|
||||||
"--port", "8000",
|
"advent22_api.app:app",
|
||||||
"--entrypoint", "advent22_api.app:app",
|
"--reload-dir",
|
||||||
"--reload-dir", "${workspaceFolder}/advent22_api",
|
"${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,8 +10,21 @@
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// "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",
|
||||||
|
|
|
||||||
22
api/advent22_api/main.py
Normal file
22
api/advent22_api/main.py
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
#!/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
Normal file
1876
api/poetry.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue