Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,21 @@ jobs:
DATABASE_HOST: localhost
DATABASE_PORT: 5432
DJANGO_ENV: DEBUG
# RealFfmpegTests (test_video_utils.py) skips when ffmpeg is missing, so a
# laptop without it stays green; here a missing ffmpeg is a failure.
REQUIRE_FFMPEG: "1"

steps:
- uses: actions/checkout@v4

# Mirror the Dockerfile's system deps: ImageMagick + Ghostscript power the
# PDF→thumbnail path that Artifact.save() runs (exercised by the Talk
# fixtures); libpq-dev is needed to build psycopg2 from source.
# fixtures); libpq-dev is needed to build psycopg2 from source; ffmpeg
# (with ffprobe) runs RealFfmpegTests, the banner video commands (#1468).
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends imagemagick ghostscript libpq-dev
sudo apt-get install -y --no-install-recommends imagemagick ghostscript libpq-dev ffmpeg
sudo cp imagemagick-policy.xml /etc/ImageMagick-6/policy.xml

- name: Set up Python
Expand Down Expand Up @@ -170,7 +174,7 @@ jobs:
run: python -m playwright install --with-deps chromium

- name: Run end-to-end tests
run: python manage.py test website.tests.test_member_e2e --settings=makeabilitylab.settings_test --verbosity=2
run: python manage.py test website.tests.test_member_e2e website.tests.test_hero_carousel_e2e --settings=makeabilitylab.settings_test --verbosity=2

# Accessibility sweep (Pa11y + Axe, WCAG 2.0 AA). CONTRIBUTING requires Pa11y
# on UI changes but nothing enforced it (#1278 item 6). This wires it in.
Expand Down
12 changes: 12 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ A superuser is required to use `/admin` and add content; create one with `python
- When fixing a bug reachable through a real queryset, URL, or view, add a regression test in the matching style before applying the fix (matches the tests-first workflow).
- **Always use the `--settings=makeabilitylab.settings_test` shim.** It sets `MIGRATION_MODULES = {'website': None}` so the test DB is built directly from the current models, sidestepping the gitignored, per-environment `website/migrations/` history. This is the durable fix for #1267 — without it, a fresh test DB can fail at creation with `column "..." already exists` (old workaround: `docker exec makeabilitylabwebsite-db-1 psql -U admin -d postgres -c "DROP DATABASE IF EXISTS test_makeability;"`).
- **CI:** `.github/workflows/test.yml` runs this same command on every push to `master` and every PR (free/unlimited for this public repo). It reports a green ✓ / red ✗ — it does not block pushes or the deploy. See the testing roadmap in #1278.
- **Banner video tests (#1468):** `transaction.on_commit` callbacks never fire by themselves in a `TestCase`, so every test of a save that may queue a conversion wraps it in `self.captureOnCommitCallbacks(execute=True)` and asserts how many callbacks were registered; `settings_test.py` sets `BANNER_VIDEO_CONVERT_INLINE = True` so the captured callback runs the job in the test thread. ffprobe/ffmpeg are patched everywhere except `RealFfmpegTests` (`test_video_utils.py`), which runs the real commands and skips when ffmpeg is absent; `REQUIRE_FFMPEG=1` (set in CI's `test` job) turns that skip into a failure. The hero's video loading is covered by Playwright in `test_hero_carousel_e2e.py` (CI `e2e` job).
- **Coverage (#1278 item 4):** the CI `test` job wraps the suite in `coverage run` and publishes a table to the run's Summary; config is in `.coveragerc` (measures the `website` app, branch coverage on). It's **report-only** — no `--fail-under` gate; the number targets backfill. Run locally inside the container: `pip install -r requirements-dev.txt`, then `coverage run manage.py test website --settings=makeabilitylab.settings_test && coverage report` (or `coverage html` for a browsable `htmlcov/`).
- Accessibility (Pa11y CI + Axe, WCAG 2.0 AA): start the site, then `docker-compose -f docker-compose-local-dev.yml --profile testing run --rm a11y`. URLs to scan are configured in `.pa11yci.json`. Run this before submitting UI changes.

Expand Down Expand Up @@ -148,6 +149,17 @@ Every container start runs, in order: `collectstatic` → `makemigrations` → `

**`image_cropping` is an in-repo fork**, not the PyPI `django-image-cropping` (which was EOL Jcrop+jQuery, Django ≤4.0). Like `sortedm2m_filter_horizontal_widget`, the top-level `image_cropping/` package is project source code and shadows/replaces the dropped dependency. Its admin widget is **Cropper.js** (vendored static, no build step): editors preview and crop client-side *before* the first save (#1299/#1269). The data layer is intentionally unchanged — `ImageRatioField` is still a `CharField` whose `deconstruct()` returns `image_cropping.fields.ImageRatioField`, so the gitignored per-environment migrations that `import image_cropping.fields` keep working and the DB column is untouched (a regression test pins this path). See `image_cropping/README.md`. To bump Cropper.js, replace the vendored `static/image_cropping/cropper.min.{js,css}` (stay on the v1.x API; v2 is a different API).

### Banner videos (#1468)

An editor's banner video upload is **not** stored as `Banner.video`. `BannerAdminForm` (used by `BannerAdmin` and the project page's `BannerInline`) checks it in `clean_video` (extension and signature, at most 250 MB, then `ffprobe`: a real video stream, at most 60 s, frame at most 4096 px, landscape, not PQ HDR) and changes nothing; `save()` stores it as `Banner.video_original` under a server-generated name in `banner/videos/originals/`, sets `video_conversion_started`, and registers a job with `transaction.on_commit`. After the commit a daemon thread in that Gunicorn worker (`website/utils/banner_video_jobs.py`) converts it, one job at a time across workers (an `fcntl.flock` in the temp dir), and sets `Banner.video` to an MP4 of at most 10 MB with one `UPDATE` filtered on the banner id, the original's name and the start time, so a superseded job (new upload, "Convert again", video cleared, banner deleted) changes nothing and deletes its output. No task queue, no startup command.

