Skip to content

Commit 2c26a3c

Browse files
frjotheskumar
andauthored
Docker development environment update (#4325)
Co-authored-by: Saurabh Kumar <[email protected]>
1 parent 9960640 commit 2c26a3c

15 files changed

+249
-239
lines changed

docker/Dockerfile

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
FROM python:3.12.7-bookworm
2+
3+
# Add venv/bin to PATH.
4+
ENV PATH="/opt/app/.venv/bin:/usr/local/bin:$PATH"
5+
6+
# Copy from the cache instead of linking since it's a mounted volume
7+
ENV UV_LINK_MODE=copy
8+
9+
# Set work directory.
10+
WORKDIR /opt/app
11+
12+
# Install node.
13+
COPY --from=node:20.18-slim /usr/local/bin /usr/local/bin
14+
COPY --from=node:20.18-slim /usr/local/lib/node_modules /usr/local/lib/node_modules
15+
16+
# Install uv.
17+
COPY --from=ghcr.io/astral-sh/uv:0.5.13 /uv /uvx /usr/local/bin
18+
19+
# Install node dependencies.
20+
COPY package*.json ./
21+
RUN npm install --quiet
22+
23+
# Install python dependencies.
24+
RUN --mount=type=cache,target=/root/.cache/uv \
25+
--mount=type=bind,source=uv.lock,target=uv.lock \
26+
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
27+
uv sync
28+
29+
# Copy the project into the image
30+
COPY ./ ./
31+
32+
# Create directories.
33+
RUN mkdir -p ./hypha/static_compiled && mkdir -p ./hypha/media
34+
35+
# Build front end.
36+
RUN npm run dev:build
37+
38+
# Run entrypoint.sh.
39+
ENTRYPOINT ["/opt/app/docker/entrypoint.sh"]

docker/Dockerfile.dev

-21
This file was deleted.

docker/Dockerfile.dockerignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.cache
2+
.git
3+
.github
4+
.ruff_cache
5+
.venv
6+
.vscode
7+
docs_build
8+
hypha/static_compiled
9+
media
10+
node_modules

docker/compose.yaml

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: hypha-dev
2+
3+
services:
4+
py:
5+
container_name: hypha-django-dev
6+
build:
7+
context: ..
8+
dockerfile: docker/Dockerfile
9+
environment:
10+
- "DATABASE_URL=postgres://hypha:hypha@db:5432/hypha"
11+
- "DJANGO_SETTINGS_MODULE=hypha.settings.dev"
12+
- "PYTHONDONTWRITEBYTECODE=1"
13+
- "PYTHONUNBUFFERED=1"
14+
- "VIRTUAL_ENV=/opt/app/.venv"
15+
ports:
16+
- 9001:9001
17+
volumes:
18+
- ../hypha:/opt/app/hypha
19+
develop:
20+
watch:
21+
- action: sync
22+
path: ..
23+
target: /opt/app
24+
ignore:
25+
- .venv/
26+
- hypha/
27+
- node_modules/
28+
- action: rebuild
29+
path: ./pyproject.toml
30+
- action: rebuild
31+
path: ./package-lock.json
32+
depends_on:
33+
- db
34+
db:
35+
container_name: hypha-postgres-dev
36+
image: postgres:14-alpine
37+
volumes:
38+
- postgres_data:/var/lib/postgresql/data/
39+
environment:
40+
- POSTGRES_USER=hypha
41+
- POSTGRES_PASSWORD=hypha
42+
- POSTGRES_DB=hypha
43+
44+
volumes:
45+
postgres_data:

docker/docker-compose.yaml

-38
This file was deleted.

docker/entrypoint.dev.sh

-16
This file was deleted.

docker/entrypoint.sh

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
# Run needed python commands.
5+
python manage.py createcachetable
6+
python manage.py migrate --noinput
7+
python manage.py clear_cache --cache=default
8+
python manage.py sync_roles
9+
python manage.py wagtailsiteupdate hypha.test 9001
10+
11+
# Start dev server.
12+
npm run watch &
13+
python manage.py runserver_plus 0.0.0.0:9001
14+
15+
exec "$@"

docker/nginx/hypha.conf

-24
This file was deleted.

docker/prod/Dockerfile

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#
2+
# Builder stage.
3+
#
4+
FROM python:3.12.7-bookworm AS builder
5+
6+
# Add venv/bin to PATH.
7+
ENV PATH="/opt/app/.venv/bin:/usr/local/bin:$PATH"
8+
9+
# Enable bytecode compilation
10+
ENV UV_COMPILE_BYTECODE=1
11+
12+
# Copy from the cache instead of linking since it's a mounted volume
13+
ENV UV_LINK_MODE=copy
14+
15+
# Set work directory.
16+
WORKDIR /opt/app
17+
18+
# Create directories.
19+
RUN mkdir -p ./hypha/static_compiled && mkdir -p ./hypha/media
20+
21+
# Install node.
22+
COPY --from=node:20.18-slim /usr/local/bin /usr/local/bin
23+
COPY --from=node:20.18-slim /usr/local/lib/node_modules /usr/local/lib/node_modules
24+
25+
# Install uv.
26+
COPY --from=ghcr.io/astral-sh/uv:0.5.13 /uv /uvx /usr/local/bin
27+
28+
# Install node dependencies.
29+
COPY package*.json ./
30+
RUN npm install --quiet
31+
32+
# Install python dependencies.
33+
RUN --mount=type=cache,target=/root/.cache/uv \
34+
--mount=type=bind,source=uv.lock,target=uv.lock \
35+
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
36+
uv sync --frozen --no-dev
37+
38+
# Copy the project into the image
39+
COPY ./ ./
40+
41+
# Build front end.
42+
RUN npm run build && python manage.py collectstatic --noinput --verbosity=0
43+
44+
45+
#
46+
# Production stage.
47+
#
48+
FROM python:3.12.7-slim-bookworm
49+
50+
# Add venv/bin to PATH.
51+
ENV PATH="/opt/app/.venv/bin:/usr/local/bin:$PATH"
52+
53+
# Set work directory.
54+
WORKDIR /opt/app
55+
56+
# Create directories.
57+
RUN mkdir -p ./hypha/static_compiled && mkdir -p ./hypha/media
58+
59+
# Copy venv and assets from builder.
60+
COPY --from=builder /opt/app/.venv /opt/app/.venv
61+
COPY --from=builder /opt/app/static /opt/app/static
62+
63+
# Copy the project into the image
64+
COPY ./ ./
65+
66+
# Run entrypoint.sh.
67+
ENTRYPOINT ["/opt/app/docker/prod/entrypoint.sh"]

docker/prod/Dockerfile.dockerignore

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.cache
2+
.git
3+
.github
4+
.ruff_cache
5+
.venv
6+
.vscode
7+
docs
8+
docs_build
9+
hypha/static_compiled
10+
media
11+
node_modules

docker/prod/README.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Docker for production
2+
3+
This is not a complete solution, but a starting point. A Dockerfile that build the Hypha app with all dependencies are provided.
4+
5+
Anyone using this will need to add a Postgres container and a Nginx (or equivalent) container.
6+
7+
8+
Please play around with it and suggest improvements at <https://github.com/HyphaApp/hypha/issues>.
9+

docker/prod/entrypoint.sh

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
3+
# Run needed python commands.
4+
python manage.py createcachetable
5+
python manage.py migrate --noinput
6+
python manage.py clear_cache --cache=default
7+
python manage.py sync_roles
8+
9+
# Start gunicorn server.
10+
gunicorn hypha.wsgi:application --env DJANGO_SETTINGS_MODULE=hypha.settings.production --threads 3 --reload --bind 0.0.0.0:9001
11+
12+
exec "$@"

0 commit comments

Comments
 (0)