Skip to content

Use USE_LOCAL_ASSETS env var to determine path for assets - #16256

Merged
jonathonherbert merged 8 commits into
mainfrom
jsh/use-env-to-determine-public-path
Jul 8, 2026
Merged

jonathonherbert merged 8 commits into
mainfrom
jsh/use-env-to-determine-public-path

Conversation

@jonathonherbert

@jonathonherbert jonathonherbert commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

What does this change?

Amend decidePublicPath to use the environment variable USE_LOCAL_ASSETS to determine the path for assets, rather than a combination of the NODE_ENV variable, and the hostname.

Why?

The hostname for using live harnesses to work on content atoms locally (docs) is always localhost. At the moment, decidePublicPath sees that hostname, and makes asset paths relative as a result — but because DCR isn't running locally, those paths don't resolve to assets. The hope is that this change accommodates both the workflows that require local assets (make dev, make prod-local, CI), and the workflows that require hosted assets (code, production, live harnesses).

Here's a table that maps out the old way, the new way, and the result, against all the workflows we know of (I've spoken to @arelra and @Jakeii). If other workflows exist, this PR may impact them, too — so please let me know if there's a row missing.

NODE_ENV (old) hostname (old) USE_LOCAL_ASSETS (new) Old assets path New assets path
local development localhost true /assets/ /assets/
prod-local production localhost true /assets/ /assets/
ci production localhost true /assets/ /assets/
code production code.dev-theguardian.com unset ${frontendAssetsFullURL}assets/ ${frontendAssetsFullURL}assets/
prod production theguardian.com unset ${frontendAssetsFullURL}assets/ ${frontendAssetsFullURL}assets/
remote-preview production localhost unset /assets/ ${frontendAssetsFullURL}assets/

How to test

  • CI passes
  • Running DCR locally (make dev) with frontend gives local asset paths
  • Running DCR locally (make prod-local) with frontend gives local asset paths
  • Running DCR in CODE works as expected
  • Running live harnesses with Preview works as expected

Screenshots

N/A

@github-actions

Copy link
Copy Markdown

Hello 👋! When you're ready to run Chromatic, please apply the run_chromatic label to this PR.

You will need to reapply the label each time you want to run Chromatic.

Click here to see the Chromatic project.

@jonathonherbert jonathonherbert added the maintenance Departmental tracking: maintenance work, not a fix or a feature label Jun 24, 2026
@jonathonherbert jonathonherbert added this to the Interactives milestone Jun 24, 2026
@jonathonherbert
jonathonherbert requested a review from a team as a code owner June 24, 2026 11:53
@github-actions

github-actions Bot commented Jun 24, 2026 •

Copy link
Copy Markdown

@jonathonherbert
jonathonherbert force-pushed the jsh/use-env-to-determine-public-path branch from 3360067 to 0c9e5ce Compare June 25, 2026 10:26
@jonathonherbert jonathonherbert added the run_chromatic Runs chromatic when label is applied label Jun 25, 2026
@github-actions github-actions Bot removed the run_chromatic Runs chromatic when label is applied label Jun 25, 2026
@jonathonherbert jonathonherbert changed the title Use CI and NODE_ENV env vars to determine path for assets Use USE_LOCAL_ASSETS env var to determine path for assets Jun 25, 2026
@jonathonherbert
jonathonherbert force-pushed the jsh/use-env-to-determine-public-path branch from 106d749 to 0e07458 Compare June 25, 2026 16:48
@jonathonherbert jonathonherbert added the run_chromatic Runs chromatic when label is applied label Jun 26, 2026
@github-actions github-actions Bot removed the run_chromatic Runs chromatic when label is applied label Jun 26, 2026
Comment thread .github/workflows/playwright.yml Outdated
env:
NODE_ENV: production
NODE_ENV: 'production'
USE_LOCAL_ASSETS: 'true'

@arelra arelra Jun 30, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the NODE_ENV variable here determines which port playwright uses i.e. 9000

const isDev = process.env.NODE_ENV !== 'production';
/**
* The server port for local development or CI
*/
export const PORT = isDev ? 3030 : 9000;
export const ORIGIN = `http://localhost:${PORT}`;

I don't think these env variables on the GHA runner will make it to the container that the CI playwright tests run against?

Do we need to add USE_LOCAL_ASSETS=true to Containerfile ?

ENV DISABLE_LOGGING_AND_METRICS=true
ENV NODE_ENV=production

@jonathonherbert jonathonherbert Jul 2, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, we don't use the container in production — so it's safe to add this?

Edit: the bundle doesn't look like it's build in the container, it's copied in, so we'll need to pass this in on build, if that's possible — run out of time tonight, but will pursue.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, after a somewhat fragmented series of commits to better understand how this works, I think I now get it — we're not bundling at all in the container, we're copying in JS and running it, and so env vars are respected in that context. Verified by building locally with make riffraff-bundle, creating the container, and running — I can see local asset paths:

Screenshot 2026-07-06 at 15 01 20

I think I'm confident enough to 🚢 this now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Change is 76e0de0)

@jonathonherbert
jonathonherbert force-pushed the jsh/use-env-to-determine-public-path branch 2 times, most recently from d541cb9 to 8741e5b Compare July 6, 2026 13:54
@github-actions

github-actions Bot commented Jul 6, 2026 •

Copy link
Copy Markdown

@jonathonherbert
jonathonherbert force-pushed the jsh/use-env-to-determine-public-path branch 2 times, most recently from b73a281 to 76e0de0 Compare July 6, 2026 14:33
@jonathonherbert
jonathonherbert force-pushed the jsh/use-env-to-determine-public-path branch from 76e0de0 to 10c14f8 Compare July 7, 2026 14:35
@arelra arelra added the run_chromatic Runs chromatic when label is applied label Jul 8, 2026
@arelra

arelra commented Jul 8, 2026

Copy link
Copy Markdown
Member

Thanks for stellar tidy up ✨

Latest changes approved ✅

@github-actions github-actions Bot removed the run_chromatic Runs chromatic when label is applied label Jul 8, 2026
@jonathonherbert
jonathonherbert merged commit d55fe31 into main Jul 8, 2026
36 checks passed
@jonathonherbert
jonathonherbert deleted the jsh/use-env-to-determine-public-path branch July 8, 2026 10:57
@gu-prout

gu-prout Bot commented Jul 8, 2026

Copy link
Copy Markdown

Overdue on PROD (merged by @jonathonherbert 30 minutes and 8 seconds ago) What's gone wrong?

@gu-prout

gu-prout Bot commented Jul 8, 2026

Copy link
Copy Markdown

Seen on PROD (merged by @jonathonherbert 40 minutes and 10 seconds ago) Please check your changes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance Departmental tracking: maintenance work, not a fix or a feature Seen-on-PROD

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants