Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.git
__pycache__/
*.pyc
*.pyo
*.pyd
.Python
venv/
.venv/
52 changes: 52 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Build and Push Docker Image

on:
push:
branches:
- main
- '**'
tags:
- "v*.*.*"
workflow_dispatch:

permissions:
contents: read
packages: write

jobs:
build-and-push:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=ref,event=branch
type=ref,event=tag
type=sha
type=raw,value=latest,enable={{is_default_branch}}

- name: Build and push image
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM python:3.13-slim

ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1

WORKDIR /app

RUN apt-get update \
&& apt-get install -y --no-install-recommends build-essential \
&& rm -rf /var/lib/apt/lists/*

# To allow caching of dependencies, copy only the requirements file first
COPY requirements.txt ./
RUN pip install --no-cache-dir --upgrade pip \
&& pip install --no-cache-dir -r requirements.txt

COPY . ./

EXPOSE 8000

CMD ["python", "server.py"]
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,27 @@ uvicorn main:app --reload --host 0.0.0.0 --port 8000
```
> **Warning:** Do not use the built-in server in production!

---
### Container

Podman/Docker
```
podman run -d \
-p 8000:8000 \
-v /path/to/env.yaml:/app/env.yaml:ro \
--name hs-rest-api \
docker pull ghcr.io/openadministration/hs.rest-api:v.xy
```
Or docker-compose.yml:
```yaml
services:
hs-rest-api:
image: docker pull ghcr.io/openadministration/hs.rest-api:v.xy
ports:
- "8000:8000"
volumes:
- ./env.yaml:/app/env.yaml:ro
restart: unless-stopped
```

## Using the API

Expand Down
1 change: 0 additions & 1 deletion server.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@
host = env["host"]
log = env["log-level"]
worker = env["worker"]

if __name__ == "__main__":
uvicorn.run("main:app", host=host, port=port, log_level=log, workers=4)
Loading