Bootstrap CodePress Live Dev Server recipe + dev Dockerfile - #39
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. - .codepress/dev-server/recipe.json: one frontend entry for web/ (CRA via react-scripts@1.0.10, Yarn 1 Classic, port 3000, procps). - .codepress/dev-server/Dockerfile.web: thin, dev-mode image on node:18-bookworm. Binds 0.0.0.0 through CODEPRESS_BIND_HOST, wires the HMR/bind env contract, bakes no node_modules and no source. Node is pinned to 18 because this app's 2017-era toolchain (webpack 2.6.1, webpack-dev-server 2.5.0, React 15) does not run on current Node majors and the repo pins no version itself. Corepack is deliberately left off so the base image's bundled Yarn 1 is used instead of a shim that downloads Yarn on every cold start. No staging backend URL was detected (no .env files, deploy config, or CI workflows), so staging_backend_url is omitted rather than guessed. The Django API in server/ was left untouched: it has no CORS surface and serves the built React app same-origin, so no preview-CORS allowance applies. 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 a preview would have had to guess how to start the app; from here on it boots from a recipe that lives in the repo, so previews are predictable and you can change how they start by editing these two files. Nothing about how the app runs today changes — the added files are only read by CodePress previews. Two things were deliberately left alone: no staging backend URL is recorded (the repo has no environment or deploy config to read one from, and guessing one would be worse than leaving it blank), and the Django API in
server/was not modified, because it serves the built React app on the same origin and has no cross-origin API surface that would need a preview allowance.Technical details
Adds
.codepress/dev-server/recipe.json(schema_version 1) with a single frontend entry forweb/, plus the matching dev-modeDockerfile.web. No existing file is touched.Frontend discovery.
web/is the only runnable frontend: CRA viareact-scripts@1.0.10,yarn.lockv1 →package_manager: yarn,install_command: yarn install --frozen-lockfile,dependency_manifests: ["web/yarn.lock"](per-app lockfile, not a root one),dev_port: 3000.samples/auth-web/is dead reference code — it imports paths that do not exist in this repo (../../redux/auth,../../../config/settings) and is not reachable fromweb/src, so it is not a frontend and its GitHub button does not make this a social-auth repo.web/public/index.htmlis a CRA template with%PUBLIC_URL%placeholders, i.e. build input, not a static site.prebuild_commandis empty: thepostbuildscript that copiesbuild/into Django's static dir is production-only, not a dev prerequisite.Node 18, on purpose. The repo pins no version (
engines/.nvmrcabsent) and this is a 2017-era toolchain (webpack 2.6.1, webpack-dev-server 2.5.0, React 15) that does not run on current Node majors, so the base is the oldest Debian-bookworm Node image rather than current LTS. It is the full image, not the trimmed variant, since dependencies install at runtime and need the node-gyp toolchain.Corepack is deliberately NOT enabled. The repo declares no
packageManagerfield, andnode:18-bookwormalready bundles Yarn 1.22. Enabling corepack would replace that binary with a shim that downloads Yarn from the public registry on first use, adding a network dependency to every cold start. A pinnednpm i -g yarn@1.22.22fallback runs only if the base image ever stops shipping Yarn.CRA specifics were verified against the pinned source (
react-scripts@1.0.10,react-dev-utils@3.0.2) rather than assumed:scripts/start.jsreadsHOSTandPORTfor bind, so the CMD mapsHOSTfromCODEPRESS_BIND_HOST— bind is 0.0.0.0, never loopback-only.config/webpackDevServer.config.jssetsdisableHostCheck: !proxy || DANGEROUSLY_DISABLE_HOST_CHECK === 'true'. Thispackage.jsonhas noproxyfield, so webpack-dev-server's DNS-rebinding host check is already off and the preview hostname is accepted; the env var is set explicitly anyway so a laterproxyaddition doesn't silently break previews.react-dev-utils/webpackHotDevClient.jsbuilds its SockJS URL fromwindow.location(protocol/hostname/port) at/sockjs-node, so HMR rides the public preview origin automatically. This version has noWDS_SOCKET_PORTsupport — it is passed for the uniform runtime contract and for a future react-scripts upgrade, and is inert today.BROWSER=nonestopsopenBrowserfrom trying to launch a browser inside the container;NODE_OPTIONS=--openssl-legacy-provideris appended (preserving any existing value) as insurance for this vintage webpack's hashing under OpenSSL 3.Image shape. Thin per contract: no
COPYof source or manifests, no bakednode_modules, no install layer, no CodePress binary.WORKDIR /appthen/app/web, with/app/web/node_modules/.bin:/app/node_modules/.binprepended to PATH as a backstop. The recipe'sdev_commandis byte-identical to the DockerfileCMDbody, so the container path and the direct MicroVM path behave the same — that equality is machine-checked.Why
server/was not edited. Preview CORS requires a backend that serves cross-origin browser clients.web/srcmakes zero API calls (nofetch, no axios, no absolute base URL, noprocess.envAPI var), andserver/server/settings.pyhas no CORS middleware and nodjango-cors-headersdependency — no allowlist to append to. The architecture is same-origin by design:postbuildcopies the CRA build intoserver/static/build/and Django's catch-all URL rendersindex.html. There is also no staging environment (singlesettings.py,DEBUG=True, no.env*, novercel.json, no CI workflows), and the staging-scoping rule forbids adding a preview allowance to shared/production config. Addingdjango-cors-headersplus middleware would be an unrequested architectural change to production-shared settings, so this is a report, not an edit.Changes
webfrontend entry (CRA, yarn, port 3000, procps, size medium)yarn startTest plan
python3 -c "import json;r=json.load(open('.codepress/dev-server/recipe.json'));print(r['schema_version'], r['frontends'][0]['label'], r['frontends'][0]['dev_port'])"→ prints1 web 3000.grep '^CMD' .codepress/dev-server/Dockerfile.webwith thedev_commandvalue in recipe.json.docker build -f .codepress/dev-server/Dockerfile.web -t ddi-web-dev .→ succeeds, anddocker run --rm ddi-web-dev yarn --versionprints a 1.22.x version (Yarn Classic, matching web/yarn.lock).docker run --rm -v "$PWD:/app" -e PORT=3000 -p 3000:3000 --entrypoint yarn ddi-web-dev install --frozen-lockfile, thendocker run --rm -v "$PWD:/app" -e PORT=3000 -p 3000:3000 ddi-web-dev. ExpectCompiled successfully!and the dev server listening on 0.0.0.0:3000 (not 127.0.0.1).web/src/containers/home/Home.js, save, and confirm the browser updates without a manual reload (the HMR socket connects at /sockjs-node on the page origin).cra, port 3000) and that the preview URL renders the app rather than failing a host check.Open items
staging_backend_urlto the recipe and it will be picked up.web/to call the Django API cross-origin from a preview,server/will need a staging-scoped CORS allowance for the preview origin — that means adding django-cors-headers and, ideally, a staging settings module to scope it to, which this run declined to introduce unprompted.samples/auth-web/is unreachable reference code, so no auth-relay wiring was added.Authors
Generated with CodePress · View the chat session