Skip to content

Django Static Demo

Django application demonstrating static file collection and multi-stage build targets.

Overview

Tech Stack Python / Django
Services 1
Pattern Static file collection, build targets

The appmecca.yaml

containers:
  - name: django-static-demo
    dockerfile: Dockerfile
    context: .
    target: production

deploy:
  - name: web
    container: django-static-demo
    port: 8000
    health_check:
      path: /health

Static assets are collected at build time — see the collectstatic step in this app's Dockerfile. The top-level static: block was removed in FEATURES #347 (it was read by nothing) and is now refused.

Key Concepts

Build Targets (containers[].target)

The Dockerfile has multiple stages: base and production. The target: production field tells AppMecca to build up to the production stage. This is useful for separating test and production builds.

Static File Collection

The static configuration runs Django's collectstatic, gathering CSS, JavaScript, and images from all Django apps into STATIC_ROOT for serving.

static: is a top-level key, not a per-service one

static: sits at the root of appmecca.yaml, alongside containers: and deploy: — it applies to the app, not to one service. Nesting it under a deploy[] entry does not work, and you get no error: AppMecca silently ignores any key it does not recognise, so a misplaced static: block simply never runs. The same is true of every typo'd key.

static: and static_site: are different features

static: collects assets alongside a containerised service (the Django case here). static_site: replaces the container entirely, building a bundle that is served from the edge. Do not confuse the two.

Multi-Stage Dockerfile

FROM python:3.12-slim AS base
# ... install deps, copy code

FROM base AS production
RUN python manage.py collectstatic --noinput
EXPOSE 8000
CMD ["gunicorn", "..."]

Step-by-Step Deployment

1. Register the app

mecca register git@gitlab.com:appmecca-sample-apps/django-static-demo.git \
  -e dev

2. Build

mecca build trigger \
  -e dev \
  -g git@gitlab.com:appmecca-sample-apps/django-static-demo.git

3. Deploy

mecca app deploy -e dev django-static-demo

4. Verify

curl https://django-static-demo-web.dev.appmecca.net/health
open https://django-static-demo-web.dev.appmecca.net

The service name (web) is always part of the hostname. Run mecca app show django-static-demo -e dev for the exact URL, which also carries your group slug.

What's Next