Skip to content

Commit 01635ce

Browse files
committed
Replace the wrong Django CI workflow with a correct Sanic CI matrix (Python 3.10-3.13) and a tag-triggered GHCR Docker build, add a Dockerfile that injects the server password at run time, and re-encode requirements.txt from UTF-16 to UTF-8.
1 parent 440b67d commit 01635ce

7 files changed

Lines changed: 160 additions & 30 deletions

File tree

‎.dockerignore‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.git
2+
.github
3+
.gitignore
4+
.idea
5+
.pytest_cache
6+
__pycache__
7+
**/__pycache__
8+
*.pyc
9+
venv
10+
i-try
11+
tests
12+
example.gif
13+
*.md
14+
*.MD
15+
LICENSE
16+
CONTRIBUTING.md
17+
tests.bat
18+
# Never copy keys or certs into the image.
19+
*.pem

‎.github/workflows/ci.yml‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
name: Test (Python ${{ matrix.python-version }})
12+
runs-on: ubuntu-latest
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
# Minimum is 3.10: sanic 25.12.0 and markdown-it-py 4.0.0 both require >=3.10
17+
# (and cryptography 46.0.3 excludes 3.9.0/3.9.1). 3.13 is the highest version
18+
# supported across every pinned dependency.
19+
python-version: ["3.10", "3.11", "3.12", "3.13"]
20+
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v4
24+
25+
- name: Set up Python ${{ matrix.python-version }}
26+
uses: actions/setup-python@v5
27+
with:
28+
python-version: ${{ matrix.python-version }}
29+
cache: pip
30+
31+
- name: Install dependencies
32+
run: |
33+
python -m pip install --upgrade pip
34+
pip install -r requirements.txt
35+
36+
- name: Run tests
37+
run: pytest tests/ -v

‎.github/workflows/django.yml‎

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Docker Publish
2+
3+
# Build and push a Docker image to GHCR on every version tag (v1.2.3, v2.0.0, ...).
4+
on:
5+
push:
6+
tags:
7+
- "v*"
8+
9+
env:
10+
REGISTRY: ghcr.io
11+
IMAGE_NAME: ${{ github.repository }}
12+
13+
jobs:
14+
build-and-push:
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read
18+
packages: write
19+
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
24+
- name: Log in to GHCR
25+
uses: docker/login-action@v3
26+
with:
27+
registry: ${{ env.REGISTRY }}
28+
username: ${{ github.actor }}
29+
password: ${{ secrets.GITHUB_TOKEN }}
30+
31+
- name: Extract image metadata
32+
id: meta
33+
uses: docker/metadata-action@v5
34+
with:
35+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
36+
# Derive image tags from the git tag.
37+
# v1.2.3 -> 1.2.3, 1.2, 1, plus a stable "latest".
38+
tags: |
39+
type=semver,pattern={{version}}
40+
type=semver,pattern={{major}}.{{minor}}
41+
type=semver,pattern={{major}}
42+
type=raw,value=latest
43+
44+
- name: Set up Buildx
45+
uses: docker/setup-buildx-action@v3
46+
47+
- name: Build and push
48+
uses: docker/build-push-action@v6
49+
with:
50+
context: .
51+
push: true
52+
tags: ${{ steps.meta.outputs.tags }}
53+
labels: ${{ steps.meta.outputs.labels }}
54+
cache-from: type=gha
55+
cache-to: type=gha,mode=max

‎Dockerfile‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# syntax=docker/dockerfile:1
2+
FROM python:3.13-slim
3+
4+
ENV PYTHONUNBUFFERED=1 \
5+
PYTHONDONTWRITEBYTECODE=1 \
6+
PIP_NO_CACHE_DIR=1 \
7+
HOST=0.0.0.0 \
8+
PORT=8000
9+
10+
WORKDIR /app
11+
12+
# Install dependencies first so this layer is cached unless requirements change.
13+
# All pinned deps ship manylinux wheels, so no compiler toolchain is needed.
14+
COPY requirements.txt ./
15+
RUN python -m pip install --upgrade pip \
16+
&& pip install -r requirements.txt
17+
18+
# Copy application source.
19+
COPY cmd_chat ./cmd_chat
20+
COPY cmd_chat.py ./
21+
COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
22+
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
23+
24+
# Run as an unprivileged user.
25+
RUN useradd --create-home --uid 10001 appuser
26+
USER appuser
27+
28+
# Server listens on $PORT (default 8000).
29+
EXPOSE 8000
30+
31+
# No password is baked into the image. PASSWORD must be supplied at run time:
32+
# docker run -e PASSWORD=secret -p 8000:8000 ghcr.io/diorwave/cmd-chat:latest
33+
ENTRYPOINT ["docker-entrypoint.sh"]

‎docker-entrypoint.sh‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env sh
2+
set -e
3+
4+
# Host and port have safe defaults but can be overridden at run time.
5+
: "${HOST:=0.0.0.0}"
6+
: "${PORT:=8000}"
7+
8+
# The server password is a secret. It is never baked into the image; it must be
9+
# provided at run time, for example:
10+
# docker run -e PASSWORD=secret -p 8000:8000 ghcr.io/diorwave/cmd-chat:latest
11+
if [ -z "${PASSWORD:-}" ]; then
12+
echo "ERROR: PASSWORD environment variable is required (pass it at run time, e.g. -e PASSWORD=...)." >&2
13+
exit 1
14+
fi
15+
16+
exec python cmd_chat.py serve "$HOST" "$PORT" --password "$PASSWORD"

‎requirements.txt‎

-659 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)