Skip to content

Commit

Permalink
Add uv and a starting Dockerfile.
Browse files Browse the repository at this point in the history
  • Loading branch information
mblayman committed Sep 11, 2024
1 parent 1e8930b commit 38829e5
Show file tree
Hide file tree
Showing 8 changed files with 1,293 additions and 10 deletions.
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
db.sqlite3
node_modules/
.coverage/
.git/
.mypy_cache/
.pytest_cache/
.ruff_cache/
.venv/
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ DJSTRIPE_WEBHOOK_SECRET=
DJSTRIPE_WEBHOOK_VALIDATION=
EMAIL_BACKEND=django.core.mail.backends.console.EmailBackend
GUNICORN_CMD_ARGS="--reload"
HASHID_FIELD_SALT="_et7oyb!6-*ez@)!27ui74hz+8osb(wd-azak(nx%8e(x4x9g$"
HASHID_FIELD_SALT='_et7oyb!6-*ez@)!27ui74hz+8osb(wd-azak(nx%8e(x4x9g_'
IS_SECURE=off
PYTHONUNBUFFERED=1
SECRET_KEY="-8dd#per$l_1e!^+$fwjac_2u5n5qil@ns*go6(3qrf^z1zj*!"
SECRET_KEY='-8dd#per$l_1e!^+$fwjac_2u5n5qil@ns*go6(3qrf^z1zj*!'
SECURE_HSTS_PRELOAD=off
SECURE_HSTS_SECONDS=0
SENDGRID_API_KEY=key
Expand Down
3 changes: 3 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
default_language_version:
python: python3

repos:
- repo: https://github.com/adamchainz/django-upgrade
rev: 1.21.0
Expand Down
34 changes: 34 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
FROM python:3.12-slim

ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
UV_PROJECT_ENVIRONMENT=/usr/local

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

COPY --from=ghcr.io/astral-sh/uv:0.4.7 /uv /bin/uv

WORKDIR /app

RUN addgroup --gid 222 --system app \
&& adduser --uid 222 --system --group app

RUN mkdir -p /app && chown app:app /app

COPY --chown=app:app pyproject.toml uv.lock /app/

RUN uv sync --frozen

COPY --chown=app:app . /app/

RUN python manage.py collectstatic --noinput

USER app

EXPOSE 8000

CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]

14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,20 @@ to inspect issues:
$ heroku pg:pull HEROKU_PG_NAME postgres://postgres:postgres@localhost:5432/mylocaldb --app APP
```

### uv

Since my macOS version is so old, psycopg doesn't have a binary package.
This causes uv (and pip!) to break.
Because of that, I'm forced to use uv through the Docker image,
but there are some settings needed to get around the fact that image doesn't install
packages in a place writeable by the app user.

Here's an example:

```
UV_PROJECT_ENVIRONMENT=/tmp/uv-venv uv add -n --dev 'types-toml==0.10.8.20240310'
```

## Market Research

This is my analysis of the market
Expand Down
22 changes: 14 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
version: '3.1'
version: "3.9"

services:

db:
image: postgres
restart: always
environment:
POSTGRES_PASSWORD: postgres
web:
build: .
volumes:
- .:/app
ports:
- "5432:5432"
- 8000:8000

# db:
# image: postgres
# restart: always
# environment:
# POSTGRES_PASSWORD: postgres
# ports:
# - "5432:5432"
48 changes: 48 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,51 @@
[project]
name = "homeschool"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = [
"beautifulsoup4==4.12.3",
"bleach==6.1.0",
"boto3==1.35.10",
"dj-database-url==2.2.0",
"dj-stripe==2.8.4",
"django-allauth==64.2.0",
"django-anymail[sendgrid]==11.1",
"django-debug-toolbar==4.4.6",
"django-denied==1.3",
"django-environ==0.11.2",
"django-extensions==3.2.3",
"django-hashid-field==3.4.1",
"django-hijack==3.6.0",
"django-htmx==1.19.0",
"django-ordered-model==3.7.4",
"django-simple-history==3.7.0",
"django-storages==1.14.4",
"django-tz-detect==0.5.0",
"django-waffle==4.1.0",
"django==5.1",
"gunicorn==23.0.0",
"psycopg[binary]==3.2.1",
"python-dateutil==2.9.0.post0",
"requests==2.32.3",
"sentry-sdk==2.13.0",
"sphinx-rtd-theme==2.0.0",
"sphinx-sitemap==2.6.0",
"sphinx==7.3.7",
"weasyprint==62.3",
"whitenoise[brotli]==6.7.0",
]

[tool.uv]
dev-dependencies = [
"time-machine>=2.15.0",
"types-bleach==6.1.0.20240331",
"types-python-dateutil==2.9.0.20240821",
"types-pytz==2024.1.0.20240417",
"types-requests==2.32.0.20240712",
"types-six==1.16.21.20240513",
"types-toml==0.10.8.20240310",
]

[tool.coverage.report]
fail_under = 100
omit = [
Expand Down
1,170 changes: 1,170 additions & 0 deletions uv.lock

Large diffs are not rendered by default.

0 comments on commit 38829e5

Please sign in to comment.