- **Encoding** (`website/utils/video_utils.py`, where all the limits live): a file already H.264 `yuv420p`, at most 1920×1080 and 10 MB, is stream-copied (still strips audio and metadata such as location); anything else gets one `libx264` pass fitting inside 1600×900 (never cropped or enlarged), at most 30 fps, CRF 27 with `-maxrate min(2500, 72000/duration)` kbit/s, and one retry at three quarters of that if the result is over 10 MB. HLG HDR is tone-mapped to BT.709. Every command is an argv list with the demuxer forced from the file signature, `-protocol_whitelist file` and `-map 0:V:0` (capital V, so cover art is never picked), under `timeout -k 10 300 nice -n 10`; on failure the tail of ffmpeg's stderr is logged with paths removed. The 60 s limit has 0.5 s of slack (a real 60 s clip probes as 60.03 s).
- **The original is kept** (on success and on failure) so "Convert again from the original upload" (a banner list action) can re-run it. It is linked only from the admin, never rendered publicly (a test pins this), deleted with the banner (`pre_delete`) and when a new upload replaces it. Originals can be up to 250 MB each on the media filesystem, which is snapshotted.
- **State:** `Banner.video_status` is `converting`, `interrupted` (started over 30 minutes ago and never finished, e.g. the worker was killed), `failed` (`video_conversion_error`), `ready` or `none`; the banner list's **Video** column and a read-only row on the form show it. `Banner.objects.displayable()` leaves out a banner whose only media is an unconverted original (landing and project pages).
- **No ffmpeg** (the checkout can be ahead of the image): an upload of at most 10 MB is stored as `video` exactly as before (and any kept original, job and error are dropped, so "Convert again" can't resurrect an older upload), a larger one is refused, the help text and the browser size check switch to 10 MB, and `/version.json` reports `"ffmpeg": false`. `validate_banner_video_size` on `Banner.video` is the 10 MB backstop for new uploads.
- **Hero markup** (`base.html`, `carousel.js`): `<source type>` follows the file (omitted for `.mov`, which Chromium would otherwise skip), only the first slide autoplays, and for a banner **with an image** (its poster) the other slides are `preload="none"` and each source is gated with `media="(prefers-reduced-motion: no-preference)"`. A banner with no image is never gated, because its paused first frame is all that can fill the hero (gated, it would be black under reduced motion or after Pause). `setVideoPlayback` lifts the gate (and calls `load()`) whenever a video is about to play, so Play works under reduced motion for every slide shown after it.
- Logs record banner ids, sizes, bitrates and timings, never file names.

### Rich text

News items use `django-ckeditor`. Uploaded files via CKEditor land under `media/uploads/`, with filenames generated by `website.utils.fileutils.get_ckeditor_image_filename`.
Expand Down
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ RUN pip install --upgrade pip
# - sqlite3: Useful for debugging, though we use PostgreSQL in production
# - git: lets docker-entrypoint.sh capture the deployed commit SHA into
# build-info.json for the /version/ endpoint (#1366)
# - ffmpeg: converts uploaded banner videos to a web-ready MP4 of at most
# 10 MB (#1468). The package also provides ffprobe. It grows
# this layer by about 560 MB (132 MB -> 692 MB): apt counts 361 MB
# for ffmpeg's packages, plus the packages it upgrades, which are
# stored again in this layer.
#
# We clean up the apt cache afterward to reduce the final image size.
RUN apt-get update \
Expand All @@ -36,6 +41,7 @@ RUN apt-get update \
ghostscript \
sqlite3 \
git \
ffmpeg \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

Expand Down
23 changes: 23 additions & 0 deletions docs/DEPLOYMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,29 @@ Match `git_sha` against the commit you pushed — **not `built_at`**, which has
fresh while the host served stale code. The build log is the workflow run's log
in the repository's GitHub Actions tab (`gh run list --workflow=deploycse-test.yml`).

### Image dependency: ffmpeg (banner videos, #1468)

The image installs Debian's `ffmpeg` package (which also provides `ffprobe`) to
convert uploaded banner videos. It grows the image by about 560 MB, and the first build after
it was added is slow, because the new `apt` layer invalidates the cached `pip`
layer.

`/version.json` reports `"ffmpeg": true` when both tools are on the image's
PATH. `false` means the bind-mounted checkout is ahead of the image (or the
image was built without ffmpeg); the site still works, but banner video uploads
over 10 MB are refused, and smaller ones are served as uploaded, until the image
is rebuilt. Locally, rebuild with `./run-docker-local-dev.sh --build`.

After a deploy that changes this, check on the test server before tagging:

- `/version.json` shows the new `git_sha` and `"ffmpeg": true`;
- in `/admin`, upload a banner video: the banner list's **Video** column reads
`converting…`, then the converted size (reload to see it change);
- uploads of about 100, 200 and 250 MB succeed through the CSE proxy (its body
limit and timeouts are not in this repo), on campus and on a slower
connection. If they fail below 250 MB, lower `MAX_UPLOAD_BYTES` in
`website/utils/video_utils.py` or raise the Gunicorn worker timeout.

## Versioning

We use [Semantic Versioning](https://semver.org/) for production releases.
Expand Down
8 changes: 6 additions & 2 deletions makeabilitylab/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,15 @@ def parse_allowed_hosts(value, django_env):
CSRF_COOKIE_SECURE = True

# Makeability Lab Global Variables, including Makeability Lab version
ML_WEBSITE_VERSION = "2.35.5" # Keep this updated with each release and also change the short description below
ML_WEBSITE_VERSION_DESCRIPTION = "Each of the three login-throttle pages under Administration (Access attempts, logs, failures) now explains what it records and how to unlock an account."
ML_WEBSITE_VERSION = "2.36.0" # Keep this updated with each release and also change the short description below
ML_WEBSITE_VERSION_DESCRIPTION = "Banner videos of any size up to 250 MB and 60 seconds are converted on the server to a web-ready MP4 of 10 MB or less, and the hero carousel loads only the video it is showing (none for visitors who prefer reduced motion)."
DATE_MAKEABILITYLAB_FORMED = datetime.date(2012, 1, 1) # Date Makeability Lab was formed
MAX_BANNERS = 7 # Maximum number of banners on a page

# Banner video conversion (#1468) runs in a daemon thread after the admin save
# commits. settings_test.py turns this on so tests run the job inline.
BANNER_VIDEO_CONVERT_INLINE = False

# With the upgrade to Django 3.2, we now need to specify the default auto field for primary keys
# See:
# - https://docs.djangoproject.com/en/3.2/releases/3.2/#customizing-type-of-auto-created-primary-keys
Expand Down
4 changes: 4 additions & 0 deletions makeabilitylab/settings_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@
# state would leak between tests that share a username. The tests that cover
# the throttle itself (test_login_throttle.py) switch it back on.
AXES_ENABLED = False

# Run banner video conversions (#1468) inside the on_commit callback instead of
# a background thread, so a test can capture the callback and see the result.
BANNER_VIDEO_CONVERT_INLINE = True
Loading
Loading