Bootstrap CodePress Live Dev Server recipe + dev Dockerfile - #56
Open
codepress-dev[bot] wants to merge 1 commit into
Open
Conversation
Adds the repo-committed Live Dev Server artifacts so previews boot from this repo instead of a runtime heuristic: - .codepress/dev-server/recipe.json - one frontend entry for web/ (CRA, yarn, port 3000) - .codepress/dev-server/Dockerfile.web - thin dev-mode image (no baked node_modules, no source COPY) that binds 0.0.0.0 and wires HMR to env vars Node 18 is pinned because this app is Create React App 1.0.10 (webpack 2.6.1 / webpack-dev-server 2.5.0). Verified during bootstrap that yarn install --frozen-lockfile + react-scripts start compile and serve on Node 18.20.8, honor PORT, bind all interfaces, answer a preview-style Host header with HTTP 200, and expose a live /sockjs-node HMR endpoint. No staging backend URL was detected (repo has no .env*, CI, or deploy config), so staging_backend_url is intentionally omitted. No preview-CORS change was needed: the Django app in server/ serves the built React bundle same-origin and has no CORS surface or cross-origin caller. 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 files CodePress needs to run a live, hot-reloading preview of this project's React frontend. Until now the preview system would have had to guess how to start this app; from here on it reads the instructions committed in this PR, which means previews start the same way every time and can be adjusted by editing these files.
The only thing added is a new
.codepress/dev-server/folder — two config files. No application code, dependencies, or backend settings were touched, so nothing about how the app builds, deploys, or behaves today changes.Worth knowing: this project is on Create React App 1.0.10, which is about eight years old, so "will it even start on a modern machine?" was the real risk here rather than anything about the config format. Rather than assume, I installed the dependencies and actually booted the dev server to confirm it runs, serves pages under a preview-style web address, and has a working live-reload connection. It does.
Technical details
Adds
.codepress/dev-server/recipe.json(schema_version 1) with a single frontend entry forweb/, plus the matching thin dev-mode image at.codepress/dev-server/Dockerfile.web. Nothing else in the tree is modified.Recipe entry:
label: web,working_dir: web,framework: cra,package_manager: yarn,dev_port: 3000,install_command: yarn install --frozen-lockfile,dependency_manifests: ["web/yarn.lock"],system_packages: ["procps"],size: medium. Noprebuild_command— thepostbuildscript inweb/package.jsonis a production-build hook (it copiesbuild/intoserver/static/build/), not a dev prerequisite.Node 18 is pinned deliberately.
web/is Create React App 1.0.10 → webpack 2.6.1 / webpack-dev-server 2.5.0. Node 18 is the oldest LTS with a Debian bookworm image, so it is the most conservative base that still satisfies the full--bookwormrequirement (the runtime installs deps inside this image and needs the node-gyp toolchain that-slimstrips). I checked webpack 2.6.1'sWebpackOptionsDefaulterdirectly:output.hashFunctiondefaults tomd5, notmd4, so the usual OpenSSL 3ERR_OSSL_EVP_UNSUPPORTEDbreakage does not apply and no--openssl-legacy-providershim is baked in.Two CRA-1.x specifics a reviewer may want to scrutinize, both verified against the actual published package source rather than assumed:
react-scripts@1.0.10/config/webpackDevServer.config.jssetsdisableHostCheck: !proxy || DANGEROUSLY_DISABLE_HOST_CHECK === 'true'.web/package.jsondeclares noproxyfield, so host checking is off and the preview hostname is accepted. This is why noDANGEROUSLY_DISABLE_HOST_CHECKenv var is needed — if aproxyfield is ever added toweb/package.json, host checking flips on and this Dockerfile will need that var.react-dev-utils@3.0.2'swebpackHotDevClientbuilds its SockJS URL fromwindow.location(protocol/hostname/port) +/sockjs-node, so the websocket already follows the public preview origin through the proxy.WDS_SOCKET_PORTis still mapped fromCODEPRESS_HMR_CLIENT_PORTin the CMD for contract uniformity; react-scripts only reads it from 3.4+, so today it is an intentional no-op that starts working if CRA is upgraded.The CMD is
sh -c 'HOST="$CODEPRESS_BIND_HOST" WDS_SOCKET_PORT="$CODEPRESS_HMR_CLIENT_PORT" exec yarn start'— a wrapper rather than plainENVso the mappings resolve against runtime-injected values instead of being frozen at build time, andexecso signals reach react-scripts.BROWSER=noneis a staticENV. The image bakes yarn 1.22.22 via corepack (repo ships ayarn lockfile v1, nopackageManagerfield) so a cold MicroVM start doesn't fetch it from the registry first.staging_backend_urlis omitted, not empty. Exhaustive scan found no candidate at all: no.env*anywhere, no.github/workflows, novercel.json, nonext.config/vite.config, no.codepress/verify-staging/recipe.json. Per the "never persist a guess" rule the key is left out entirely. The frontend env-var prefill step was skipped as a consequence, andweb/srcreads no API base URL env var anyway.No preview-CORS change, deliberately. The Django app in
server/was detected, but it fails the cross-origin gate on both signals: it carries no CORS surface (nodjango-cors-headersinPipfile, nothing inINSTALLED_APPS/MIDDLEWARE, noCORS_*settings), and no same-repo frontend calls it cross-origin —web/srccontains nofetch/axios/XHR call whatsoever. The architecture is same-origin by design:postbuildcopies the CRA build intoserver/static/build/andserver/server/views.pyrendersindex.htmlfrom the catch-allurl(r'^', ...)route. Independently,server/has a single flatsettings.pywith no staging module and no.env.staging, so even an eligible backend would have been a report-only case for lack of a staging-scoped config path.No social-auth work. The runnable frontend has no sign-in flow —
App.jsroutes only/→Home. The backend exposesrest_auth/allauthendpoints but installs onlyallauth.account, with noallauth.socialaccountand no provider configured.samples/auth-web/contains a GitHub OAuth button but is dead sample code: it lives outsideweb/, is imported by nothing, and references a../../redux/authmodule that does not exist.Changes
Test plan
docker build -f .codepress/dev-server/Dockerfile.web -t drf-web-dev .— expect a clean build with no node_modules or source baked in.docker run --rm -p 3000:3000 -v "$PWD":/app -e PORT=3000 drf-web-dev(runyarn install --frozen-lockfileinweb/first, or let the runtime hydrate deps). ExpectCompiled successfully!in the logs.On Your Network:address, andcurl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:3000/should return 200.Invalid Host headerfailure mode):curl -s -H 'Host: 0123456789abcdef0123456789abcdef-a3bdc7594d3a2b9e.preview.codepress.dev' http://127.0.0.1:3000/ | grep -c 'Invalid Host header'should print 0, and the response should be the CRA index HTML with<title>React App</title>.curl -s http://127.0.0.1:3000/sockjs-node/infoshould return JSON containing"websocket":true.curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:3000/some/deep/routeshould return 200.python3 -c "import json;r=json.load(open('.codepress/dev-server/recipe.json'));print(r['schema_version'], r['frontends'][0]['dockerfile_path'])".Open items
docker buildin this environment (no Docker daemon available), so the Dockerfile itself is validated statically against the contract rather than built. What I did verify for real: on Node 18.20.8 I ranyarn install --frozen-lockfileand then the recipe's literaldev_commandwith the Dockerfile's exact env defaults — it compiled, honored a non-defaultPORT, bound all interfaces, returned HTTP 200 for a preview-styleHostheader, and served a live/sockjs-nodeendpoint. The firstdocker buildis the remaining unproven step.Authors
Generated with CodePress · View the chat session
Co-authored-by: dev@codepress.dev dev@codepress.dev