Skip to content

Commit 8498963

Browse files
committed
fix: dockerfile and documentation
1 parent e643b1c commit 8498963

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+601
-702
lines changed

.env.docker.example

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
SECRET_KEY='secret-key'
33
LITESTAR_DEBUG=true
44
LITESTAR_HOST=0.0.0.0
5-
LITESTAR_PORT=8000
5+
LITESTAR_PORT=8080
66
APP_URL=http://localhost:${LITESTAR_PORT}
77

8-
LOG_LEVEL=10
8+
LOG_LEVEL=20
99
# Database
10-
DATABASE_ECHO=true
11-
DATABASE_ECHO_POOL=true
10+
DATABASE_ECHO=false
11+
DATABASE_ECHO_POOL=false
1212
DATABASE_POOL_DISABLE=false
1313
DATABASE_POOL_MAX_OVERFLOW=5
1414
DATABASE_POOL_SIZE=5
@@ -26,5 +26,5 @@ SAQ_CONCURRENCY=1
2626
VITE_HOST=localhost
2727
VITE_PORT=3006
2828
VITE_HOT_RELOAD=True
29-
VITE_DEV_MODE=True
30-
ALLOWED_CORS_ORIGINS=["localhost:3006","localhost:8000"]
29+
VITE_DEV_MODE=False
30+
ALLOWED_CORS_ORIGINS=["localhost:3006","localhost:8080","localhost:8000"]

deploy/docker/dev/Dockerfile

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ARG PYTHON_BUILDER_IMAGE=3.11-slim-bookworm
1+
ARG PYTHON_BUILDER_IMAGE=3.12-slim-bookworm
22

33
## ---------------------------------------------------------------------------------- ##
44
## ------------------------- Python base -------------------------------------------- ##
@@ -53,7 +53,6 @@ COPY tools ./tools/
5353
COPY public ./public/
5454
COPY resources ./resources/
5555
RUN python -m venv --copies /workspace/app/.venv \
56-
&& /workspace/app/.venv/bin/pip install cython uv nodeenv \
5756
&& uv sync ${UV_INSTALL_ARGS} \
5857
&& uvx nodeenv .venv --force --quiet \
5958
&& NODE_OPTIONS="--no-deprecation --disable-warning=ExperimentalWarning" npm install --ignore-scripts --no-fund
@@ -67,10 +66,14 @@ COPY src ./src/
6766
FROM build-base AS dev-image
6867
ARG ENV_SECRETS="runtime-secrets"
6968
ARG LITESTAR_APP="app.asgi:create_app"
69+
ARG VITE_USE_SERVER_LIFESPAN="false"
70+
ARG SAQ_USE_SERVER_LIFESPAN="false"
7071
## --------------------------- standardize execution env ----------------------------- ##
7172
ENV PATH="/workspace/app/.venv/bin:$PATH" \
7273
VIRTUAL_ENV="/workspace/app/.venv" \
7374
ENV_SECRETS="${ENV_SECRETS}" \
75+
VITE_USE_SERVER_LIFESPAN="${VITE_USE_SERVER_LIFESPAN}" \
76+
SAQ_USE_SERVER_LIFESPAN="${SAQ_USE_SERVER_LIFESPAN}" \
7477
PIP_DEFAULT_TIMEOUT=100 \
7578
PIP_DISABLE_PIP_VERSION_CHECK=1 \
7679
PIP_NO_CACHE_DIR=1 \

deploy/docker/run/Dockerfile

+68-42
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,115 @@
1-
ARG PYTHON_BUILDER_IMAGE=3.11-slim-bookworm
21

2+
ARG BUILDER_IMAGE=python:3.12-slim-bookworm
33
## ---------------------------------------------------------------------------------- ##
44
## ------------------------- Python base -------------------------------------------- ##
55
## ---------------------------------------------------------------------------------- ##
6-
FROM python:${PYTHON_BUILDER_IMAGE} as python-base
7-
ENV PIP_DEFAULT_TIMEOUT=100 \
8-
PIP_DISABLE_PIP_VERSION_CHECK=1 \
9-
PIP_NO_CACHE_DIR=1 \
10-
PIP_ROOT_USER_ACTION=ignore \
11-
PYTHONDONTWRITEBYTECODE=1 \
12-
PYTHONUNBUFFERED=1 \
13-
PYTHONFAULTHANDLER=1 \
14-
PYTHONHASHSEED=random \
15-
LANG=C.UTF-8 \
16-
LC_ALL=C.UTF-8
6+
FROM ${BUILDER_IMAGE} AS python-base
177
RUN apt-get update \
188
&& apt-get upgrade -y \
19-
&& apt-get install -y --no-install-recommends git tini \
9+
&& apt-get install -y --no-install-recommends tini \
2010
&& apt-get autoremove -y \
2111
&& apt-get clean -y \
2212
&& rm -rf /root/.cache \
2313
&& rm -rf /var/apt/lists/* \
2414
&& rm -rf /var/cache/apt/* \
25-
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false\
26-
&& mkdir -p /workspace/app \
27-
&& pip install --quiet -U pip wheel setuptools virtualenv
28-
15+
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
16+
&& mkdir -p /workspace/app
17+
# Install uv
18+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
2919
## ---------------------------------------------------------------------------------- ##
3020
## ------------------------- Python build base -------------------------------------- ##
3121
## ---------------------------------------------------------------------------------- ##
32-
FROM python-base AS build-base
33-
ARG UV_INSTALL_ARGS=""
34-
ENV UV_INSTALL_ARGS="${UV_INSTALL_ARGS}" \
35-
GRPC_PYTHON_BUILD_WITH_CYTHON=1 \
36-
PATH="/workspace/app/.venv/bin:/usr/local/bin:$PATH"
22+
FROM python-base AS builder
23+
ARG UV_INSTALL_ARGS="--no-dev"
24+
ENV GRPC_PYTHON_BUILD_WITH_CYTHON=1 \
25+
UV_LINK_MODE=copy \
26+
UV_NO_CACHE=1 \
27+
UV_COMPILE_BYTECODE=1 \
28+
UV_INSTALL_ARGS="${UV_INSTALL_ARGS}" \
29+
UV_SYSTEM_PYTHON=1 \
30+
PATH="/workspace/app/.venv/bin:/usr/local/bin:/opt/nodeenv/bin:$PATH" \
31+
PYTHONDONTWRITEBYTECODE=1 \
32+
PYTHONUNBUFFERED=1 \
33+
PYTHONFAULTHANDLER=1 \
34+
PYTHONHASHSEED=random \
35+
LANG=C.UTF-8 \
36+
LC_ALL=C.UTF-8
3737
## -------------------------- add build packages ----------------------------------- ##
38-
RUN apt-get install -y --no-install-recommends build-essential curl \
38+
RUN apt-get install -y --no-install-recommends git build-essential curl \
3939
&& apt-get autoremove -y \
40-
&& apt-get clean make -y \
40+
&& apt-get clean -y \
4141
&& rm -rf /root/.cache \
4242
&& rm -rf /var/apt/lists/* \
4343
&& rm -rf /var/cache/apt/* \
44-
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false
44+
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
45+
&& mkdir -p /cloudsql
46+
4547

4648
## -------------------------- install application ----------------------------------- ##
4749
WORKDIR /workspace/app
4850
COPY pyproject.toml uv.lock README.md .pre-commit-config.yaml LICENSE Makefile \
49-
package.json package-lock.json vite.config.ts tsconfig.json tsconfig.node.json \
51+
package.json package-lock.json vite.config.ts tsconfig.json \
5052
tailwind.config.cjs postcss.config.cjs components.json \
5153
./
5254
COPY tools ./tools/
55+
RUN uvx nodeenv --quiet /opt/nodeenv/
56+
RUN NODE_OPTIONS="--no-deprecation --disable-warning=ExperimentalWarning" npm install --ignore-scripts --no-fund
57+
RUN uv venv \
58+
&& uv sync ${UV_INSTALL_ARGS} --frozen --no-install-project --no-editable \
59+
&& uv export ${UV_INSTALL_ARGS} --frozen --no-hashes --output-file=requirements.txt
60+
5361
COPY public ./public/
5462
COPY resources ./resources/
55-
RUN python -m venv --copies /workspace/app/.venv \
56-
&& /workspace/app/.venv/bin/pip install --quiet uv nodeenv cython \
57-
&& make install ${UV_INSTALL_ARGS} \
58-
&& uv export ${UV_INSTALL_ARGS} --no-hashes --no-dev --output-file=requirements.txt
63+
RUN uv run pip install --quiet cython \
64+
&& uv sync ${UV_INSTALL_ARGS} --frozen --no-install-project --no-editable \
65+
&& uv export ${UV_INSTALL_ARGS} --frozen --no-hashes --output-file=requirements.txt
5966
COPY src ./src/
60-
RUN make build
67+
68+
# build the frontend and sync the project
69+
RUN uv run tools/manage-assets.py --build-assets \
70+
&& uv sync ${UV_INSTALL_ARGS} --frozen --no-editable \
71+
&& uv build
6172

6273

6374
## ---------------------------------------------------------------------------------- ##
64-
## -------------------------------- runtime build ----------------------------------- ##
75+
## -------------------------------- Run Image ----------------------------------- ##
6576
## ---------------------------------------------------------------------------------- ##
6677
## ------------------------- use base image ---------------------------------------- ##
6778

68-
FROM python-base as run-image
79+
FROM python-base AS runner
6980
ARG ENV_SECRETS="runtime-secrets"
81+
ARG VITE_USE_SERVER_LIFESPAN="false"
82+
ARG SAQ_USE_SERVER_LIFESPAN="false"
7083
ARG LITESTAR_APP="app.asgi:create_app"
7184
ENV ENV_SECRETS="${ENV_SECRETS}" \
85+
PATH="/workspace/app/.venv/bin:/usr/local/bin:$PATH" \
86+
UV_LINK_MODE=copy \
87+
UV_NO_CACHE=1 \
88+
UV_COMPILE_BYTECODE=1 \
89+
UV_SYSTEM_PYTHON=1 \
90+
UV_INSTALL_ARGS="${UV_INSTALL_ARGS}" \
91+
VITE_USE_SERVER_LIFESPAN="${VITE_USE_SERVER_LIFESPAN}" \
92+
SAQ_USE_SERVER_LIFESPAN="${SAQ_USE_SERVER_LIFESPAN}" \
93+
PYTHONDONTWRITEBYTECODE=1 \
94+
PYTHONUNBUFFERED=1 \
95+
PYTHONFAULTHANDLER=1 \
96+
PYTHONHASHSEED=random \
97+
LANG=C.UTF-8 \
98+
LC_ALL=C.UTF-8 \
7299
LITESTAR_APP="${LITESTAR_APP}"
73-
100+
## -------------------------- install built application -------------------------------- ##
74101
RUN addgroup --system --gid 65532 nonroot \
75102
&& adduser --no-create-home --system --uid 65532 nonroot \
76103
&& chown -R nonroot:nonroot /workspace
77-
## -------------------------- install application ----------------------------------- ##
78-
COPY --from=build-base --chown=65532:65532 /workspace/app/requirements.txt /tmp/requirements.txt
79-
COPY --from=build-base --chown=65532:65532 /workspace/app/dist /tmp/
104+
COPY --from=builder --chown=65532:65532 /cloudsql /cloudsql
105+
COPY --from=builder --chown=65532:65532 /workspace/app/dist /tmp/
80106
WORKDIR /workspace/app
81-
RUN pip install --quiet --disable-pip-version-check --no-deps --requirement=/tmp/requirements.txt
82-
RUN pip install --quiet --disable-pip-version-check --no-deps /tmp/*.whl
83-
107+
RUN uv pip ${UV_INSTALL_ARGS} install --quiet --disable-pip-version-check /tmp/*.whl \
108+
&& rm -Rf /tmp/* \
109+
&& chown -R nonroot:nonroot /workspace/app
84110
USER nonroot
85111
STOPSIGNAL SIGINT
86-
EXPOSE 8000
112+
EXPOSE 8080
87113
ENTRYPOINT ["tini","--" ]
88-
CMD [ "litestar","run","--host","0.0.0.0"]
114+
CMD [ "app", "run", "--port","8080", "--host", "0.0.0.0"]
89115
VOLUME /workspace/app

docker-compose.override.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ services:
2424
context: .
2525
dockerfile: deploy/docker/dev/Dockerfile
2626
ports:
27-
- "8000:8000"
27+
- "8080:8080"
2828
- "3006:3006"
2929
tty: true
3030
environment:

docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ services:
5858
cache:
5959
condition: service_healthy
6060
ports:
61-
- "8000:8000"
61+
- "8080:8080"
6262
environment:
6363
VITE_USE_SERVER_LIFESPAN: "false" # true if ssr or separate service
6464
SAQ_USE_SERVER_LIFESPAN: "false"

docs/api/cli.rst

+7
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,10 @@ Database CLI
1717
.. click:: advanced_alchemy.extensions.litestar.cli:database_group
1818
:prog: app database
1919
:nested: full
20+
21+
User management CLI
22+
^^^^^^^^^^^^^^^^^^^
23+
24+
.. click:: app.cli.commands:user_management_group
25+
:prog: app user
26+
:nested: full

docs/api/config.rst

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
========
2+
config
3+
========
4+
5+
Documentation for the config module.
6+
7+
.. automodule:: app.config
8+
:members:

docs/api/db.rst

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
========
2+
db
3+
========
4+
5+
Documentation for the db module.
6+
7+
.. automodule:: app.db
8+
:members:

docs/api/domain/accounts/controllers/access.rst

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ Controllers for the access routes for the accounts domain.
66

77
.. automodule:: app.domain.accounts.controllers.access
88
:members:
9+
:no-index:

docs/api/domain/accounts/controllers/accounts.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ accounts
44

55
Controllers for the accounts routes for the accounts domain.
66

7-
.. automodule:: app.domain.accounts.controllers.accounts
8-
:members:
7+
.. automodule:: app.domain.accounts.controllers
8+
:members: UserController UserRoleController RoleController
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
===========
2+
controllers
3+
===========
4+
5+
Controllers for the user accounts.
6+
7+
.. automodule:: app.domain.accounts.controllers.users
8+
:members:
9+
:no-index:

docs/api/domain/accounts/dependencies.rst

-8
This file was deleted.

docs/api/domain/accounts/deps.rst

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
========
2+
deps
3+
========
4+
5+
Dependencies for the accounts domain.
6+
7+
.. automodule:: app.domain.accounts.deps
8+
:members:

docs/api/domain/accounts/dtos.rst

-8
This file was deleted.

docs/api/domain/accounts/models.rst

-8
This file was deleted.

docs/api/domain/analytics/controllers.rst

-8
This file was deleted.

docs/api/domain/analytics/dependencies.rst

-8
This file was deleted.

docs/api/domain/analytics/dtos.rst

-8
This file was deleted.

docs/api/domain/analytics/index.rst

-11
This file was deleted.

docs/api/domain/analytics/queries.rst

-8
This file was deleted.

docs/api/domain/index.rst

+3-6
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@ domain
88
:caption: Domain API Reference
99
:hidden:
1010

11-
urls
12-
security
13-
system/index
14-
web/index
11+
accounts/index
1512
teams/index
1613
tags/index
17-
analytics/index
18-
accounts/index
14+
web/index
15+
system/index

docs/api/domain/security.rst

-8
This file was deleted.

docs/api/domain/system/dtos.rst

-8
This file was deleted.

0 commit comments

Comments
 (0)