Skip to content

Commit b970a31

Browse files
committed
new use_uv
1 parent 33a1285 commit b970a31

27 files changed

Lines changed: 333 additions & 315 deletions

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,4 @@ You can run `npm install` and `uv sync` in the respective `client` and `server`
158158

159159
### Changing env vars
160160

161-
Edit the `.env` file in the respective directory (client or server).
161+
Edit the `.env` file in the respective directory (client or server).

client/eslint.config.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import tsParser from "@typescript-eslint/parser";
66
const compat = new FlatCompat({
77
baseDirectory: import.meta.dirname,
88
})
9-
9+
1010
const eslintConfig = [
1111
...compat.config({
1212
extends: ["next/core-web-vitals", "next/typescript"]
@@ -32,5 +32,5 @@ const eslintConfig = [
3232
ignores: ["node_modules/**", ".next/**", "next-env.d.ts"]
3333
}
3434
]
35-
36-
export default eslintConfig
35+
36+
export default eslintConfig

client/next.config.mjs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
1-
// import os from "node:os";
2-
// import isInsideContainer from "is-inside-container";
1+
import os from "node:os";
2+
import isInsideContainer from "is-inside-container";
33

4-
// const isWindowsDevContainer = () =>
5-
// os.release().toLowerCase().includes("microsoft") && isInsideContainer();
4+
const isWindowsDevContainer = () =>
5+
os.release().toLowerCase().includes("microsoft") && isInsideContainer();
66

77
/** @type {import('next').NextConfig} */
8-
9-
const config = {
8+
const nextConfig = {
109
reactStrictMode: true,
11-
turbopack: {
12-
root: import.meta.dirname,
13-
}
14-
// Turns on file change polling for the Windows Dev Container
15-
// Doesn't work currently for turbopack, so file changes will not automatically update the client.
16-
// watchOptions: isWindowsDevContainer()
17-
// ? {
18-
// pollIntervalMs: 1000
19-
// }
20-
// : undefined,
10+
// dumb fix for windows docker
11+
webpack: isWindowsDevContainer()
12+
? (config) => {
13+
config.watchOptions = {
14+
poll: 1000,
15+
aggregateTimeout: 300,
16+
};
17+
return config;
18+
}
19+
: undefined,
2120
};
2221

23-
export default config;
22+
export default nextConfig;

docker-compose.prod.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
services:
2+
db:
3+
image: postgres:16.4
4+
restart: unless-stopped
5+
volumes:
6+
- ./data/db:/var/lib/postgresql/data
7+
env_file: ./.env.prod
8+
healthcheck:
9+
test: ["CMD-SHELL", "pg_isready -U postgres"]
10+
interval: 3s
11+
timeout: 3s
12+
retries: 5
13+
214
server:
315
image: ghcr.io/codersforcauses/django-nextjs-template-use_uv-prod-server:latest
416
container_name: transplant_server
@@ -12,6 +24,8 @@ services:
1224
- ./opt/static_files:/opt/static_files
1325
environment:
1426
- DJANGO_SETTINGS_MODULE=api.settings
27+
depends_on:
28+
- db
1529

1630
client:
1731
image: ghcr.io/codersforcauses/django-nextjs-template-use_uv-prod-client:latest

docker-compose.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
services:
2+
db:
3+
image: postgres:16.4
4+
restart: unless-stopped
5+
volumes:
6+
- ./data/db:/var/lib/postgresql/data
7+
healthcheck:
8+
test: ["CMD-SHELL", "pg_isready -U postgres"]
9+
interval: 3s
10+
timeout: 3s
11+
retries: 5
12+
env_file: ./server/.env
13+
ports:
14+
- 5432:5432

docker/server/Dockerfile

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
FROM python:3.12-slim
1+
FROM astral/uv:0.9-python3.14-bookworm-slim
22

3-
RUN apt-get update && apt-get install --yes --no-install-recommends g++ libssl-dev && rm -rf /var/lib/apt/lists/*
4-
5-
RUN pip install --upgrade pip && pip install uv
3+
RUN apt-get update && apt-get upgrade --yes && apt-get install --yes --no-install-recommends postgresql-client g++ libssl-dev && rm -rf /var/lib/apt/lists/*
64

75
WORKDIR /app
86

97
COPY ./docker/server/entrypoint.sh /entrypoint.sh
108

119
COPY ./server/pyproject.toml ./server/uv.lock ./
1210

13-
RUN uv sync
11+
RUN uv sync --frozen
1412

1513
COPY ./server ./
1614

1715
RUN chmod +x /entrypoint.sh
18-
CMD ["/entrypoint.sh"]
16+
CMD ["/entrypoint.sh"]

docker/server/entrypoint.sh

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,36 @@
11
#!/bin/bash
22

3+
# Wait until Database is available before continuing
4+
printf "\n" && echo "Checking Database is up"
5+
# using psql
6+
while ! pg_isready -q -h $POSTGRES_HOST -p $POSTGRES_PORT -U $POSTGRES_USER
7+
do
8+
echo "$(date) - waiting for database to start"
9+
sleep 1
10+
done
11+
12+
>&2 echo "Postgres is up - continuing"
13+
314
echo "Applying database migrations"
4-
python manage.py migrate --noinput
15+
uv run python manage.py migrate --noinput
516

617
echo "Collecting static files"
7-
python manage.py collectstatic --noinput
18+
uv run python manage.py collectstatic --noinput
819

920
# Create Django Superuser
1021
echo "Creating Django Superuser"
11-
python manage.py createsuperuser --noinput
22+
uv run python manage.py createsuperuser --noinput
1223

1324
# Run inbuilt Django server if ENV is development
1425
if [ "${APP_ENV^^}" = "DEVELOPMENT" ]; then
1526

1627
# Install extra non-prod packages
1728
printf "\n" && echo "Installing dev dependencies for $APP_ENV"
18-
uv sync
29+
uv sync --frozen --all-groups
1930
# Run developments
2031
printf "\n" && echo "Starting inbuilt django webserver"
2132
echo "Running: python manage.py runserver 0.0.0.0:8081"
22-
python manage.py runserver 0.0.0.0:8081
33+
uv run python manage.py runserver 0.0.0.0:8081
2334
exit
2435
fi
2536

@@ -30,6 +41,6 @@ if [ "${APP_ENV^^}" = "PRODUCTION" ]; then
3041

3142
# Run Gunicorn / Django
3243
printf "\n" && echo " Running Gunicorn / Django"
33-
echo "Running: gunicorn api.wsgi -b 0.0.0.0:8081 --workers=6 --keep-alive 20 --log-file=- --log-level debug --access-logfile=/var/log/accesslogs/gunicorn --capture-output --timeout 50"
34-
gunicorn api.wsgi -b 0.0.0.0:8081 --workers=6 --keep-alive 20 --log-file=- --log-level debug --access-logfile=/var/log/accesslogs/gunicorn --capture-output --timeout 50
35-
fi
44+
echo "Running: gunicorn server.wsgi -b 0.0.0.0:8081 --workers=6 --keep-alive 20 --log-file=- --log-level debug --access-logfile=/var/log/accesslogs/gunicorn --capture-output --timeout 50"
45+
uv run gunicorn server.wsgi -b 0.0.0.0:8081 --workers=6 --keep-alive 20 --log-file=- --log-level debug --access-logfile=/var/log/accesslogs/gunicorn --capture-output --timeout 50
46+
fi

server/.env.example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ APP_ENV=DEVELOPMENT
44
API_SECRET_KEY="supersecretkey"
55
API_ALLOWED_HOSTS=".localhost 127.0.0.1 [::1]"
66

7+
POSTGRES_HOST=localhost
8+
POSTGRES_NAME=postgres
9+
POSTGRES_USER=postgres
10+
POSTGRES_PASSWORD=password
11+
POSTGRES_PORT=5432
12+
713
DJANGO_SUPERUSER_PASSWORD=Password123
814
DJANGO_SUPERUSER_EMAIL=admin@test.com
915
DJANGO_SUPERUSER_USERNAME=admin

server/.flake8

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

server/.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.14

0 commit comments

Comments
 (0)