Skip to content

Commit 5d6ff61

Browse files
Optimize Dockerfile and mise tasks (#91)
Co-authored-by: Amr Abed <3361565+amrabed@users.noreply.github.com>
1 parent 7079d94 commit 5d6ff61

4 files changed

Lines changed: 30 additions & 31 deletions

File tree

‎.pre-commit-config.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ repos:
1515
args: [--branch, main]
1616

1717
- repo: https://github.com/astral-sh/ruff-pre-commit
18-
rev: v0.15.12
18+
rev: v0.15.14
1919
hooks:
2020
- id: ruff
2121
args: [--fix]

‎Dockerfile‎

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
1-
FROM python:3.14-alpine
1+
# Stage 1: Build stage
2+
FROM python:3.14-alpine AS build
23

34
# Install uv
45
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
56

6-
# Set environment variables
7+
# Enable bytecode compilation for faster startup
78
ENV UV_COMPILE_BYTECODE=1
8-
ENV PATH="/code/.venv/bin:$PATH"
99

10-
# Set working directory
1110
WORKDIR /code
1211

13-
# Copy project files
14-
COPY . .
12+
# Install dependencies first to leverage Docker layer caching
13+
COPY pyproject.toml uv.lock ./
14+
RUN uv sync --frozen --no-install-project --no-dev
1515

16-
# Sync dependencies (frozen and no-dev for production)
16+
# Install the project itself
17+
COPY . .
1718
RUN uv sync --frozen --no-dev
1819

19-
# Create a non-root user and change ownership
20-
RUN adduser -D appuser && chown -R appuser:appuser /code
20+
# Stage 2: Runtime stage
21+
FROM python:3.14-alpine AS runtime
2122

22-
# Switch to non-root user
23-
USER appuser
23+
RUN adduser -D appuser
24+
WORKDIR /code
25+
26+
COPY --from=build --chown=appuser:appuser /code /code
2427

25-
# Run the application directly
28+
ENV PATH="/code/.venv/bin:$PATH"
29+
USER appuser
2630
ENTRYPOINT ["app"]

‎mise.toml‎

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ ll = "ls -l"
1616
la = "ls -a"
1717

1818
g = "git"
19+
gco = "git checkout"
20+
gb = "git branch"
21+
gd = "git diff"
1922
gs = "git status"
2023
ga = "git add"
2124
gc = "git commit"
@@ -34,7 +37,7 @@ depends = ["precommit", "install"]
3437

3538
[tasks.precommit]
3639
description = "Install pre-commit hooks"
37-
run = "uv run pre-commit autoupdate && uv run pre-commit install"
40+
run = "pre-commit autoupdate && pre-commit install"
3841

3942
[tasks.install]
4043
description = "Install dependencies"
@@ -52,20 +55,12 @@ run = "uv lock --upgrade"
5255
[tasks.lint]
5356
description = "Lint and format code"
5457
alias = "l"
55-
run = [
56-
"uv run ruff check --fix",
57-
"uv run ruff format",
58-
# "uv run pyright",
59-
]
58+
run = "ruff check --fix . && ruff format ."
6059

6160
[tasks.test]
6261
description = "Run tests with coverage"
6362
alias = "t"
64-
run = [
65-
"uv run coverage run -m pytest .",
66-
"uv run coverage report -m",
67-
"uv run coverage xml",
68-
]
63+
run = "coverage run -m pytest . && coverage report -m && coverage xml"
6964

7065
[tasks.all]
7166
description = "Full setup from scratch"
@@ -81,25 +76,25 @@ hide = true
8176
[tasks.docs]
8277
description = "Build and deploy documentation to GitHub pages"
8378
depends = ["install-docs"]
84-
run = "uv run mkdocs gh-deploy --force"
79+
run = "mkdocs gh-deploy --force"
8580

8681
[tasks.local-docs]
8782
description = "Serve documentation on a local server"
8883
alias = "d"
8984
depends = ["install-docs"]
90-
run = "uv run mkdocs serve"
85+
run = "mkdocs serve"
9186

9287
###### Scripts ######
9388

9489
[tasks.app]
9590
description = "Run the app"
9691
alias = "a"
97-
run = "uv run app"
92+
run = "app"
9893

9994
[tasks.rename]
10095
description = "Rename project (run once)"
10196
alias = "r"
102-
run = "uv run rename"
97+
run = "rename"
10398

10499
[tasks.project]
105100
alias = ["rename", "p"]

‎uv.lock‎

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

0 commit comments

Comments
 (0)