Bootstrap CodePress Live Dev Server recipe + dev Dockerfile - #47
Open
codepress-dev[bot] wants to merge 1 commit into
Open
Conversation
Author the committed Live Dev Server artifacts for this repo so previews boot from repo-owned files instead of a runtime heuristic. - .codepress/dev-server/recipe.json: one frontend entry for web/ (Create React App, yarn, port 3000). - .codepress/dev-server/Dockerfile.web: thin dev-mode image on node:16-bookworm. Node 16 is deliberate — react-scripts 1.0.10 runs webpack 2.6.1, whose md4 module hashing fails on Node 17+/OpenSSL 3. Binds via CODEPRESS_BIND_HOST, bakes no node_modules or source, and maps the runtime's public HMR port into the dev command. No staging backend URL was found anywhere in the repo, so staging_backend_url is omitted rather than guessed. The Django API in server/ is left untouched: it renders the React build same-origin, ships no CORS surface, and has no staging settings path, so there is no preview-CORS change to make safely. 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 preview of this project's React app. Until now the preview would have had to guess how to run the app; now the repo tells it directly — which app to run, how to install it, and which Node version it needs. The only frontend here is
web/, so that's the one preview this adds. Nothing about how the app builds or runs for you locally changes: these are new files under.codepress/, and no existing application code was touched. Two things were deliberately left alone rather than guessed at, and both are explained below: no staging backend URL was recorded (there isn't one declared anywhere in the repo), and the Django API inserver/was not modified for preview CORS, because it currently serves the React build from its own origin and has no cross-origin API surface to open up.Technical details
Discovery. One runnable frontend:
web/— Create React App,react-scripts1.0.10,yarn.lock(yarn v1 format, no root workspace),start→react-scripts start, default port 3000.samples/auth-web/is not a frontend: nopackage.json, noindex.html, imports (../../../config/settings,secure-random) that resolve to nothing in the tree, and no reference fromweb/src.server/is a Django 1.11 backend (see the CORS note below).Node 16 is the load-bearing decision.
react-scripts1.0.10 sits onwebpack@2.6.1, which hashes modules with md4. Under Node 17+ (OpenSSL 3) that throwserror:0308010C:digital envelope routines::unsupportedand the dev server never comes up. Pinningnode:16-bookworm(OpenSSL 1.1.1) lets the 2017 toolchain inweb/yarn.lockrun unmodified, and avoids the alternative of papering over it withNODE_OPTIONS=--openssl-legacy-provideron a newer Node, which would leave the rest of the 2017 dependency tree on an untested runtime. The tag was verified to exist and resolve on the public ECR mirror. Full-bookworm, never-slim, because deps install at runtime and node-gyp needs the toolchain.No corepack. The repo declares no
packageManager, and the Node base image already bundles yarn 1 classic — exactly what this lockfile format needs. Activating an unpinned corepack shim would only add a registry fetch on every cold start.CRA specifics, verified against the published
react-scripts@1.0.10/react-dev-utils@4.2.3sources rather than assumed:start.jsreadsHOST(defaulting to0.0.0.0) andPORT, so bind is env-driven; the CMD derivesHOSTfromCODEPRESS_BIND_HOST.webpackHotDevClient.jsbuilds its SockJS URL fromwindow.location(protocol/hostname/port), so HMR follows the public preview origin automatically behind the TLS proxy.WDS_SOCKET_PORTis a no-op in CRA 1.x but is mapped fromCODEPRESS_HMR_CLIENT_PORTanyway so the wiring stays correct ifreact-scriptsis upgraded.webpackDevServer.config.jscomputesdisableHostCheck: !proxy || DANGEROUSLY_DISABLE_HOST_CHECK === 'true'.web/package.jsondeclares noproxy, so the host check is already off today; the Dockerfile sets the env var explicitly so adding aproxyfield later doesn't silently break previews withInvalid Host header. The dev server is only reachable through the CodePress preview proxy.BROWSER=nonestopsreact-scriptsfrom trying to launch a browser inside the container.Image shape. Thin and toolchain-only: no
COPYof source, no bakednode_modules, no install layer — the runtime bind-mounts the checkout at/appand provides deps.WORKDIR /app/web,EXPOSE 3000,procpsinstalled for supervisor shutdown, workspace bins prepended toPATH. The DockerfileCMDand the recipe'sdev_commandare byte-identical argv (asserted in validation).Staging backend URL: omitted, not guessed. There is no
.codepress/verify-staging/recipe.json, no.env*of any kind, novercel.json, nonext.config/vite.config, and no.github/workflows. Zero candidates, sostaging_backend_urlis left out entirely rather than written as a placeholder. No Live Dev Server env prefill was done for the same reason — andweb/srcmakes no API calls at all, so there is no framework-public API-base var to prefill even if a URL existed.Preview CORS: no edit, by design.
server/is a Django backend, but it fails the gate for a preview-CORS change on three independent counts, each verified: (1) it has no CORS surface —django-cors-headersis not inINSTALLED_APPS, not inMIDDLEWARE, not inPipfile, and not present anywhere inPipfile.lock; a repo-wide grep forcors/allow_origin/Access-Controlreturns nothing. (2) It is same-origin by construction —server/server/urls.pyroutes^to a view that renders the React build'sindex.html, andweb/package.json'spostbuildcopiesbuild/intoserver/static/build/. (3) There is no cross-origin caller —web/srccontains nofetch/axios/absolute API URL at all. Adding CORS here would mean introducing a new dependency and inventing a surface the app doesn't have. Separately, the repo has a singleserver/server/settings.pywithDEBUG = Trueand no staging settings module or.env.staging, so there is no staging-only config path to scope an allowance to — which is a report case regardless. If a browser client on another origin is added later, run this bootstrap again and it will detect the CORS surface and wire it.Preview social auth: not applicable. No social or enterprise sign-in exists in the runnable frontend. The GitHub OAuth button under
samples/auth-web/components/is unreferenced sample code outside any buildable app, so there was nothing to make preview-compatible.Changes
.codepress/dev-server/recipe.json— schema_version 1, one frontend entry forweb/(frameworkcra, package manageryarn,yarn install --frozen-lockfile, dependency manifestweb/yarn.lock, dev port 3000,procps, sizemedium).codepress/dev-server/Dockerfile.web— thin dev-mode image onnode:16-bookwormpinned for the webpack 2 / OpenSSL 1.1.1 requirement, binding viaCODEPRESS_BIND_HOSTand wiring HMR fromCODEPRESS_HMR_CLIENT_PORT/CODEPRESS_HMR_PROTOCOLstaging_backend_url— no staging URL is declared anywhere in the reposerver/(Django) unmodified — no CORS surface, same-origin architecture, and no staging config path to scope an allowance toTest plan
git diff --stat master...HEADshould show only.codepress/dev-server/recipe.jsonand.codepress/dev-server/Dockerfile.web, and no application code.python3 -c "import json;print(json.load(open('.codepress/dev-server/recipe.json'))['frontends'][0])"— expectworking_dir: web,framework: cra,package_manager: yarn,dev_port: 3000.docker build -f .codepress/dev-server/Dockerfile.web -t drx-web-dev .— it should complete in seconds, since it installs onlyprocpsand copies no source.docker run --rm -p 3000:3000 -v "$PWD:/app" drx-web-dev sh -c 'yarn install --frozen-lockfile && BROWSER=none HOST=0.0.0.0 yarn start', thencurl -I http://localhost:3000and expect HTTP 200. (The install runs here only because you are starting the container by hand; in a real preview the platform hydratesnode_modulesbefore start.)node:22-bookwormsubstituted in theFROMline and verifyyarn startfails witherror:0308010C:digital envelope routines::unsupported— that failure is the reason the Dockerfile pins Node 16.web/src/containers/home/Home.jsand confirm the browser athttp://localhost:3000updates without a manual refresh.grep -rniE 'cors|allow_origin|Access-Control' server/should return nothing, andserver/server/urls.pyshould still route^toindex_views.index.Open items
node:16-bookwormmanifest resolves on the public ECR mirror, the recipe/Dockerfile pass the contract checks,CMDanddev_commandare identical argv, and CRA 1.0.10'sHOST/PORT/host-check/HMR-socket behavior was read from the published package sources rather than assumed. The first real build happens on the platform side; the test plan above reproduces it locally.yarn install --frozen-lockfileresolves a 2017 dependency tree from the public npm registry. It should be fine (all tarballs are still published, andfseventsis darwin-gated so it is skipped on Linux), but it was not executed here and is the most likely source of a first-build surprise.DANGEROUSLY_DISABLE_HOST_CHECK=trueis set in the dev image. It changes nothing today — CRA already computesdisableHostCheck: truebecauseweb/package.jsonhas noproxyfield — and it only guards against a futureproxyaddition silently breaking previews. Say the word if you would rather it were dropped and the breakage surfaced instead.server/. That is correct for the repo as it stands (the React app makes no API calls), but if you wire the frontend to/api/auth/...against a separately hosted backend later, that backend will need a preview-origin CORS allowance — rerun this bootstrap in whichever repo the backend lives in.Authors
Generated with CodePress · View the chat session
Co-authored-by: dev@codepress.dev dev@codepress.dev