Skip to content

Commit baa4622

Browse files
1 parent e473d47 commit baa4622

11 files changed

Lines changed: 467 additions & 456 deletions

.dockerignore

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,10 @@
33

44
# Except code
55
!/src/
6-
!/deploy/
6+
!/pyproject.toml
7+
!/uv.lock
78
!/alembic/
89
!/alembic.ini
9-
!/pyproject.toml
10-
!logging.yaml
11-
!uv.lock
1210

1311
# And ignore cache files in the code
1412
__pycache__
15-
16-
.venv

.github/dependabot.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ updates:
66
schedule:
77
interval: "weekly"
88
groups:
9-
# TODO: switch to uv
10-
poetry: # currently can't switch to uv because of https://github.com/dependabot/dependabot-core/issues/10478
9+
python-dependencies:
1110
patterns:
1211
- "*"
1312

@@ -16,9 +15,17 @@ updates:
1615
directory: "/"
1716
schedule:
1817
interval: "weekly"
18+
groups:
19+
docker-dependencies:
20+
patterns:
21+
- "*"
1922

2023
# Enable version updates for Actions
2124
- package-ecosystem: "github-actions"
2225
directory: "/"
2326
schedule:
2427
interval: "weekly"
28+
groups:
29+
actions-dependencies:
30+
patterns:
31+
- "*"
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Build and publish a Docker image
1+
name: Build and deploy
22

33
on:
44
# Allow manual trigger of the workflow
@@ -16,7 +16,7 @@ on:
1616
env:
1717
# Use GitHub Container Registry
1818
REGISTRY: ghcr.io
19-
IMAGE_NAME: one-zero-eight/printers
19+
IMAGE_NAME: ${{ github.repository }}
2020

2121
jobs:
2222
build-and-push-image:
@@ -30,26 +30,26 @@ jobs:
3030
outputs:
3131
imageid: ${{ steps.build.outputs.imageid }}
3232
steps:
33-
- name: Checkout repository
34-
uses: actions/checkout@v4
33+
- name: 👾 Checkout repository
34+
uses: actions/checkout@v5
3535

36-
- name: Set up Docker Buildx
36+
- name: 🐳 Set up Docker Buildx
3737
uses: docker/setup-buildx-action@v3
3838

39-
- name: Log in to the Container registry
39+
- name: 🐳 Log in to the Container registry
4040
uses: docker/login-action@v3
4141
with:
4242
registry: ${{ env.REGISTRY }}
4343
username: ${{ github.actor }}
4444
password: ${{ secrets.GITHUB_TOKEN }}
4545

46-
- name: Extract metadata for Docker
46+
- name: 🐳 Extract metadata for Docker
4747
id: meta
4848
uses: docker/metadata-action@v5
4949
with:
5050
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
5151

52-
- name: Build and push Docker image
52+
- name: 🐳 Build and push Docker image
5353
id: build
5454
uses: docker/build-push-action@v6
5555
with:
@@ -63,7 +63,7 @@ jobs:
6363
deploy:
6464
# Only on manual trigger or push to main
6565
if: github.repository_owner == 'one-zero-eight' && (github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.ref == 'refs/heads/main'))
66-
name: Deploy to server for ${{ github.event.inputs.environment || 'staging' }}
66+
name: ⚡️ Deploy to server for ${{ github.event.inputs.environment || 'staging' }}
6767
needs: build-and-push-image
6868
runs-on: [self-hosted, innohassle]
6969
environment:
@@ -75,7 +75,7 @@ jobs:
7575
group: ${{ github.event.inputs.environment || 'staging' }}
7676
cancel-in-progress: false
7777
steps:
78-
- name: Deploy via SSH
78+
- name: ⚡️ Deploy via SSH
7979
uses: appleboy/ssh-action@v1.1.0
8080
with:
8181
host: ${{ secrets.SSH_HOST }}

.github/workflows/pre-commit.yaml

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,21 @@
1-
name: pre-commit
1+
name: Run pre-commit
22

3-
on: [push, pull_request]
3+
on: [ push, pull_request ]
44

