-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Docker development environment update (#4325)
Co-authored-by: Saurabh Kumar <[email protected]>
- Loading branch information
Showing
15 changed files
with
249 additions
and
239 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
FROM python:3.12.7-bookworm | ||
|
||
# Add venv/bin to PATH. | ||
ENV PATH="/opt/app/.venv/bin:/usr/local/bin:$PATH" | ||
|
||
# Copy from the cache instead of linking since it's a mounted volume | ||
ENV UV_LINK_MODE=copy | ||
|
||
# Set work directory. | ||
WORKDIR /opt/app | ||
|
||
# Install node. | ||
COPY --from=node:20.18-slim /usr/local/bin /usr/local/bin | ||
COPY --from=node:20.18-slim /usr/local/lib/node_modules /usr/local/lib/node_modules | ||
|
||
# Install uv. | ||
COPY --from=ghcr.io/astral-sh/uv:0.5.13 /uv /uvx /usr/local/bin | ||
|
||
# Install node dependencies. | ||
COPY package*.json ./ | ||
RUN npm install --quiet | ||
|
||
# Install python dependencies. | ||
RUN --mount=type=cache,target=/root/.cache/uv \ | ||
--mount=type=bind,source=uv.lock,target=uv.lock \ | ||
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \ | ||
uv sync | ||
|
||
# Copy the project into the image | ||
COPY ./ ./ | ||
|
||
# Create directories. | ||
RUN mkdir -p ./hypha/static_compiled && mkdir -p ./hypha/media | ||
|
||
# Build front end. | ||
RUN npm run dev:build | ||
|
||
# Run entrypoint.sh. | ||
ENTRYPOINT ["/opt/app/docker/entrypoint.sh"] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.cache | ||
.git | ||
.github | ||
.ruff_cache | ||
.venv | ||
.vscode | ||
docs_build | ||
hypha/static_compiled | ||
media | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
name: hypha-dev | ||
|
||
services: | ||
py: | ||
container_name: hypha-django-dev | ||
build: | ||
context: .. | ||
dockerfile: docker/Dockerfile | ||
environment: | ||
- "DATABASE_URL=postgres://hypha:hypha@db:5432/hypha" | ||
- "DJANGO_SETTINGS_MODULE=hypha.settings.dev" | ||
- "PYTHONDONTWRITEBYTECODE=1" | ||
- "PYTHONUNBUFFERED=1" | ||
- "VIRTUAL_ENV=/opt/app/.venv" | ||
ports: | ||
- 9001:9001 | ||
volumes: | ||
- ../hypha:/opt/app/hypha | ||
develop: | ||
watch: | ||
- action: sync | ||
path: .. | ||
target: /opt/app | ||
ignore: | ||
- .venv/ | ||
- hypha/ | ||
- node_modules/ | ||
- action: rebuild | ||
path: ./pyproject.toml | ||
- action: rebuild | ||
path: ./package-lock.json | ||
depends_on: | ||
- db | ||
db: | ||
container_name: hypha-postgres-dev | ||
image: postgres:14-alpine | ||
volumes: | ||
- postgres_data:/var/lib/postgresql/data/ | ||
environment: | ||
- POSTGRES_USER=hypha | ||
- POSTGRES_PASSWORD=hypha | ||
- POSTGRES_DB=hypha | ||
|
||
volumes: | ||
postgres_data: |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
# Run needed python commands. | ||
python manage.py createcachetable | ||
python manage.py migrate --noinput | ||
python manage.py clear_cache --cache=default | ||
python manage.py sync_roles | ||
python manage.py wagtailsiteupdate hypha.test 9001 | ||
|
||
# Start dev server. | ||
npm run watch & | ||
python manage.py runserver_plus 0.0.0.0:9001 | ||
|
||
exec "$@" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# | ||
# Builder stage. | ||
# | ||
FROM python:3.12.7-bookworm AS builder | ||
|
||
# Add venv/bin to PATH. | ||
ENV PATH="/opt/app/.venv/bin:/usr/local/bin:$PATH" | ||
|
||
# Enable bytecode compilation | ||
ENV UV_COMPILE_BYTECODE=1 | ||
|
||
# Copy from the cache instead of linking since it's a mounted volume | ||
ENV UV_LINK_MODE=copy | ||
|
||
# Set work directory. | ||
WORKDIR /opt/app | ||
|
||
# Create directories. | ||
RUN mkdir -p ./hypha/static_compiled && mkdir -p ./hypha/media | ||
|
||
# Install node. | ||
COPY --from=node:20.18-slim /usr/local/bin /usr/local/bin | ||
COPY --from=node:20.18-slim /usr/local/lib/node_modules /usr/local/lib/node_modules | ||
|
||
# Install uv. | ||
COPY --from=ghcr.io/astral-sh/uv:0.5.13 /uv /uvx /usr/local/bin | ||
|
||
# Install node dependencies. | ||
COPY package*.json ./ | ||
RUN npm install --quiet | ||
|
||
# Install python dependencies. | ||
RUN --mount=type=cache,target=/root/.cache/uv \ | ||
--mount=type=bind,source=uv.lock,target=uv.lock \ | ||
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \ | ||
uv sync --frozen --no-dev | ||
|
||
# Copy the project into the image | ||
COPY ./ ./ | ||
|
||
# Build front end. | ||
RUN npm run build && python manage.py collectstatic --noinput --verbosity=0 | ||
|
||
|
||
# | ||
# Production stage. | ||
# | ||
FROM python:3.12.7-slim-bookworm | ||
|
||
# Add venv/bin to PATH. | ||
ENV PATH="/opt/app/.venv/bin:/usr/local/bin:$PATH" | ||
|
||
# Set work directory. | ||
WORKDIR /opt/app | ||
|
||
# Create directories. | ||
RUN mkdir -p ./hypha/static_compiled && mkdir -p ./hypha/media | ||
|
||
# Copy venv and assets from builder. | ||
COPY --from=builder /opt/app/.venv /opt/app/.venv | ||
COPY --from=builder /opt/app/static /opt/app/static | ||
|
||
# Copy the project into the image | ||
COPY ./ ./ | ||
|
||
# Run entrypoint.sh. | ||
ENTRYPOINT ["/opt/app/docker/prod/entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.cache | ||
.git | ||
.github | ||
.ruff_cache | ||
.venv | ||
.vscode | ||
docs | ||
docs_build | ||
hypha/static_compiled | ||
media | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Docker for production | ||
|
||
This is not a complete solution, but a starting point. A Dockerfile that build the Hypha app with all dependencies are provided. | ||
|
||
Anyone using this will need to add a Postgres container and a Nginx (or equivalent) container. | ||
|
||
|
||
Please play around with it and suggest improvements at <https://github.com/HyphaApp/hypha/issues>. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/sh | ||
|
||
# Run needed python commands. | ||
python manage.py createcachetable | ||
python manage.py migrate --noinput | ||
python manage.py clear_cache --cache=default | ||
python manage.py sync_roles | ||
|
||
# Start gunicorn server. | ||
gunicorn hypha.wsgi:application --env DJANGO_SETTINGS_MODULE=hypha.settings.production --threads 3 --reload --bind 0.0.0.0:9001 | ||
|
||
exec "$@" |
Oops, something went wrong.