Bootstrap CodePress Live Dev Server recipe + dev Dockerfile - #33
Open
codepress-dev[bot] wants to merge 1 commit into
Open
Conversation
Author the committed Live Dev Server artifacts for the single runnable frontend in this repo (web/, Create React App via react-scripts 1.0.10): - .codepress/dev-server/recipe.json — schema_version 1 with one frontend entry (working_dir web, yarn, framework cra, dev_port 3000). - .codepress/dev-server/Dockerfile.web — thin dev-mode image on node:18-bookworm (pinned low deliberately: webpack 2.6.1 / webpack-dev-server 2.5.0 do not run reliably on recent Node majors). No baked node_modules, no source COPY; binds 0.0.0.0 and wires HMR/bind to the runtime env vars. No staging backend URL was confidently detected, so staging_backend_url is omitted. The Django app in server/ serves the React production build itself and carries no CORS allowlist or staging settings path, so no preview-CORS edit was made. 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 boot a live, hot-reloading preview of this project's React app (web/) on demand, instead of guessing how to run it each time. Two new files describe the frontend and how to start it in dev mode; nothing about how the app builds or deploys today changes, and no application code was touched. One thing worth knowing: the React app here is Create React App from 2017 (react-scripts 1.0.10), so the preview image deliberately pins an older Node version that this toolchain still runs on. Separately, the Django server in server/ was checked for preview-related CORS setup and needs none — it serves the React production build itself, so browser requests are same-origin, and it has no staging environment to scope such a change to.
Technical details
Adds
.codepress/dev-server/recipe.json(schema_version 1) with a single frontend entry and.codepress/dev-server/Dockerfile.web.Recipe entry —
label: web,working_dir: web,framework: cra,package_manager: yarn(fromweb/yarn.lock; nopackageManagerfield anywhere),install_command: yarn install --frozen-lockfile,dependency_manifests: ["web/yarn.lock"](the lockfile lives in the app dir, not the repo root),dev_port: 3000(CRA default; no port override in thestartscript),system_packages: ["procps"],size: medium.prebuild_commandis empty —postbuild(cp -r build/ ../server/static/build/) is a production-build concern and must not run for a dev preview.staging_backend_urlis omitted: there is no.env*, no.github/, novercel.json, and no.codepress/verify-staging/recipe.json, so there was no candidate — and therefore no frontend API-base env var to prefill either.Dockerfile — thin/toolchain-only per the contract: no
COPYof source or manifests, no bakednode_modules, deps arrive at runtime on the bind-mounted checkout at/app. FinalWORKDIR /app/web, with/app/web/node_modules/.binand/app/node_modules/.binprepended toPATHas a backstop.CMDroutes through the package manager (yarn start) and maps the runtime contract into CRA's own env names:HOST=$CODEPRESS_BIND_HOST, plusWDS_SOCKET_PORT/WDS_SOCKET_PROTOCOL.Two decisions worth a close look:
node:18-bookworm, not the current LTS.web/yarn.lockpinswebpack@2.6.1andwebpack-dev-server@2.5.0; those do not run reliably on recent Node majors. 18 is the newest Node with a-bookwormvariant that this 2017 toolchain still tolerates. If the preview fails to compile, this line is the first thing to revisit.window.location, so the HMR socket follows the public preview origin automatically once websocket upgrades are proxied —WDS_SOCKET_PORTonly exists from CRA 3.4 and is inert here. It is still exported so the image honors one uniform runtime contract.DANGEROUSLY_DISABLE_HOST_CHECK=trueandBROWSER=noneare set for the containerized dev server (host check would otherwise reject the preview hostname; CRA would otherwise try to launch a browser). Both are confined to this dev image.corepack prepare yarn@1.22.22 --activatebakes only the yarn binary so a cold start never fetches a package manager before booting. The single native dep in the lockfile isfsevents(macOS-only, skipped on Linux), so no apt library beyondprocpsis needed.Preview CORS and preview social auth were both evaluated and are deliberate no-ops — see Open items.
Changes
webfrontend entry (CRA, yarn, port 3000)Test plan
python3 -c "import json;print(json.load(open('.codepress/dev-server/recipe.json'))['frontends'])"— one entry, working_dirweb, dev_port 3000.docker build -f .codepress/dev-server/Dockerfile.web -t drf-web-dev .— it should build in seconds and contain no node_modules (docker run --rm drf-web-dev ls /appis empty).cd web && yarn install --frozen-lockfile && cd .., thendocker run --rm -p 3000:3000 -v "$PWD:/app" drf-web-dev. Wait forCompiled successfullyand open http://localhost:3000 — the React welcome page renders.web/src/containers/home/Home.js(change theWelcome to Reactheading) and confirm the browser updates without a manual reload.git diff master --stattouches only the two new files under .codepress/dev-server/.Open items
indexview (same-origin), the frontend in web/src makes no cross-origin API calls, and server/ has no django-cors-headers, no CORS allowlist, and no staging settings module or .env.staging to scope a staging-only allowance to. If a separately deployed API is ever introduced that previews call cross-origin, that API's own repo needs this bootstrap run against it.Authors
Generated with CodePress · View the chat session
Co-authored-by: dev@codepress.dev dev@codepress.dev