diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..db9ef21 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,11 @@ +# .git stays: Starlight's "Last updated" is each page's last commit, read by the build. +node_modules +dist +.astro +.task +.sources +.env +.env.* +.DS_Store +_output +ui-hill-climb/rounds diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml index 1c46cb2..d3cf13b 100644 --- a/.github/workflows/pages.yml +++ b/.github/workflows/pages.yml @@ -40,12 +40,6 @@ jobs: with: # Every commit, so each page's "Last updated" is its own last change, not the checkout's. fetch-depth: 0 - - uses: pnpm/action-setup@73e46992e05b19abd31f2f3c20e0e7370d762115 # v6.1.1 - # No store cache: a package restored from one is never asked of the registry, so Socket - # Firewall, which stands between the two, would not see it. - - uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0 - with: - node-version: '22' - uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 with: go-version-file: go.mod @@ -71,7 +65,8 @@ jobs: SOURCES_TOKEN: ${{ steps.sources-token.outputs.token }} run: go tool task sources # What a developer runs, with the Task go.mod pins: task check, the install through Socket - # Firewall among it. The sources are fetched, so this asks nothing of spin. + # Firewall among it, in the image the Dockerfile makes - Node and pnpm are the image's, not + # the runner's. The sources are fetched, so this asks nothing of spin. - if: env.SOURCES_APP == 'true' run: go tool task check - if: env.SOURCES_APP != 'true' diff --git a/AGENTS.md b/AGENTS.md index 89f70f8..10ca342 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -48,8 +48,8 @@ exist.** Everything below follows from that. | a workflow | `task gate` | Tasks run as `go tool task `. spin is private: `task sources` reads it with `SOURCES_TOKEN` -(`gh auth token` gives one) or git's own credentials. The build needs the Node the workflows -install; an older one of the same major fails it, saying so. +(`gh auth token` gives one) or git's own credentials. A host needs Go and Docker: Node and pnpm +run in the image the `Dockerfile` makes, never on the host. ## Claims and tone diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7ba5323 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,49 @@ +# syntax=docker/dockerfile:1 +# check=skip=InvalidDefaultArgInFrom +# The site's Node toolchain, so a host needs Go and Docker and nothing of Node's: the install, the +# build and the dev server run here, at the Node the image names. Go stays on the host, where +# refgen builds spin's CLI and every check but the build runs. The images are versions.yaml's, +# handed in by the Taskfile (versions args). +ARG GOLANG_IMAGE +ARG NODE_IMAGE + +# go-tools' sfw, at the commit go.mod pins: the install goes through Socket Firewall in the image +# as it did on the host, and sfw check holds this file to it. +FROM ${GOLANG_IMAGE} AS sfw +WORKDIR /src +COPY go.mod go.sum ./ +RUN --mount=type=cache,id=spinbox-docs-gomod,target=/go/pkg/mod \ + CGO_ENABLED=0 go build -o /sfw github.com/spin-stack/go-tools/cmd/sfw + +FROM ${NODE_IMAGE} AS deps +# git: the build reads each page's last commit. COREPACK_HOME outside a home: task dev runs as the +# host's user, who finds pnpm where root put it. +ENV CI=true COREPACK_ENABLE_DOWNLOAD_PROMPT=0 COREPACK_HOME=/usr/local/share/corepack +RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates git \ + && rm -rf /var/lib/apt/lists/* +COPY --from=sfw /sfw /usr/local/bin/sfw +WORKDIR /app +COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./ +# pnpm itself comes from corepack, at the version package.json names: the firewall stands between +# a package manager and the registry, not in front of the package manager. No store cache: a +# package restored from one never reaches the registry, so the firewall would not see it. The +# firewall's own binary is cached, checked against its pin on every run. GITHUB_TOKEN, when the +# host has one, is what sfw downloads that binary with. +RUN corepack enable pnpm && corepack install \ + && chmod -R a+rX "$COREPACK_HOME" +RUN --mount=type=cache,id=spinbox-docs-sfw,target=/root/.cache/spin-stack/sfw \ + --mount=type=secret,id=github_token,env=GITHUB_TOKEN \ + sfw pnpm install --frozen-lockfile \ + # task dev runs as the host's user: Vite and Astro write their caches under node_modules. + && chmod a+rwx node_modules + +FROM deps AS build +ARG SITE_URL +ARG BASE_PATH +ENV SITE_URL=$SITE_URL BASE_PATH=$BASE_PATH +COPY . . +# The few rules the build keeps in JavaScript, with node's own runner: no dependency. +RUN node --test 'src/lib/*.test.mjs' && pnpm build + +FROM scratch AS dist +COPY --from=build /app/dist/ / diff --git a/README.md b/README.md index 89fa721..0dd9e6e 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,8 @@ The rule this site keeps: a page is generated from the code it describes, or hel check that fails the build, or it does not exist. Everything below is one of those checks. ``` -go tool task install # dependencies, through Socket Firewall (sfw) -go tool task dev # http://localhost:4321, live reload +go tool task install # the image with the dependencies, installed through Socket Firewall (sfw) +go tool task dev # http://localhost:4321, live reload, in that image go tool task sources # spin, spin-terraform-aws and brand into .sources/, at the commits versions.yaml pins go tool task check # what CI runs: the reference against the sources, and the gate go tool task gate # the gates, the install, the tests, the public reference, the build, every link @@ -19,7 +19,12 @@ go tool task --list # everything else `go tool task` is go-tools' task command, the one tool `go.mod` takes: it runs the Task `versions.yaml` pins, the version CI runs, with go-tools' commands on its PATH; the tasks below -are named without it. `task check` is what CI runs: the reference against its sources, then `task +are named without it. A host needs Go and Docker, nothing of Node's: the install, +the build and the dev server run in the image the `Dockerfile` makes, at the Node it names, so a +laptop builds with the Node CI does. The install there goes through the firewall as it did on the +host - the image builds go-tools' `sfw` at the version `go.mod` pins - and `task dev` mounts the +source and runs as your user, with `node_modules` from the image. Go stays on the host: refgen +builds spin's CLI, and every check but the build runs there. `task check` is what CI runs: the reference against its sources, then `task gate`, which fails first on an install that skips the firewall (`sfw check`) or a workflow step that is not one task (`taskgate`). diff --git a/Taskfile.yml b/Taskfile.yml index 980fe00..5b98ba9 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -5,7 +5,8 @@ version: '3' # produce. SPIN, TERRAFORM and BRAND are checkouts of spin-stack/spin, spin-stack/spin-terraform-aws # and spin-stack/brand: by default the ones task sources fetches into .sources/, at the commits # versions.yaml pins. SHOTS is where it unpacks the dashboard's screenshots, which spin's -# release carries as site-shots.tar.gz. +# release carries as site-shots.tar.gz. Node and pnpm run in the image the Dockerfile makes: a host +# needs Go and Docker, and every machine builds with the same Node. vars: SPIN: '{{.SPIN | default ".sources/spin"}}' @@ -13,17 +14,36 @@ vars: BRAND: '{{.BRAND | default ".sources/brand"}}' SHOTS: '{{.SHOTS | default ".sources/spin-site-shots"}}' BASE_PATH: '{{.BASE_PATH | default "/website"}}' + PORT: '{{.PORT | default "4321"}}' + HOST: '{{.HOST | default "127.0.0.1"}}' + IMAGE: spinbox-docs + UID: + sh: id -u + GID: + sh: id -g tasks: + # The images are versions.yaml's (versions args). GITHUB_TOKEN, when set, is what sfw downloads + # the firewall with: anonymous downloads are the first GitHub sheds under load. A secret, so it + # is in no layer of the image. install: - desc: Install the site's dependencies from the lockfile, through Socket Firewall (sfw). + desc: Build the image with the site's dependencies from the lockfile, installed through Socket Firewall (sfw) - the Dockerfile's deps stage. The tasks that need it build it. cmds: - - sfw pnpm install --frozen-lockfile + - docker build --target deps $(versions args golang node) --secret id=github_token,env=GITHUB_TOKEN -t {{.IMAGE}}:deps . dev: - desc: Serve the site with live reload. - cmds: - - pnpm dev + desc: Serve the site with live reload at http://localhost:4321 (HOST=0.0.0.0 for every interface, PORT=N for another port). The source is mounted; node_modules comes from the image. + deps: [install] + cmds: + # The mount point for the image's node_modules; made here so it is yours, not root's. + - mkdir -p node_modules + - >- + docker run --rm -it --init + --user {{.UID}}:{{.GID}} -e HOME=/tmp + -v "$PWD":/app -v /app/node_modules + -p {{.HOST}}:{{.PORT}}:4321 + {{.IMAGE}}:deps + pnpm dev --port 4321 --host 0.0.0.0 sources: desc: Fetch spin, spin-terraform-aws and brand into .sources/, each at the commit versions.yaml pins, and spin's release's screenshots (site-shots.tar.gz) beside them. spin is private - SOURCES_TOKEN, or git's own credentials, reads it. @@ -96,9 +116,13 @@ tasks: - go run ./tools/pricing -terraform .sources/spin-terraform-aws -check build: - desc: Build the site into dist/, with llms.txt, llms-full.txt and a .md twin of every page. + desc: Build the site into dist/, with llms.txt, llms-full.txt and a .md twin of every page - the Dockerfile's build stage, after the build's own tests. SITE_URL and BASE_PATH are where it is served. cmds: - - pnpm build + - rm -rf dist + - >- + docker build --target dist $(versions args golang node) --secret id=github_token,env=GITHUB_TOKEN + --build-arg SITE_URL={{.SITE_URL}} --build-arg BASE_PATH={{.BASE_PATH}} + --output type=local,dest=dist . links: desc: Fail on a link to a page or an anchor the build did not produce. @@ -111,7 +135,7 @@ tasks: - go run ./tools/linkcheck -external dist gate: - desc: What CI runs - every install through the firewall and every workflow step a task, the install, vet and the tools' tests and the build's, the reference against the public sources, the build, and every link. + desc: What CI runs - every install through the firewall and every workflow step a task, the install, vet and the tools' tests, the reference against the public sources, the build, and every link. cmds: - sfw check # The Task running this one, which taskgate asks for the task names a workflow step runs. @@ -122,8 +146,6 @@ tasks: - task: install - go vet ./... - go test ./... - # The few rules the build keeps in JavaScript, with node's own runner: no dependency. - - node --test 'src/lib/*.test.mjs' - task: reference:public - task: build - task: links diff --git a/versions.yaml b/versions.yaml index f30c94c..421a9c3 100644 --- a/versions.yaml +++ b/versions.yaml @@ -48,3 +48,23 @@ note: >- The Task `go tool task` runs (go-tools' cmd/task), for every platform a person or a runner works on: no repository compiles it. + +- name: node + kind: image + source: mirror.gcr.io/library/node + version: 22-bookworm-slim + pin: sha256:e9f565d32859f0cbfb52125eafe8be39390f24dac302dc3cdf566e8ba3ab21ee + track: digest + note: >- + The Node the Dockerfile installs, builds and serves the site with, on every machine and in CI. + After a bump: `task check`, and a look at `task dev`. + +- name: golang + kind: image + source: mirror.gcr.io/library/golang + version: 1.27.4-bookworm + pin: sha256:4fa7c968ba93f1635670522dbb01a2c78150443e1385746924566079f36570ea + track: go + note: >- + What the Dockerfile builds go-tools' sfw with, the firewall the install in the image goes + through. After a bump: `task install`.