Bootstrap CodePress Live Dev Server recipe + dev Dockerfile - #38
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. Discovery found one runnable frontend (web/, create-react-app on react-scripts 1.0.10 + yarn classic) and one backend (server/, Django 1.11) that is same-origin by construction: the catch-all URL renders the copied React build and there is no CORS surface or cross-origin caller, so no preview-CORS edit applies. - .codepress/dev-server/recipe.json: schema_version 1 with the web frontend entry (working_dir, dev_command, cra/yarn, dev_port 3000, install + dependency_manifests, procps). - .codepress/dev-server/Dockerfile.web: thin dev-mode image on the full node:18-bookworm base, binds via CODEPRESS_BIND_HOST, wires HMR to the CODEPRESS_HMR_* env vars, bakes no deps or source. No staging_backend_url: the repo declares no staging backend anywhere, so nothing was persisted rather than guessing. 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 a CodePress preview can boot the React app on its own instead of guessing how to run it. Two small files are added under
.codepress/dev-server/— a recipe describing the one runnable frontend (web/), and a dev-mode Dockerfile that runs it with hot reload. Nothing in the app itself changes; these are additive config files only.Two things this deliberately did NOT do, both to avoid guessing. First, no staging backend URL was recorded: the repo declares one nowhere (no
.env.staging,.env.example, deploy workflow, or proxy config), and recording a wrong or production URL would point live previews at the wrong data. Second, no CORS change was made to the Django backend inserver/— it is same-origin by construction (Django's catch-all URL renders the copied React build, and no CORS package or cross-origin caller exists), so previews have no cross-origin API call to unblock. If this app later grows a browser API call fromweb/to a separately-hosted Django, that is when preview CORS becomes relevant — and it would need a staging settings path to scope it to, which this repo does not have yet (see Open items).Technical details
Discovery. One runnable frontend:
web/— create-react-app (react-scripts1.0.10,webpack2.6.1,webpack-dev-server2.5.0 perweb/yarn.lock), yarn classic (# yarn lockfile v1),startscript, no--portoverride → CRA default 3000.samples/auth-web/is not a frontend (nopackage.json, no framework marker, and its imports —../../redux/auth,../header/Header,../../../config/settings, plusreact-spinkit/query-string/secure-random— resolve to nothing in this repo), so it is excluded.web/public/index.htmlis the CRA template (%PUBLIC_URL%), not a servable static site.recipe.json.schema_version: 1, onefrontends[]entry:working_dir: "web",framework: "cra",package_manager: "yarn",install_command: "yarn install --frozen-lockfile",dependency_manifests: ["web/yarn.lock"](the per-app lockfile — this is not a workspace, there is no root manifest),dev_port: 3000,system_packages: ["procps"],size: "medium". Noprebuild_command: the only extra lifecycle script ispostbuild, which copies a production build intoserver/static/build/and has no place in a dev-server run.staging_backend_urlis omitted entirely rather than written empty.Dockerfile.web. Thin, toolchain-only: noCOPY, no bakednode_modules(the runtime hydrates deps onto the bind-mounted checkout at/app), no CodePress binary. Three decisions worth a look:node:18-bookworm, not the current LTS. This is a 2017 toolchain and the repo pins no Node version. Node 18 is the oldest bookworm-based official image, so it is the closest available match. Node 20/22 were considered and rejected as more removal surface for no benefit. The OpenSSL-3md4hash failure that breaks CRA on modern Node does not apply here — that is a webpack 4 default, and this app is on webpack 2, which hashes with md5. I also checked the other classic age-related breakers:graceful-fsresolves to 4.1.11 (not the 3.x that throwsprimordials is not defined), there is nonode-sass, and the only native dep,fsevents@1.1.2, is darwin-only and optional so yarn skips it on linux. The full-bookwormvariant (never-slim) is used because the runtime dependency install needs the node-gyp toolchain.react-dev-utils@^3builds its SockJS URL fromwindow.location, so the HMR socket already rides the preview origin behind the proxy — no client-port flag exists in this version. The fourCODEPRESS_*env vars are still declared for the uniform runtime contract, andWDS_SOCKET_PORTis mapped fromCODEPRESS_HMR_CLIENT_PORTin theCMDso the wiring is already correct ifreact-scriptsis ever upgraded to a version that honors it (it is inert today).DANGEROUSLY_DISABLE_HOST_CHECK=true. webpack-dev-server 2.5.0 has the DNS-rebinding host check, which would otherwise reject the preview proxy'sHostheader. This is the CRA counterpart to theserver.allowedHostssetting Vite repos get, and it lives only in this dev image — it takes no part inreact-scripts build.Bind is
CODEPRESS_BIND_HOST(default0.0.0.0) rather than the ambientHOSTNAME;ENV PATHprepends/app/web/node_modules/.binand/app/node_modules/.binas a backstop, and theCMDstill routes through yarn rather than invokingreact-scriptsbare. Corepack pre-activatesyarn@1.22.22at build time so a cold start never downloads a package manager.Validation. Static contract checks only, all passing: recipe parses at
schema_version 1with every required field,dockerfile_pathexists, the image is dev-mode/thin/0.0.0.0-bound with the four env vars and nolocalhostliteral,install_commandis plain argv and notnpm ci, anddependency_manifestsresolves on disk. Thedev_commandstring was executed throughsh -cwith the env prefix swapped toenvto prove the quoting appliesHOST/WDS_SOCKET_PORT/BROWSER/DANGEROUSLY_DISABLE_HOST_CHECKcorrectly. Docker is not available in this session, so the image was not built and the dev server was not booted — that is the main thing to verify below.Changes
.codepress/dev-server/recipe.json— schema_version 1 with one frontend entry forweb/(cra, yarn, port 3000).codepress/dev-server/Dockerfile.web— thin dev-mode image on node:18-bookworm, binds 0.0.0.0, HMR wired to the CODEPRESS_* env varsstaging_backend_url— no staging backend is declared anywhere in the reposerver/is same-origin (catch-all renders the copied React build; no CORS package, no cross-origin caller)Test plan
docker build -f .codepress/dev-server/Dockerfile.web -t drl-web-dev .— verify it completes (this is the step that was not runnable in the bootstrap session).docker run --rm -p 3000:3000 -v "$PWD":/app drl-web-dev sh -c 'yarn install --frozen-lockfile && HOST=0.0.0.0 WDS_SOCKET_PORT=443 BROWSER=none DANGEROUSLY_DISABLE_HOST_CHECK=true yarn start'— expectCompiled successfullyand a listener on 0.0.0.0:3000.web/src/containers/home/Home.jsand verify the browser updates without a manual refresh./sockjs-nodeconnection succeeding rather than erroring).cd web && yarn buildstill succeeds andpostbuildcopies intoserver/static/build/.Open items
FROMline in.codepress/dev-server/Dockerfile.web.server/server/settings.pywithDEBUG = Truehardcoded, no settings package, no.env.staging, no deploy workflow). That is why no staging backend URL was recorded and why preview CORS would be report-only even if it were needed: there is no staging-only config path to scope such a change to, and it must never be added to production config.server/server/settings.pycarries a hardcodedSECRET_KEYandDEBUG = TruewithALLOWED_HOSTS = []. Untouched by this PR and out of its scope, but worth flagging if this repo is ever deployed beyond local use.react-scripts1.0.10 (2017). This PR deliberately accommodates it rather than upgrading it, but the age is the main risk to preview reliability — a CRA upgrade (or a migration to Vite) would let the dev image use a current Node LTS and drop the host-check escape hatch.Authors
Generated with CodePress · View the chat session