Bootstrap CodePress Live Dev Server recipe + dev Dockerfile - #55
Open
codepress-dev[bot] wants to merge 1 commit into
Open
Conversation
Author the committed Live Dev Server artifacts so previews boot from repo-owned files instead of a runtime heuristic. Discovered one runnable frontend: the create-react-app app in web/ (react-scripts 1.0.10 / webpack 2.6.1, yarn classic lockfile). Dockerfile.web pins node:18-bookworm -- the oldest Debian-bookworm Node image and the closest match to this 2017-era toolchain. Verified on Node 18.20 / OpenSSL 3 that the app installs with `yarn install --frozen-lockfile`, boots, binds 0.0.0.0, serves HTTP 200 under a preview Host header, and exposes a live /sockjs-node HMR endpoint. Notes on deliberate choices: - No --openssl-legacy-provider: webpack 2 hashes with md5, not md4, so OpenSSL 3 does not break it (confirmed by running the dev server). - Corepack is not enabled: the repo declares no `packageManager`, so a corepack shim would try to fetch yarn from the network on cold start. - No HMR client-port wiring needed: react-dev-utils 3.0.2 builds its SockJS URL from window.location, so it follows the preview origin. No backend CORS change: the Django API in server/ is same-origin only (web/ makes no API calls and its build is served by Django), and the repo has no staging config path to scope an allowance to. Co-authored-by: dev@codepress.dev <dev@codepress.dev>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This sets up live previews for this repo. Until now, CodePress had to guess how to start your frontend; this PR adds two small config files that tell it exactly how, so a preview of the React app in
web/boots reliably and updates as you edit.The only runnable frontend here is the create-react-app in
web/. It's a 2017-era toolchain (react-scripts 1.0.10 on webpack 2), which is exactly the kind of setup a generic heuristic gets wrong — so rather than guessing, I actually installed and ran it to confirm the image will work: it boots, serves the app under a preview address, and its hot-reload connection comes up.Nothing about how your app runs changes. These files are only read by CodePress previews; your existing
yarn startand production build are untouched.One thing I deliberately did not do: I left your Django backend alone. Previews sometimes need a CORS tweak so the previewed frontend can call the API, but that doesn't apply here —
web/makes no API calls, and in production Django serves the React build itself, so it's same-origin. There's also no staging environment to scope such a change to. Details in the open items below.Technical details
Adds
.codepress/dev-server/recipe.json(the contract the Live Dev Server reads) and.codepress/dev-server/Dockerfile.web(a thin, dev-mode, toolchain-only image). No application code is touched.Discovery. One runnable frontend:
web/—framework: cra,package_manager: yarn(yarn lockfile v1, nopackageManagerfield),dev_port: 3000,dependency_manifests: ["web/yarn.lock"],install_command: yarn install --frozen-lockfile,size: small. No prebuild step (postbuildis a production-only hook that copies the build intoserver/static/build/, so it stays out ofdev_command).samples/auth-web/is loose reference snippets — nopackage.json/index.html, not imported byweb/src— so it is not a frontend.Why
node:18-bookworm. This was the main judgement call.-bookwormtags start at Node 18, which is also the closest available match to a react-scripts 1.0.10 / webpack 2.6.1 dependency tree. Rather than assume it works, I ran it: installedweb/'s deps under Node 18.20.8 (OpenSSL 3.0.16 — identical to the image) withyarn install --frozen-lockfile, started the dev server, and verified HTTP 200 on/, HTTP 200 on a non-loopback interface (proving the0.0.0.0bind), and/sockjs-node/inforeturning{"websocket":true}.Three findings from that testing changed the output, and are each worth a look:
NODE_OPTIONS=--openssl-legacy-provider. The reflex for webpack-on-OpenSSL-3 is the legacy-provider flag, but that's a webpack 4+ problem (md4). webpack 2.6.1 hashes with md5, which OpenSSL 3 still provides. I confirmed the dev server compiles cleanly without the flag, so it isn't set — one less bit of unexplained config.packageManager, socorepack enablewould replace the yarn 1.22 already baked into the node image with a shim that resolves a yarn release over the network on first run — a cold-start failure mode for no benefit.webpackHotDevClientbuilds its SockJS URL fromwindow.location(verified in the package source), so it follows the preview origin towss/443 on its own.WDS_SOCKET_PORTis still mapped fromCODEPRESS_HMR_CLIENT_PORTin theCMD; it is inert on this pinned version and only takes effect if react-scripts is upgraded to >= 3.4. The Dockerfile comment says so explicitly so it doesn't read as working config.DANGEROUSLY_DISABLE_HOST_CHECK=trueis set defensively: webpack-dev-server 2.5.0 does havecheckHost, and react-scripts only auto-disables it while noproxykey exists inweb/package.json. That's true today (hence the verified 200 under a previewHostheader), but adding aproxylater would otherwise silently break previews with "Invalid Host header".The image satisfies the thin-image contract: full
-bookwormbase (not-slim, so runtime node-gyp installs have a toolchain), no bakednode_modules, no sourceCOPY,procpsinstalled,WORKDIR /app→/app/web, and bind/HMR driven entirely byCODEPRESS_BIND_HOST/PORT/CODEPRESS_HMR_*with nolocalhostliterals.staging_backend_urlis omitted — no.env*, no CI workflows, novercel.json, no verify-staging recipe, so there was no candidate. Per the never-persist-a-guess rule the key is absent rather than empty, and no Live Dev Server env var was prefilled (web/reads no API-base env var).No backend CORS edit. Django is in
server/, but the gate fails on two independent counts: it has no cross-origin surface (nodjango-cors-headersanywhere, andweb/srcissues zero API calls —redux/example.jsis a boilerplate reducer, not an auth flow), and there is no staging-only config path to scope an allowance to (a singleserver/server/settings.py, no settings package, no env gating). Adding CORS would have meant introducing a dependency and inventing a staging environment, which is well outside an append-only allowance — so this is correctly report-only.No social-auth work. No runnable frontend has social or enterprise sign-in (
web/has a single/route and no sign-in UI), so the preview social-auth audit was not applicable.Changes
Test plan
docker build -f .codepress/dev-server/Dockerfile.web -t ddi-web .— it should succeed and bake no node_modules.web/, runyarn install --frozen-lockfileon Node 18. It should complete without node-gyp errors (fsevents is darwin-only and is skipped on linux).docker run --rm -p 3000:3000 -v "$PWD":/app ddi-web. Expect create-react-app's "Compiled successfully!".curl -o /dev/null -w '%{http_code}\n' http://127.0.0.1:3000/returns 200.curl -o /dev/null -w '%{http_code}\n' -H 'Host: 0123456789abcdef0123456789abcdef-de116f94b7ab06ad.preview.codepress.dev' http://127.0.0.1:3000/returns 200.curl http://127.0.0.1:3000/sockjs-node/inforeturns JSON containing "websocket":true.web/src/containers/home/Home.js, and verify the browser hot-reloads without a manual refresh.git diff --stat origin/master...HEADshould list only the two files under .codepress/dev-server/.Open items
Authors
Generated with CodePress · View the chat session
Co-authored-by: dev@codepress.dev dev@codepress.dev