Skip to content
This repository was archived by the owner on Jan 20, 2026. It is now read-only.

Commit ddbd063

Browse files
Update using UV + FastApi (#5)
* Update using UV + FastApi * more changes --------- Co-authored-by: unknown <rulrnovistky@gmail.com>
1 parent 6f3047d commit ddbd063

20 files changed

+910
-135
lines changed

.envrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake

.github/workflows/CI.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ jobs:
1212
steps:
1313
- uses: actions/checkout@v3
1414
- uses: actions/setup-python@v3
15-
- uses: pre-commit/action@v3.0.0
15+
# - uses: pre-commit/action@v3.0.0

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,7 @@ cython_debug/
158158
# and can be added to the global gitignore or merged into this file. For a more nuclear
159159
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160160
#.idea/
161+
162+
.direnv
163+
.venv
164+
result.pdf

.markdownlint.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

.pre-commit-config.yaml

Lines changed: 0 additions & 15 deletions
This file was deleted.

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.12

Dockerfile

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,38 @@
1-
FROM python:3.11-buster
2-
RUN apt update
3-
RUN apt install cargo -y
4-
RUN pip install --upgrade pip
5-
# RUN groupadd -r typstuser && useradd -rm -g typstuser typstuser
6-
# USER typstuser
1+
# An example of using standalone Python builds with multistage images.
2+
3+
# First, build the application in the `/app` directory
4+
FROM ghcr.io/astral-sh/uv:bookworm-slim AS builder
5+
ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy
6+
7+
# Configure the Python directory so it is consistent
8+
ENV UV_PYTHON_INSTALL_DIR=/python
9+
10+
# Only use the managed Python version
11+
ENV UV_PYTHON_PREFERENCE=only-managed
12+
13+
# Install Python before the project for caching
14+
RUN uv python install 3.12
15+
716
WORKDIR /app
8-
COPY ./typst-http-api/requirements.txt requirements.txt
9-
RUN pip install -r requirements.txt
10-
COPY ./typst-http-api .
11-
# equivalent to 'from hello import app'
12-
RUN chmod +x gunicorn.sh
13-
CMD ["sh", "gunicorn.sh"]
14-
#Expose port 8000 of the container to the outside
15-
EXPOSE 8000
17+
RUN --mount=type=cache,target=/root/.cache/uv \
18+
--mount=type=bind,source=uv.lock,target=uv.lock \
19+
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
20+
uv sync --frozen --no-install-project --no-dev
21+
ADD . /app
22+
RUN --mount=type=cache,target=/root/.cache/uv \
23+
uv sync --frozen --no-dev
24+
25+
# Then, use a final image without uv
26+
FROM debian:bookworm-slim
27+
28+
# Copy the Python version
29+
COPY --from=builder --chown=python:python /python /python
30+
31+
# Copy the application from the builder
32+
COPY --from=builder --chown=app:app /app /app
33+
34+
# Place executables in the environment at the front of the path
35+
ENV PATH="/app/.venv/bin:$PATH"
36+
WORKDIR /app
37+
# Run the FastAPI application by default
38+
CMD ["uvicorn", "src:app"]

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
run:
2+
uv run fastapi dev typst-http-api/app.py

flake.lock

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
description = "";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/master";
6+
};
7+
8+
outputs = {
9+
self,
10+
nixpkgs,
11+
}: let
12+
forAllSystems = function:
13+
nixpkgs.lib.genAttrs [
14+
"x86_64-darwin"
15+
"x86_64-linux"
16+
"aarch64-darwin"
17+
"aarch64-linux"
18+
] (system: function nixpkgs.legacyPackages.${system});
19+
in {
20+
devShells = forAllSystems (pkgs: {
21+
default = pkgs.mkShell {
22+
# nativeBuildInputs is usually what you want -- tools you need to run
23+
nativeBuildInputs = with pkgs; [
24+
gnumake
25+
26+
uv
27+
python3
28+
ruff
29+
pre-commit
30+
];
31+
};
32+
});
33+
};
34+
}

0 commit comments

Comments
 (0)