55
jobs:
66
pre-commit:
77
runs-on: ubuntu-latest
88
steps:
9-
#----------------------------------------------
10-
# Check-out repo and set-up python
11-
#----------------------------------------------
12-
- name: Check out repository
13-
uses: actions/checkout@v4
14-
15-
#----------------------------------------------
16-
# Install uv
17-
#----------------------------------------------
18-
# based on https://docs.astral.sh/uv/guides/integration/github/
19-
- name: Install uv
20-
uses: astral-sh/setup-uv@v5
9+
- name: 👾 Check out repository
10+
uses: actions/checkout@v5
11+
- name: 📦 Set up uv
12+
uses: astral-sh/setup-uv@v7
2113
with:
2214
enable-cache: true
23-
24-
- name: "Set up Python"
25-
uses: actions/setup-python@v5
26-
with:
27-
python-version-file: "pyproject.toml"
28-
#----------------------------------------------
29-
# Install project dependencies if not cached
30-
#----------------------------------------------
31-
32-
- name: Load pre-commit caches
33-
uses: actions/cache@v4
34-
with:
35-
path: ~/.cache/pre-commit
36-
key: pre-commit-3|${{ env.pythonLocation }}|${{ hashFiles('.pre-commit-config.yaml') }}
37-
38-
- name: Install libcups2-dev
39-
run: sudo apt-get update && sudo apt-get install libcups2-dev
40-
41-
- name: Run pre-commit
42-
run: uvx pre-commit run --show-diff-on-failure --color=always --all-files --hook-stage manual
15+
activate-environment: true
16+
- name: 📦 Install the project
17+
run: uv sync
18+
- name: 🧪 Run pre-commit
19+
run: uv run pre-commit run --show-diff-on-failure --color=always --all-files --hook-stage manual
4320
env:
4421
RUFF_FORMAT: github

.pre-commit-config.yaml

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ default_stages:
1313
repos:
1414
# Fix some errors with Ruff
1515
- repo: https://github.com/astral-sh/ruff-pre-commit
16-
rev: v0.7.4
16+
rev: v0.14.0
1717
hooks:
1818
- id: ruff
1919
args: [ --fix, --exit-zero ]
@@ -23,19 +23,17 @@ repos:
2323

2424
# Lint Python files with Ruff
2525
- repo: https://github.com/astral-sh/ruff-pre-commit
26-
rev: v0.7.4
26+
rev: v0.14.0
2727
hooks:
2828
- id: ruff
2929
name: "ruff: linting"
3030

3131
# Check other files
3232
- repo: https://github.com/pre-commit/pre-commit-hooks
33-
rev: v5.0.0
33+
rev: v6.0.0
3434
hooks:
3535
- id: trailing-whitespace
36-
exclude: typings/
3736
- id: end-of-file-fixer
38-
exclude: typings/
3937
- id: check-added-large-files
4038

4139
# Local linting
@@ -47,9 +45,3 @@ repos:
4745
entry: uv run ./scripts/generate_settings_schema.py
4846
pass_filenames: false
4947
files: ^src/config_schema.py$
50-
- id: uv-check
51-
name: uv lockfile check
52-
entry: uv lock --check
53-
language: system
54-
pass_filenames: false
55-
files: "pyproject.toml"

Dockerfile

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,51 @@
1-
# Based on https://github.com/astral-sh/uv-docker-example/blob/main/multistage.Dockerfile
1+
###########################################################
2+
# Builder stage. Build dependencies.
23
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim AS builder
3-
ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy UV_PYTHON_DOWNLOADS=0
4+
ENV PYTHONUNBUFFERED=1 \
5+
PYTHONDONTWRITEBYTECODE=1 \
6+
UV_COMPILE_BYTECODE=1 \
7+
UV_LINK_MODE=copy \
8+
UV_PYTHON_DOWNLOADS=0
49

