Skip to content

Deploying a MediaCMS App

Introduction

MediaCMS is an open-source video and media platform built with Django, FastAPI, Celery workers, and a React front end. Deploying MediaCMS with a Dockerfile on Klutch.sh delivers reproducible builds, managed secrets, and persistent storage for uploads and transcoded assets—all configured from klutch.sh/app. This guide covers installation, repository prep, a production-ready Dockerfile, deployment steps, Nixpacks overrides, sample API usage, and production tips.


Prerequisites

  • A Klutch.sh account (sign up)
  • A GitHub repository containing your MediaCMS code and Dockerfile (GitHub is the only supported git source)
  • PostgreSQL database (deploy as a Klutch.sh TCP app on port 8000 and connect on 5432)
  • Redis for Celery/queues (optional but recommended; deploy as a TCP app and connect on 6379)
  • Domain ready for your MediaCMS instance

For onboarding, see the Quick Start.


Architecture and ports

  • MediaCMS web/API typically listens on internal port 8000; choose HTTP traffic.
  • Celery workers run alongside for background jobs; Redis serves as broker/result backend.
  • Persistent storage is required for uploads, transcodes, and static assets.

Repository layout

mediacms/
├── Dockerfile # Must be at repo root for auto-detection
├── requirements.txt # or poetry/pyproject
├── manage.py
├── mediacms/ # Django project
├── frontend/ # React build (optional)
├── media/ # Uploads/transcodes (persist)
├── static/ # Collected static files (persist)
└── README.md

Keep secrets out of Git; store them in Klutch.sh environment variables.


Installation (local) and starter commands

Validate locally before pushing to GitHub:

Terminal window
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
python manage.py migrate
python manage.py collectstatic --noinput
gunicorn mediacms.wsgi:application --bind 0.0.0.0:8000

Celery (optional local):

Terminal window
celery -A mediacms worker -l info

Dockerfile for MediaCMS (production-ready)

Place this Dockerfile at the repo root; Klutch.sh auto-detects it (no Docker selection in the UI):

FROM python:3.11-slim
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PORT=8000
WORKDIR /app
COPY requirements.txt .
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential ffmpeg libpq-dev && \
pip install --no-cache-dir -r requirements.txt && \
apt-get clean && rm -rf /var/lib/apt/lists/*
COPY . .
# Collect static in image build; adjust if you prefer runtime collection
RUN python manage.py collectstatic --noinput
EXPOSE 8000
CMD ["bash", "-lc", "python manage.py migrate && gunicorn mediacms.wsgi:application --bind 0.0.0.0:${PORT:-8000}"]

Notes:

  • Add a separate process or second app for Celery workers if you need background processing; reuse the same image with celery -A mediacms worker -l info.
  • Keep media/ and static/ writable and mount them as volumes.

Environment variables (Klutch.sh)

Set these in Klutch.sh before deploying:

  • PORT=8000
  • DJANGO_SECRET_KEY=<secure-random>
  • DJANGO_ALLOWED_HOSTS=example-app.klutch.sh
  • DATABASE_URL=postgres://<user>:<password>@<host>:5432/<db>
  • REDIS_URL=redis://:<password>@<host>:6379/0 (if using Celery/Redis)
  • MEDIA_URL=/media/ and STATIC_URL=/static/
  • EMAIL_HOST, EMAIL_PORT, EMAIL_HOST_USER, EMAIL_HOST_PASSWORD, EMAIL_USE_TLS (optional)
  • CELERY_BROKER_URL and CELERY_RESULT_BACKEND (if Celery is enabled)
  • TZ=UTC

If you deploy without the Dockerfile and need Nixpacks overrides (Python/Django):

  • NIXPACKS_PYTHON_VERSION=3.11
  • NIXPACKS_BUILD_CMD=pip install -r requirements.txt && python manage.py collectstatic --noinput
  • NIXPACKS_START_CMD=bash -lc 'python manage.py migrate && gunicorn mediacms.wsgi:application --bind 0.0.0.0:8000'

Attach persistent volumes

In Klutch.sh storage settings, add mount paths and sizes (no names required):

  • /app/media — user uploads, transcodes, thumbnails.
  • /app/static — collected static assets (if you prefer to persist them).
  • /app/logs — optional for application logs.

Ensure these directories are writable.


Deploy MediaCMS on Klutch.sh (Dockerfile workflow)

  1. Push your repository—with the Dockerfile at the root—to GitHub.
  2. Open klutch.sh/app, create a project, and add an app.
  3. Select HTTP traffic and set the internal port to 8000.
  4. Add the environment variables above, including Postgres/Redis credentials, Django secrets, and email settings.
  5. Attach persistent volumes for /app/media and, optionally, /app/static and /app/logs with sizes that fit your storage and retention needs.
  6. Deploy. Your MediaCMS instance will be reachable at https://example-app.klutch.sh; attach a custom domain if desired.

Sample API usage

List public videos (example endpoint; adjust to your API):

Terminal window
curl -X GET "https://example-app.klutch.sh/api/videos" \
-H "Accept: application/json"

Health checks and production tips

  • Add an HTTP probe to /health or / after configuring a simple view for readiness.
  • Enforce HTTPS at the edge; forward internally to port 8000.
  • Pin dependency versions and test upgrades in staging before production.
  • Monitor database connections and queue health; scale a worker app if Celery jobs back up.
  • Store secrets only in Klutch.sh and rotate them regularly.
  • Schedule backups for /app/media and database snapshots; sync backups off-site if needed.

MediaCMS on Klutch.sh combines reproducible Docker builds with managed secrets, persistent storage, and flexible HTTP/TCP routing. With the Dockerfile at the repo root, port 8000 configured, and Postgres/Redis connected, you can deliver a robust media platform without extra YAML or workflow overhead.