Skip to content

About

Previews of the templates proposed to the TemplateFlow Archive

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

5 Commits

Folders and files

Repository files navigation

TemplateFlow intake previews

Previews of the templates proposed to the TemplateFlow Archive, published at https://www.templateflow.org/intake-previews/ while they are under review.

A template is proposed with a pull request on templateflow/templateflow that adds tpl-<ID>.toml, naming the contributor's DataLad dataset (github.com/<user>/tpl-<ID>). For every open proposal, this repository's workflow:

  1. clones the dataset with git (without its annexed content);
  2. finds where each annexed file can be downloaded: the URLs registered in the dataset (git annex registerurl, addurl, datalad addurls), or the OSF node it was uploaded to;
  3. downloads the files the viewer needs, checks each against its annex key (size and checksum), and publishes them to the previews S3 bucket;
  4. builds the site with the TemplateFlow gallery (the same profile pages as https://www.templateflow.org/templates/), deploys it to GitHub Pages, and comments on each pull request with its preview and anything missing.

Runs are triggered by the intake pull requests (through a GitHub App), daily, and by hand. A run stops early when no proposal changed since the deployed site (manifest.json).

Security model

Submissions are untrusted.

  • Nothing from a submission runs: no DataLad, no git-annex, no special remotes. Git runs with hooks, local transports, submodules and LFS disabled.
  • Symlinks are never followed: annexed files are recognized by their link text, and text is read from regular files only, so a submission cannot get files from the build machine published.
  • Downloads are restricted: https only, to public addresses (each host is resolved and checked, and the connection pinned to the checked address, including through redirects). Every file must match the size and checksum in its annex key. Per-file (2 GB) and per-template (5 GB) caps apply.
  • Only expected files are published: data and small text files, with an allowlisted content type (never HTML) and Content-Disposition: attachment. Metadata are escaped in the pages, and comments quote file names and errors as code.
  • Uploads need a human: the workflow first plans, without credentials, what changed since the deployed site (shown in the run's summary). The only job holding AWS credentials runs in the previews-upload environment, which waits for a reviewer's approval, and uploads exactly the approved plan: if a submission changed meanwhile, it stops.
  • Only the previews bucket: the organization's AWS keys may reach other buckets (the Archive's), so the code refuses any bucket but templateflow-previews and any key outside a tpl-<ID>/ folder. Comments go through the App only.

Setup

S3 bucket templateflow-previews (us-east-1)

Allow public bucket policies on it (Block Public Access), then:

{"Version": "2012-10-17", "Statement": [{"Sid": "PublicRead", "Effect": "Allow",
  "Principal": "*", "Action": "s3:GetObject",
  "Resource": "arn:aws:s3:::templateflow-previews/*"}]}

CORS (as the Archive's bucket, so the viewer can read ranges):

{"CORSRules": [{"AllowedOrigins": ["*"], "AllowedMethods": ["GET", "HEAD"],
  "AllowedHeaders": ["*"], "MaxAgeSeconds": 86400,
  "ExposeHeaders": ["Content-Length", "Content-Range", "Accept-Ranges", "ETag"]}]}

Lifecycle: abort incomplete multipart uploads after 1 day. Previews of closed or merged pull requests are deleted by the workflow.

GitHub App and settings

  • A GitHub App (e.g. "TemplateFlow intake bot"), installed on templateflow/templateflow and templateflow/intake-previews, with permissions Actions: read and write (to dispatch this workflow) and Pull requests: read and write (to comment).
  • This repository:
    • environment previews-upload with required reviewers (the people allowed to approve uploads) and deployments limited to the main branch;
    • variables PREVIEWS_BUCKET (templateflow-previews), INTAKE_APP_CLIENT_ID (the App's Client ID), and PREVIEW_COMMENTS (true once comments should be posted);
    • secrets INTAKE_APP_KEY, and AWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY (the organization's, allowed to write the previews bucket);
    • Pages source "GitHub Actions".
  • templateflow/templateflow: variable INTAKE_APP_CLIENT_ID and secret INTAKE_APP_KEY, for its intake-preview.yml (or define both once at the organization level, for these two repositories).

Local runs

Publish to a local folder instead of S3, then serve both folders:

uv sync
GH_TOKEN=$(gh auth token) uv run python -m intake -v build out/site --work out/work \
    --data-dir out/data --data-base-url http://127.0.0.1:8000/data --force
python3 -m http.server -d out 8000   # http://127.0.0.1:8000/site/

Tests: uv run pytest.

About

Previews of the templates proposed to the TemplateFlow Archive

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages