Bootstrap CodePress Live Dev Server recipe + dev Dockerfiles - #46
Open
codepress-dev[bot] wants to merge 1 commit into
Open
Conversation
Author the committed Live Dev Server artifacts for this repo so previews boot from repo-owned files instead of a runtime heuristic. Discovery found one runnable frontend (web/, Create React App via react-scripts 1.0.10, Yarn Classic, port 3000) and one backend (server/, Django 1.11 + DRF). - .codepress/dev-server/recipe.json: single "web" frontend entry. - .codepress/dev-server/Dockerfile.web: thin, toolchain-only dev image on the full node:22-bookworm base. Binds 0.0.0.0, installs procps, pins Yarn Classic via corepack, bakes no node_modules and no source. react-scripts reads the bind address from HOST rather than HOSTNAME, so the CMD maps CODEPRESS_BIND_HOST onto HOST at run time; that keeps a runtime override working instead of freezing it in at build time. No preview-CORS change: the Django app has no CORS surface and no cross-origin caller. web/'s postbuild copies the React build into server/static/build/ and Django's catch-all route renders it, so the app and API share one origin. The repo also has no staging-only config path, which would make a CORS edit report-only regardless. No staging backend URL was detected, so staging_backend_url is omitted rather than guessed. 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 the Live Dev Server for this repo, so CodePress can spin up a live, hot-reloading preview of the React app straight from files committed here instead of guessing how to run it at boot time.
Exploring the repo turned up one runnable frontend — the Create React App in
web/— plus the Django API inserver/. This PR adds two files under.codepress/dev-server/describing how to build and start that frontend. Nothing about how the app currently runs for you locally changes; these files are only read by CodePress previews.Worth flagging:
web/pins react-scripts 1.0.10 (from 2017), which is old enough that "will it even start on a modern Node?" was a real risk. Rather than assume, I installed the dependencies and actually booted the dev server against the exact settings in this Dockerfile — it compiles and serves cleanly. Details in the test plan below.No CORS changes were needed. Your React app and Django API are served from the same origin (
web'spostbuildcopies the build intoserver/static/build/, and Django's catch-all route renders it), so a preview has no cross-origin call to fail. Nothing was changed inserver/.Technical details
.codepress/dev-server/recipe.json—schema_version: 1with a single frontend entry:label: web,working_dir: web,dev_command: yarn start,framework: cra,package_manager: yarn,install_command: yarn install --frozen-lockfile,dependency_manifests: ["web/yarn.lock"](a per-app lockfile — there is no root one),dev_port: 3000,system_packages: ["procps"],size: small..codepress/dev-server/Dockerfile.web— thin, toolchain-only image on the fullnode:22-bookwormbase (pulled from the public-ECR mirror). No bakednode_modules, no sourceCOPY; deps arrive at runtime on the bind-mounted checkout.Decisions worth a look:
Node 22, not an era-appropriate old Node. react-scripts 1.0.10 is webpack 3, so I checked rather than guessed. A clean
yarn install --frozen-lockfileplus a dev-server boot both succeed on Node 22 (also verified on Node 18). I initially expected to needNODE_OPTIONS=--openssl-legacy-providerfor the classic OpenSSL 3 hash failure, tested without it, and confirmed it is not required — webpack 3 hashes with md5, not the md4 that OpenSSL 3 moved to the legacy provider. So the flag is deliberately absent rather than cargo-culted in.HOST, notHOSTNAME. react-scripts reads its bind address fromHOST; the platform contract suppliesCODEPRESS_BIND_HOST. TheCMDmaps one onto the other at run time (HOST="${CODEPRESS_BIND_HOST:-0.0.0.0}" ... yarn start) rather than freezing it into anENV, so a runtime override is still honored. Verified: overridingPORT=4500moved the server to 4500.WDS_SOCKET_PORTis mapped but is a documented no-op here. I read the actual react-dev-utils 3.xwebpackHotDevClientshipped by this version: it builds its SockJS URL fromwindow.location, so behind the preview proxy HMR already connects towss://<preview-host>/sockjs-nodeon 443 with no wiring.WDS_SOCKET_PORTonly exists in react-scripts 3.4+. It is mapped for contract uniformity and takes effect as written if react-scripts is ever upgraded; the comment in the Dockerfile says so rather than implying it does something today.DANGEROUSLY_DISABLE_HOST_CHECK=trueis defensive, not currently load-bearing. This version computesdisableHostCheck: !proxy || DANGEROUSLY_DISABLE_HOST_CHECK === 'true'.web/package.jsonsets noproxy, so the host check is already off and a request carrying a previewHostheader returns 200 today. Setting it keeps previews working if someone later adds aproxyfield.system_packagesis justprocps. The only node-gyp package inweb/yarn.lockisfsevents, which is darwin-only and skipped on Linux, so nothing builds from source and no apt library is needed.staging_backend_urlis omitted. There is no.env*, no CI workflow, novercel.json, and noverify-stagingrecipe in the tree — zero candidates, so nothing was persisted rather than a guess. Consequently the frontend env-var prefill step was skipped too.Preview CORS: correctly a no-op. The gate needs a backend that serves cross-origin browser clients.
server/has nodjango-cors-headersdependency, nocorsheadersinINSTALLED_APPS/MIDDLEWARE, and no CORS setting anywhere;web/srcmakes no API calls at all and reads no absolute API base URL. Independently, the repo has a singlesettings.pywith no staging module, no settings package, and no.env.staging— no staging-only config path — so even had the gate passed, this would have been report-only rather than an edit to production config.Social auth: not applicable.
samples/auth-web/contains a GitHub OAuth button, but it is detached reference code — it has nopackage.json, is imported by nothing, and imports modules that do not exist in this repo (../../../config/settings,../../redux/auth,../header/Header) plus deps absent fromweb/package.json. It cannot compile and is not part of a runnable frontend, so the preview social-auth skill was not invoked.Changes
webCRA frontend (yarn, port 3000, per-app lockfile fingerprint)Test plan
python3 -c "import json;print(json.load(open('.codepress/dev-server/recipe.json'))['frontends'][0])"— expect one entry with working_dirweb, dev_port 3000, frameworkcra.cd web && yarn install --frozen-lockfile, thenHOST=0.0.0.0 PORT=3000 BROWSER=none yarn starton Node 22. ExpectCompiled successfully!.curl -o /dev/null -w '%{http_code}\n' http://127.0.0.1:3000/→ 200, and that the HTML containsid="root".curl -o /dev/null -w '%{http_code}\n' -H 'Host: 0123456789abcdef0123456789abcdef-8d7329d07b7e6057.preview.codepress.dev' http://127.0.0.1:3000/→ 200.curl http://127.0.0.1:3000/sockjs-node/info→ JSON with"websocket":true.PORT=4500and confirm the server binds 4500 instead of 3000.Open items
yarn install --frozen-lockfileand the Dockerfile's literal CMD string, run under its exact ENV block on Node 22. The first real image build will exercise the apt/corepack layers./sockjs-nodeendpoint responds and the client derives its URL fromwindow.location(confirmed by reading the shipped react-dev-utils 3.x source). An actual browser hot-reload through the proxy is worth eyeballing on the first preview.Generated with CodePress