Bootstrap CodePress Live Dev Server recipe + dev Dockerfile - #43
Open
codepress-dev[bot] wants to merge 1 commit into
Open
Conversation
Author committed Live Dev Server artifacts so previews boot from the repo instead of a runtime heuristic. - .codepress/dev-server/recipe.json: schema_version 1 with the single runnable frontend (web/, create-react-app, yarn, port 3000). - .codepress/dev-server/Dockerfile.web: thin dev-mode image that binds 0.0.0.0, installs procps, and wires HMR/bind to the runtime env contract. Pinned to node:16-bookworm because react-scripts 1.0.10 resolves to webpack 2.6.1, which hashes with md4; OpenSSL 3 (Node 17+) removed md4, so a newer base fails to start. Corepack is left disabled since the repo declares no packageManager field and yarn 1.x already ships in the base image. No staging_backend_url: the repo declares no staging/env/CI backend URL, so nothing was persisted rather than guessing. No preview-CORS edit: the Django app in server/ serves the built React bundle same-origin and has no CORS surface (no django-cors-headers, no CORS settings), and the web/ frontend makes no cross-origin API calls, so there is nothing to allow. 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 django-react-intro so CodePress previews of this repo boot from files committed here rather than guessing at runtime. It adds a small
.codepress/dev-server/folder describing the one runnable frontend in this repo — the create-react-app inweb/— plus the container recipe used to run it with hot reloading. Nothing about how the app builds or behaves changes; these files are only read when a CodePress preview starts up. Two things were deliberately left alone: no staging backend URL was recorded (the repo doesn't declare one anywhere, and guessing one risks pointing previews at the wrong environment), and no CORS change was made to the Django backend, because this project serves the React bundle from Django on the same origin and has no cross-origin API surface to open up.Technical details
recipe.json—schema_version: 1with a singlefrontends[]entry:working_dir: "web",framework: "cra",package_manager: "yarn"(fromweb/yarn.lock; nopackageManagerfield anywhere),dev_command: "yarn start",install_command: "yarn install --frozen-lockfile",dependency_manifests: ["web/yarn.lock"],dev_port: 3000,system_packages: ["procps"],size: "medium".prebuild_commandis empty —web/package.json's only build hook ispostbuild(copies the production build intoserver/static/build/), which is a production concern, not a dev prebuild.Dockerfile.web— thin, toolchain-only: noCOPY, no bakednode_modules, no CodePress binary.WORKDIR /app→/app/web,procpsvia apt, PATH backstop fornode_modules/.bin, and the runtime env contract (PORT,CODEPRESS_BIND_HOST,CODEPRESS_HMR_CLIENT_PORT,CODEPRESS_HMR_PROTOCOL).Two decisions worth a close look:
node:16-bookworm, not the current LTS.web/package.jsonpinsreact-scripts1.0.10, which resolves (perweb/yarn.lock) to webpack 2.6.1. webpack 2/3 hash modules with md4, and OpenSSL 3 — bundled from Node 17 on — removed md4, so a modern base fails immediately witherror:0308010C:digital envelope routines::unsupported. Node 16 ships OpenSSL 1.1.1, so the dev server runs without patching the app. The full-bookwormvariant (never-slim) keeps the node-gyp toolchain available for the runtime install. I confirmednode:16-bookwormexists on ECR Public with alinux/amd64manifest.packageManagerfield, and yarn 1.x already ships in thenode:16base. Enabling corepack would shadow that working yarn with a shim that tries to fetch a package manager from the public registry on every cold start. ARUN yarn --versionassertion makes a future base-image swap fail loudly at build time instead of at dev-command time.HMR: the pinned
react-dev-utils3.0.2 builds its SockJS URL fromwindow.location, so HMR already follows the public preview origin (like Next.js) and needs no client-port flag.WDS_SOCKET_PORTis still mapped fromCODEPRESS_HMR_CLIENT_PORTin theCMDfor forward compatibility, since only react-scripts ≥ 3.4 honors it.DANGEROUSLY_DISABLE_HOST_CHECK=trueis set so webpack-dev-server accepts the proxied previewHostheader — this is a dev-only image that never produces a production build.Why no preview-CORS edit:
server/is Django, but there are zero CORS references anywhere in the repo (nodjango-cors-headersinPipfile/Pipfile.lock, nocorsheadersinINSTALLED_APPS, noCORS_*settings), andweb/srcmakes no API calls at all — nofetch/axios, no absolute API base URL, no CRAproxyfield. Django's catch-all route renders the CRA build fromstatic/buildsame-origin. So neither cross-origin-caller signal holds and there is nothing to allow. Separately, the repo has no staging config path at all (one flatsettings.py, nosettings/package, no.env*, no CI workflows), so a preview-origin allowance would have had nowhere staging-scoped to live even if it were warranted.Why no social-auth work: the only social sign-in code is
samples/auth-web/(aGithubButton), which is dead reference material — not imported byweb/src, and outside CRA'ssrc/compile root, so it cannot build. The backend installsallauth/rest_authbut enables noallauth.socialaccountprovider and wires no provider routes, so no sign-in flow is reachable from a preview.Changes
.codepress/dev-server/recipe.json— schema_version 1, one frontend entry for theweb/create-react-app (yarn, port 3000).codepress/dev-server/Dockerfile.web— thin dev-mode image onnode:16-bookwormthat binds 0.0.0.0, installsprocps, and wires HMR/bind to the runtime env varsstaging_backend_url— no staging backend URL is declared anywhere in the repo, so nothing was persisted rather than guessingTest plan
python3 -c "import json;r=json.load(open('.codepress/dev-server/recipe.json'));print(r['schema_version'], r['frontends'][0]['working_dir'], r['frontends'][0]['dev_port'])"→ prints1 web 3000, and.codepress/dev-server/Dockerfile.webexists at the recordeddockerfile_path.-f):docker build -f .codepress/dev-server/Dockerfile.web -t drintro-web-dev .→ build succeeds and theRUN yarn --versionstep prints a 1.x version.docker run --rm -p 3000:3000 -v "$PWD:/app" drintro-web-dev→ afteryarn install --frozen-lockfilehas populatedweb/node_modules, react-scripts printsCompiled successfully!andcurl -s -o /dev/null -w '%{http_code}' http://localhost:3000/returns200.web/src/containers/home/Home.jsand confirm the browser updates without a manual refresh (the HMR socket follows the page origin, so this also holds behind the preview proxy).FROMline tonode:22-bookworm, rebuild, and run → startup fails witherror:0308010C:digital envelope routines::unsupported. Revert the line afterwards.docker history drintro-web-devshows noyarn installlayer and no sourceCOPY, anddocker run --rm drintro-web-dev sh -c 'ls /app'is empty without a bind mount.Open items
CMDwas extracted and verified to parse undersh -nand to expandHOST/WDS_SOCKET_PORTcorrectly both with runtime-injected values and with image defaults, andnode:16-bookwormwas confirmed present on ECR Public forlinux/amd64. The first realdocker build+ boot (test plan steps 2–3) is the outstanding verification.react-scripts1.0.10 / React 15 is from 2017 and is the reason the base image is pinned to Node 16. If the frontend is ever upgraded, revisit the pin and the corepack decision — a modern react-scripts would allow the current LTS base and could then honorWDS_SOCKET_PORTdirectly.settings.py, no.env*).Authors
Generated with CodePress · View the chat session
Co-authored-by: dev@codepress.dev dev@codepress.dev