510
# pycups is sources-only so we have to build it
611
RUN apt-get update && apt-get install -y --no-install-recommends libcups2-dev gcc && rm -rf /var/lib/apt/lists/*
712

813
WORKDIR /app
14+
COPY ./pyproject.toml ./uv.lock ./
15+
916
RUN --mount=type=cache,target=/root/.cache/uv \
10-
--mount=type=bind,source=uv.lock,target=uv.lock \
11-
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
1217
uv sync --frozen --no-install-project --no-dev
1318

14-
COPY . /app
15-
RUN --mount=type=cache,target=/root/.cache/uv \
16-
uv sync --frozen --no-dev
1719

20+
###########################################################
21+
# Production stage. Copy only runtime deps that were installed in the Builder stage.
22+
FROM python:3.12-slim-bookworm AS production
1823

19-
# Then, use a final image without uv
20-
FROM python:3.12-slim-bookworm
21-
# It is important to use the image that matches the builder, as the path to the
22-
# Python executable must be the same, e.g., using `python:3.11-slim-bookworm`
23-
# will fail.
24-
RUN groupadd -g 1500 app && \
25-
useradd -m -u 1500 -g app app
24+
ENV PYTHONUNBUFFERED=1
2625

27-
RUN apt-get update && apt-get install -y --no-install-recommends \
28-
libcups2 cups-client && rm -rf /var/lib/apt/lists/*
26+
RUN apt-get update && apt-get install -y --no-install-recommends libcups2 cups-client && rm -rf /var/lib/apt/lists/*
2927

30-
ENV PATH="/app/.venv/bin:$PATH"
31-
# Copy the application from the builder
32-
COPY --from=builder --chown=app:app /app /app
33-
USER app
28+
# Copy the applicant from the builder
29+
COPY --from=builder /app /app
30+
31+
# Create user with the name uv
32+
RUN groupadd -g 1500 uv && \
33+
useradd -m -u 1500 -g uv uv
34+
35+
USER uv
3436
WORKDIR /app
3537

38+
# Place executables in the environment at the front of the path
39+
ENV PATH="/app/.venv/bin:$PATH"
40+
41+
COPY --chown=uv:uv . /app
42+
3643
EXPOSE 8000
37-
CMD [ "gunicorn", "--worker-class", "uvicorn.workers.UvicornWorker", "--bind", "0.0.0.0:8000", "--workers", "1", "src.api.app:app" ]
44+
CMD ["gunicorn", \
45+
"--worker-class", "uvicorn.workers.UvicornWorker", \
46+
"--bind", "0.0.0.0:8000", \
47+
"--workers", "1", \
48+
"src.api.app:app", \
49+
"--timeout", "300", \
50+
"--forwarded-allow-ips=*" \
51+
]

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ This is the FastAPI ASGI application.
2222

2323
### Set up for development
2424

25-
1. Install [Python 3.12+](https://www.python.org/downloads/), [uv](https://docs.astral.sh/uv/),
26-
[Docker](https://docs.docker.com/engine/install/)
25+
1. Install [uv](https://docs.astral.sh/uv/), [Docker](https://docs.docker.com/engine/install/)
2726
2. Install project dependencies
2827
```bash
2928
uv sync
@@ -33,7 +32,7 @@ This is the FastAPI ASGI application.
3332
uv run -m src.api --reload
3433
```
3534
> Follow provided instructions if needed
36-
4. Open in the browser: http://localhost:8000
35+
4. Open in the browser: http://localhost:8011
3736
> The api will be reloaded when you edit the code
3837
3938
> [!IMPORTANT]

deploy/docker-entrypoint.sh

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

docker-compose.yaml

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,46 @@
1+
# This is a Docker Compose configuration for local use.
2+
3+
# Run all services:
4+
# docker compose up --build --wait
5+
16
services:
27
api:
38
build: .
4-
volumes:
5-
- "./settings.yaml:/app/settings.yaml:ro" # Read-only settings file
9+
restart: no
610
depends_on:
711
db:
812
condition: service_healthy
9-
restart: always
1013
ports:
11-
- "8000:8000"
14+
- "8011:8000"
15+
volumes:
16+
- "./settings.yaml:/app/settings.yaml:ro" # Read-only settings file
1217

1318
db:
14-
# See more: https://registry.hub.docker.com/_/mongo
19+
# See more: https://hub.docker.com/_/mongo
1520
image: "mongo:8.0"
16-
restart: always
17-
volumes:
18-
- "mongodb:/data/db"
21+
restart: no
1922
ports:
2023
- "27017:27017"
24+
volumes:
25+
- "mongodb:/data/db"
2126
healthcheck:
22-
test: echo 'db.runCommand("ping").ok' | mongosh localhost:27017/db --quiet
23-
interval: 5s
27+
test: echo 'db.runCommand("ping").ok' | mongosh 127.0.0.1:27017/db --quiet
2428
timeout: 5s
25-
retries: 5
29+
start_period: 30s
30+
interval: 1m
2631
environment:
2732
MONGO_INITDB_ROOT_USERNAME: ${MONGO_INITDB_ROOT_USERNAME:-mongoadmin}
2833
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_INITDB_ROOT_PASSWORD:-secret}
2934

3035
unoserver:
3136
image: ghcr.io/unoconv/unoserver-docker
37+
restart: no
3238
ports:
3339
- "2003:2003"
3440

3541
cups:
3642
image: olbat/cupsd:2025-05-12
37-
restart: always
43+
restart: no
3844
volumes:
3945
- "cups:/etc/cups"
4046
profiles: [ cups ]

0 commit comments

Comments
 (0)