Compare commits
25
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f4b9dda15f | ||
|
|
24a17ce434 | ||
|
|
9c6f4eb2de | ||
|
|
9e33c06c65 | ||
|
|
a268799e97 | ||
|
|
ca24c6b7ff | ||
|
|
a13d1726b6 | ||
|
|
2bc68d1f1e | ||
|
|
64b8139d44 | ||
|
|
e80de25c48 | ||
|
|
57d993ca21 | ||
|
|
e3f3160fad | ||
|
|
c166d20195 | ||
|
|
99c8e425da | ||
|
|
e13195dd84 | ||
|
|
410b9b1621 | ||
|
|
81cfb9be83 | ||
|
|
2f9f3dd622 | ||
|
|
93de4f1758 | ||
|
|
45c0f997b7 | ||
|
|
287ffdf43e | ||
|
|
4cce747e00 | ||
|
|
48c7faf557 | ||
|
|
964d973e3c | ||
|
|
1ad7ae14be |
No files matched your search
+4
-10
@@ -2,18 +2,14 @@
|
|||||||
# lint` or `script/lint`, which are themselves a docker build and would
|
# lint` or `script/lint`, which are themselves a docker build and would
|
||||||
# recurse into a daemon that does not exist in a build step.
|
# recurse into a daemon that does not exist in a build step.
|
||||||
#
|
#
|
||||||
# In every stage, ARG CACHEBUST comes right after the step that installs
|
# node and yarn come from the distribution, which is trusted, so they
|
||||||
# system packages. script/ passes a new value on every build. That value
|
# need no version and no hash. That yarn only starts the release file in
|
||||||
# reruns every RUN step below the ARG line, and the install step keeps
|
# .yarn/releases/, so every stage copies that file and .yarnrc.yml
|
||||||
# its layer. node and yarn come from the distribution, which is trusted,
|
# before it runs script/bootstrap.
|
||||||
# so they need no version and no hash. That yarn only starts the release
|
|
||||||
# file in .yarn/releases/, so every stage copies that file and
|
|
||||||
# .yarnrc.yml before it runs script/bootstrap.
|
|
||||||
#
|
#
|
||||||
# alpine 3.24.3, 2026-11-04
|
# alpine 3.24.3, 2026-11-04
|
||||||
FROM alpine@sha256:be2656061b536c1883c4034790e21d0a09c5aaaf51968b89368a3c0371ea2c9a AS lint
|
FROM alpine@sha256:be2656061b536c1883c4034790e21d0a09c5aaaf51968b89368a3c0371ea2c9a AS lint
|
||||||
RUN apk add --no-cache git make nodejs-current yarn
|
RUN apk add --no-cache git make nodejs-current yarn
|
||||||
ARG CACHEBUST
|
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
@@ -31,7 +27,6 @@ RUN yarn run prettier --check '**/*.md' --tab-width 4 --prose-wrap always
|
|||||||
# alpine 3.24.3, 2026-11-04
|
# alpine 3.24.3, 2026-11-04
|
||||||
FROM alpine@sha256:be2656061b536c1883c4034790e21d0a09c5aaaf51968b89368a3c0371ea2c9a AS test
|
FROM alpine@sha256:be2656061b536c1883c4034790e21d0a09c5aaaf51968b89368a3c0371ea2c9a AS test
|
||||||
RUN apk add --no-cache git make nodejs-current yarn
|
RUN apk add --no-cache git make nodejs-current yarn
|
||||||
ARG CACHEBUST
|
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
@@ -53,7 +48,6 @@ RUN timeout 90 test/update-policy.sh
|
|||||||
# alpine 3.24.3, 2026-11-04
|
# alpine 3.24.3, 2026-11-04
|
||||||
FROM alpine@sha256:be2656061b536c1883c4034790e21d0a09c5aaaf51968b89368a3c0371ea2c9a
|
FROM alpine@sha256:be2656061b536c1883c4034790e21d0a09c5aaaf51968b89368a3c0371ea2c9a
|
||||||
RUN apk add --no-cache git make nodejs-current yarn
|
RUN apk add --no-cache git make nodejs-current yarn
|
||||||
ARG CACHEBUST
|
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
|
|||||||
@@ -116,12 +116,10 @@ alpine. We provide:
|
|||||||
`script/bootstrap`, then `script/install-precommit`
|
`script/bootstrap`, then `script/install-precommit`
|
||||||
- `script/projectname` — output the project name (our own extension); used by
|
- `script/projectname` — output the project name (our own extension); used by
|
||||||
`script/docker` for the image tag
|
`script/docker` for the image tag
|
||||||
- `script/test` —
|
- `script/test` — `docker build --target test --output type=cacheonly .`,
|
||||||
`docker build --build-arg CACHEBUST="$(date +%s)-$$" --target test --output type=cacheonly .`,
|
|
||||||
building the `test` phase of the `Dockerfile`, which runs
|
building the `test` phase of the `Dockerfile`, which runs
|
||||||
`test/update-policy.sh`, without writing an image
|
`test/update-policy.sh`, without writing an image
|
||||||
- `script/lint` —
|
- `script/lint` — `docker build --target lint --output type=cacheonly .`,
|
||||||
`docker build --build-arg CACHEBUST="$(date +%s)-$$" --target lint --output type=cacheonly .`,
|
|
||||||
building the `lint` phase, which runs prettier over the markdown files,
|
building the `lint` phase, which runs prettier over the markdown files,
|
||||||
without writing an image
|
without writing an image
|
||||||
- `script/fmt` — format all markdown files with prettier (writes; native, not in
|
- `script/fmt` — format all markdown files with prettier (writes; native, not in
|
||||||
@@ -129,14 +127,13 @@ alpine. We provide:
|
|||||||
- `script/fmt-check` — check formatting (read-only; native)
|
- `script/fmt-check` — check formatting (read-only; native)
|
||||||
- `script/check` — run all checks: `test`, `lint`, `fmt-check` (our own
|
- `script/check` — run all checks: `test`, `lint`, `fmt-check` (our own
|
||||||
extension); builds no image of its own
|
extension); builds no image of its own
|
||||||
- `script/docker` —
|
- `script/docker` — `docker build --build-arg VERSION="$version" -t prompts .`,
|
||||||
`docker build --build-arg CACHEBUST="$(date +%s)-$$" --build-arg VERSION="$version" -t prompts .`,
|
|
||||||
the tag coming from `script/projectname` (byte-identical across repos)
|
the tag coming from `script/projectname` (byte-identical across repos)
|
||||||
- `script/cibuild` — cd to the repo root, run `script/bootstrap`, run
|
- `script/cibuild` — cd to the repo root, run `script/bootstrap`, run
|
||||||
`script/check`, compute `version` from `git describe`, then
|
`script/check`, compute `version` from `git describe`, then
|
||||||
`docker build --build-arg CACHEBUST="$(date +%s)-$$" --build-arg VERSION="$version" -t prompts .`
|
`docker build --build-arg VERSION="$version" -t prompts .` (what CI runs; it
|
||||||
(what CI runs; it bootstraps because CI checks out and runs this alone while
|
bootstraps because CI checks out and runs this alone while `script/fmt-check`
|
||||||
`script/fmt-check` is native)
|
is native)
|
||||||
- `script/precommit` — run by the git pre-commit hook (our own extension); calls
|
- `script/precommit` — run by the git pre-commit hook (our own extension); calls
|
||||||
`script/check`
|
`script/check`
|
||||||
- `script/install-precommit` — installs the git pre-commit hook (our own
|
- `script/install-precommit` — installs the git pre-commit hook (our own
|
||||||
@@ -147,22 +144,9 @@ alpine. We provide:
|
|||||||
|
|
||||||
`make hooks` installs the pre-commit hook that runs `script/precommit`.
|
`make hooks` installs the pre-commit hook that runs `script/precommit`.
|
||||||
|
|
||||||
In every stage of a `Dockerfile`, every step that lints, tests or compiles comes
|
The builds use Docker's normal cache: a step runs again only when its inputs
|
||||||
after `ARG CACHEBUST`. `ARG CACHEBUST` comes right after these steps:
|
change. This repo's own `Dockerfile` installs git, make, node and yarn right
|
||||||
|
after `FROM` in every stage, so a change to `script/` keeps that layer.
|
||||||
- the steps that install system packages
|
|
||||||
- the steps that download Go's modules
|
|
||||||
- the step that runs `script/bootstrap` to install a Python `test` phase's
|
|
||||||
packages from `Pipfile.lock`
|
|
||||||
|
|
||||||
A stage with none of these steps declares `ARG CACHEBUST` right after `FROM`.
|
|
||||||
The `script/` builds pass a new `CACHEBUST` value on every build, which reruns
|
|
||||||
every `RUN` step after that line and leaves the layers above it and the cache
|
|
||||||
mounts in place; `--no-cache` would build those layers again and empty the
|
|
||||||
mounts. This repo's own `Dockerfile` installs git, make, node and yarn right
|
|
||||||
after `FROM` in every stage, above `ARG CACHEBUST`. `script/bootstrap` installs
|
|
||||||
the node packages below that line, because check builds keep system packages but
|
|
||||||
not node packages.
|
|
||||||
|
|
||||||
## Rationale
|
## Rationale
|
||||||
|
|
||||||
@@ -175,7 +159,8 @@ share, and evolve prompts across projects.
|
|||||||
The repository is a collection of Markdown files organized in the `prompts/`
|
The repository is a collection of Markdown files organized in the `prompts/`
|
||||||
subdirectory. Each file contains one or more related prompts or policy
|
subdirectory. Each file contains one or more related prompts or policy
|
||||||
documents. There is no build step or runtime component; the prompts are consumed
|
documents. There is no build step or runtime component; the prompts are consumed
|
||||||
by copying them into other projects or referencing them directly.
|
by copying them into other projects or referencing them directly. `examples/`
|
||||||
|
holds the example `Dockerfile` files that `prompts/REPO_POLICIES.md` links to.
|
||||||
|
|
||||||
## See Also
|
## See Also
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
FROM golangci/golangci-lint@sha256:... AS lint
|
||||||
|
RUN apt-get update \
|
||||||
|
&& apt-get install -y --no-install-recommends libvips-dev \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
WORKDIR /src
|
||||||
|
COPY go.mod go.sum ./
|
||||||
|
RUN go mod download
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
# The steps that install system packages and download Go's modules
|
||||||
|
# come before COPY . ., so a change to the code keeps their layers.
|
||||||
|
# The steps that compile mount Go's build cache, and golangci-lint run
|
||||||
|
# also mounts golangci-lint's; both survive from build to build.
|
||||||
|
|
||||||
|
# Lint phase
|
||||||
|
# golangci/golangci-lint:v2.x.x, YYYY-MM-DD
|
||||||
|
FROM golangci/golangci-lint@sha256:... AS lint
|
||||||
|
WORKDIR /src
|
||||||
|
COPY go.mod go.sum ./
|
||||||
|
RUN go mod download
|
||||||
|
COPY . .
|
||||||
|
RUN --mount=type=cache,target=/root/.cache/go-build \
|
||||||
|
--mount=type=cache,target=/root/.cache/golangci-lint \
|
||||||
|
golangci-lint run --config .golangci.yml ./...
|
||||||
|
|
||||||
|
# Test phase. -race needs cgo and so a C compiler, which the Debian Go
|
||||||
|
# image ships and the alpine one does not. -count=1 because the mounted
|
||||||
|
# cache also holds test results, which go test would otherwise replay.
|
||||||
|
# A first run that timed out gets no rerun, because a rerun would only
|
||||||
|
# wait for the same hang.
|
||||||
|
# golang:1.x, YYYY-MM-DD
|
||||||
|
FROM golang@sha256:... AS test
|
||||||
|
WORKDIR /src
|
||||||
|
COPY go.mod go.sum ./
|
||||||
|
RUN go mod download
|
||||||
|
COPY . .
|
||||||
|
RUN --mount=type=cache,target=/root/.cache/go-build \
|
||||||
|
status=0; \
|
||||||
|
output=$(go test -count=1 -timeout 90s -race -cover ./... 2>&1) || status=$?; \
|
||||||
|
printf '%s\n' "$output"; \
|
||||||
|
test "$status" -eq 0 && exit 0; \
|
||||||
|
case "$output" in \
|
||||||
|
*"panic: test timed out"*|*"*** Test killed"*) exit 1 ;; \
|
||||||
|
esac; \
|
||||||
|
echo "--- Rerunning with -v for details ---"; \
|
||||||
|
go test -count=1 -timeout 90s -race -v ./...; \
|
||||||
|
exit 1
|
||||||
|
|
||||||
|
# Build stage. Nothing is wanted from either phase above; the copies
|
||||||
|
# are what make BuildKit build them first, so nothing after them can
|
||||||
|
# run unless lint and test passed.
|
||||||
|
# golang:1.x-alpine, YYYY-MM-DD
|
||||||
|
FROM golang@sha256:... AS builder
|
||||||
|
# git comes from the base image's own distribution package index, which
|
||||||
|
# is trusted, so it needs no version and no hash.
|
||||||
|
RUN apk add --no-cache git
|
||||||
|
WORKDIR /src
|
||||||
|
COPY go.mod go.sum ./
|
||||||
|
RUN go mod download
|
||||||
|
COPY --from=lint /src/go.sum /dev/null
|
||||||
|
COPY --from=test /src/go.sum /dev/null
|
||||||
|
# A tar-stream context keeps the sender's file owners, which git refuses.
|
||||||
|
RUN git config --system --add safe.directory /src
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# The VERSION build arg when one is given, otherwise
|
||||||
|
# `git describe --tags --always` on the .git in the build context. With
|
||||||
|
# .git present, a version that is still empty, dev or unknown fails the
|
||||||
|
# build: git is missing or could not read the checkout.
|
||||||
|
ARG VERSION
|
||||||
|
RUN --mount=type=cache,target=/root/.cache/go-build \
|
||||||
|
VERSION="${VERSION:-$(git describe --tags --always)}"; \
|
||||||
|
if [ -e .git ]; then \
|
||||||
|
case "$VERSION" in ""|dev|unknown) \
|
||||||
|
echo "version is '$VERSION' although .git is present" >&2; \
|
||||||
|
exit 1 ;; \
|
||||||
|
esac; \
|
||||||
|
fi; \
|
||||||
|
CGO_ENABLED=0 go build -trimpath \
|
||||||
|
-ldflags="-s -w -X main.Version=${VERSION}" \
|
||||||
|
-o /app ./cmd/app/
|
||||||
|
|
||||||
|
# Runtime stage, and the last one
|
||||||
|
FROM alpine@sha256:...
|
||||||
|
COPY --from=builder /app /usr/local/bin/app
|
||||||
|
ENTRYPOINT ["app"]
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
# Test phase. Both pytest runs share one 90-second timeout, so a hang
|
||||||
|
# uses it once and gets no rerun.
|
||||||
|
# debian:trixie-slim, YYYY-MM-DD
|
||||||
|
FROM debian@sha256:... AS test
|
||||||
|
# Python, pip and venv come from the distribution, which is trusted, so
|
||||||
|
# they need no version and no hash. make and git are base tools that
|
||||||
|
# script/bootstrap installs when they are missing. Installed here, they
|
||||||
|
# stay in their own layer when script/ changes.
|
||||||
|
RUN apt-get update \
|
||||||
|
&& apt-get install -y --no-install-recommends ca-certificates make git \
|
||||||
|
python3 python3-venv \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
# script/bootstrap installs pipenv in a virtual environment at
|
||||||
|
# $HOME/.pipenv, and the tests below run that pipenv.
|
||||||
|
ENV PATH=/root/.pipenv/bin:$PATH
|
||||||
|
WORKDIR /app
|
||||||
|
COPY script/ script/
|
||||||
|
COPY Pipfile Pipfile.lock ./
|
||||||
|
RUN script/bootstrap
|
||||||
|
COPY . .
|
||||||
|
RUN timeout 90 sh -c 'pipenv run pytest || { \
|
||||||
|
echo "--- Rerunning with -v for details ---"; \
|
||||||
|
pipenv run pytest -v; exit 1; }'
|
||||||
@@ -113,13 +113,7 @@ last_modified: 2026-11-16
|
|||||||
1. Write a `Dockerfile` for every repo, even if it only runs the tests and
|
1. Write a `Dockerfile` for every repo, even if it only runs the tests and
|
||||||
linting. It carries the lint and test phases, and the final stage depends on
|
linting. It carries the lint and test phases, and the final stage depends on
|
||||||
both, so a build makes sure the code is in an able-to-be-compiled state,
|
both, so a build makes sure the code is in an able-to-be-compiled state,
|
||||||
linted, and its tests run. Go through `script/cibuild` or `script/docker`
|
linted, and its tests run.
|
||||||
rather than a bare `docker build .`: they pass a new `CACHEBUST` value on
|
|
||||||
every build, which reruns every step that lints, tests or compiles and keeps
|
|
||||||
the system packages, Go's modules and build cache, and golangci-lint's
|
|
||||||
cache; `--no-cache` would throw all of them away. Without a new value an
|
|
||||||
unchanged tree serves the gate layers from cache and the build reports a
|
|
||||||
green it never ran.
|
|
||||||
|
|
||||||
1. Every repo must have a `Makefile`. See
|
1. Every repo must have a `Makefile`. See
|
||||||
[Repository Policies](https://git.eeqj.de/sneak/prompts/raw/branch/main/prompts/REPO_POLICIES.md)
|
[Repository Policies](https://git.eeqj.de/sneak/prompts/raw/branch/main/prompts/REPO_POLICIES.md)
|
||||||
@@ -221,7 +215,7 @@ last_modified: 2026-11-16
|
|||||||
...
|
...
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
SendErrorResponse(w, MSGenericError)
|
SendErrorResponse(w, ErrBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -501,19 +495,27 @@ exported name, and reads them as one name: `http.Server`, `list.New`.
|
|||||||
run together (`tabwriter`, never `tab_writer` or `tabWriter`), because that
|
run together (`tabwriter`, never `tab_writer` or `tabWriter`), because that
|
||||||
is how the standard library spells every package name.
|
is how the standard library spells every package name.
|
||||||
|
|
||||||
1. Never name a package `model`, `models`, `util`, `utils`, `common`, `misc`,
|
1. Never use a package name from the list below, or anything else that says
|
||||||
`helper`, `helpers`, `types`, `interfaces` or `api`, or anything else that
|
nothing about what is in it, because every program has a data model, helpers
|
||||||
says nothing about what is in it: every program has a data model, helpers
|
and types.
|
||||||
and types. Name the package for the one thing its code is about; when its
|
- `model` and `models`
|
||||||
code is about several things, split it first (`stringset`, not `util`).
|
- `util` and `utils`
|
||||||
|
- `common`
|
||||||
|
- `misc`
|
||||||
|
- `helper` and `helpers`
|
||||||
|
- `types`
|
||||||
|
- `interfaces`
|
||||||
|
- `api`
|
||||||
|
|
||||||
|
1. Split a package whose code is about several things, so that each part can be
|
||||||
|
named for what it provides (`stringset`, not `util`).
|
||||||
|
|
||||||
1. Spell a word out unless its short form is the one everybody already uses
|
1. Spell a word out unless its short form is the one everybody already uses
|
||||||
(`fmt`, `strconv`), because any other abbreviation has to be decoded.
|
(`fmt`, `strconv`), because any other abbreviation has to be decoded.
|
||||||
|
|
||||||
1. Never give a package a name that callers want for a variable (`buf`,
|
1. Lengthen a package name that callers want for a variable or that a widely
|
||||||
`count`) or that a widely used standard package has (`log`, `http`, `url`),
|
used standard package has (`bufio`, not `buf`; `auditlog`, not `log`),
|
||||||
because every importer then has to rename one of the two. Use a longer name
|
because importers must otherwise rename one of the two.
|
||||||
that says which one: `bufio`, `usercount`.
|
|
||||||
|
|
||||||
1. Give a package's directory the package's name, package `main` excepted, so
|
1. Give a package's directory the package's name, package `main` excepted, so
|
||||||
that the import path ends in the name the code uses.
|
that the import path ends in the name the code uses.
|
||||||
@@ -522,44 +524,54 @@ exported name, and reads them as one name: `http.Server`, `list.New`.
|
|||||||
plus `test` (`storetest`, never `testutil` or `testhelper`), because the
|
plus `test` (`storetest`, never `testutil` or `testhelper`), because the
|
||||||
name then says whose tests it is for.
|
name then says whose tests it is for.
|
||||||
|
|
||||||
1. Import a package under its own name. Give it a local name only when two
|
1. Import a package under its own name unless two imports share a name or its
|
||||||
imports have the same name or its own name breaks these rules, and use that
|
own name breaks these rules, so that a reader knows it without checking the
|
||||||
local name in every file, so that one name always means one package.
|
imports.
|
||||||
|
|
||||||
|
1. Give a renamed import the same local name in every file, so that one name
|
||||||
|
always means one package.
|
||||||
|
|
||||||
## Exported names
|
## Exported names
|
||||||
|
|
||||||
1. Never repeat the package name inside a longer exported name (`http.Server`,
|
1. Never repeat the package name inside a longer exported name (`http.Server`,
|
||||||
not `http.HTTPServer`; `yamlconfig.Parse`, not
|
not `http.HTTPServer`; `yamlconfig.Parse`, not
|
||||||
`yamlconfig.ParseYAMLConfig`), because the caller has already written it.
|
`yamlconfig.ParseYAMLConfig`), because the caller has already written it.
|
||||||
The type a package is named for may carry the same name on its own:
|
|
||||||
`list.List`, `time.Time`.
|
|
||||||
|
|
||||||
1. Use the same plain name in two packages when it fits both (`bufio.Reader`,
|
1. Use the same plain name in two packages when it fits both (`bufio.Reader`,
|
||||||
`csv.Reader`), because the package name already tells them apart.
|
`csv.Reader`), because the package name already tells them apart.
|
||||||
|
|
||||||
1. Leave the receiver's type out of a method name, and the parameter and result
|
1. Leave the receiver's type out of a method name, and the parameter and result
|
||||||
types out of a function name (`(c *Config) WriteTo(w)`, not
|
types out of a function name (`(c *Config) WriteTo(w)`, not
|
||||||
`WriteConfigTo`), because the signature already states them. Only when two
|
`WriteConfigTo`), because the signature already states them.
|
||||||
functions differ in nothing but a type does the type go in, at the end:
|
|
||||||
`ParseInt`, `ParseInt64`.
|
|
||||||
|
|
||||||
1. Name a function that returns a value for the value and one that acts for the
|
1. Put a type at the end of a function's name when the type is the only
|
||||||
action (`JobName(key)`, `WriteDetail(w)`), so that a call reads as what it
|
difference between two functions (`ParseInt`, `ParseInt64`), because Go
|
||||||
gives or what it does.
|
needs a different name for each.
|
||||||
|
|
||||||
|
1. Use a noun for a function that only reports a value (`Owner()`,
|
||||||
|
`JobName(key)`), so that a call reads as the value it gives.
|
||||||
|
|
||||||
|
1. Use a verb for a function that does work, even when it also returns a result
|
||||||
|
(`Parse`, `WriteDetail(w)`), so that a call reads as the work it does.
|
||||||
|
|
||||||
1. Never start a getter with `Get` (`Owner()`, not `GetOwner()`; the setter is
|
1. Never start a getter with `Get` (`Owner()`, not `GetOwner()`; the setter is
|
||||||
`SetOwner()`), because the capital letter already tells the method from the
|
`SetOwner()`), because the capital letter already tells the method from the
|
||||||
field. A call that goes to a database or the network takes a verb that says
|
field.
|
||||||
so (`Fetch`, `Load`), and `Get` stays only where it is the thing's own word,
|
|
||||||
as in an HTTP GET.
|
1. Start a getter's name with `Fetch` when it reads the value from a database
|
||||||
|
or the network (`FetchOwner`, never `Owner` or `GetOwner`), because the
|
||||||
|
reader must know the call can be slow or fail.
|
||||||
|
|
||||||
1. Name a one-method interface for its method plus `er` (`Reader`,
|
1. Name a one-method interface for its method plus `er` (`Reader`,
|
||||||
`Formatter`), because the name then says the one thing a value of it does.
|
`Formatter`), because the name then says the one thing a value of it does.
|
||||||
|
|
||||||
1. Give a method that does what a well-known method does that method's name and
|
1. Use a well-known method's name and signature for a method that does the same
|
||||||
signature: `String()`, never `ToString()`. Give a method that does anything
|
thing (`String()`, never `ToString()`), because readers and the standard
|
||||||
else another name, because readers and the standard interfaces rely on
|
interfaces expect them.
|
||||||
`Read`, `Write`, `Close` and `String` meaning one thing.
|
|
||||||
|
1. Give another name to a method that differs in meaning or signature from a
|
||||||
|
well-known method of the same name (`Read`, `Write`, `Close`, `String`),
|
||||||
|
because readers rely on each name meaning one thing.
|
||||||
|
|
||||||
1. Write an initialism in one case throughout (`ServeHTTP`, `appID`, `URL` or
|
1. Write an initialism in one case throughout (`ServeHTTP`, `appID`, `URL` or
|
||||||
`url`; never `Url`, `Id` or `Http`), because that is how the standard
|
`url`; never `Url`, `Id` or `Http`), because that is how the standard
|
||||||
@@ -575,13 +587,15 @@ exported name, and reads them as one name: `http.Server`, `list.New`.
|
|||||||
|
|
||||||
## Local names
|
## Local names
|
||||||
|
|
||||||
1. Match a local name's length to the distance between its declaration and its
|
1. Match a local name's length to how far from its declaration it is used (`i`
|
||||||
last use (`i`, `r` and `db` across a few lines, a full word or two across a
|
in a short loop), because a reader far from the declaration has only the
|
||||||
long function), because a reader far from the declaration has only the name.
|
name.
|
||||||
|
|
||||||
1. Name a receiver with one or two letters, the same in every method of its
|
1. Name a receiver with one or two letters, never `this`, `self` or `me`,
|
||||||
type, never `this`, `self` or `me`, because it appears on nearly every line
|
because its role is plain from the method.
|
||||||
of those methods.
|
|
||||||
|
1. Use the same receiver name in every method of a type, so that the name
|
||||||
|
always means the receiver.
|
||||||
|
|
||||||
# Other Golang Tips and Best Practices (Optional)
|
# Other Golang Tips and Best Practices (Optional)
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
title: Existing Repo Checklist
|
title: Existing Repo Checklist
|
||||||
last_modified: 2026-11-09
|
last_modified: 2026-11-16
|
||||||
---
|
---
|
||||||
|
|
||||||
Use this checklist when beginning work in a repo that may not yet conform to our
|
Use this checklist when beginning work in a repo that may not yet conform to our
|
||||||
@@ -49,32 +49,20 @@ with your task.
|
|||||||
`--target` names it, so a lost `COPY --from=` edge leaves `docker build .`
|
`--target` names it, so a lost `COPY --from=` edge leaves `docker build .`
|
||||||
passing while the gate never runs. Confirm by planting a violation, not by
|
passing while the gate never runs. Confirm by planting a violation, not by
|
||||||
reading the file.
|
reading the file.
|
||||||
- [ ] In every stage, every step that lints, tests or compiles comes after
|
- [ ] No `docker build` in `script/` passes `--no-cache` or a cache-busting
|
||||||
`ARG CACHEBUST`. `ARG CACHEBUST` comes right after these steps:
|
build argument such as `CACHEBUST`, and no `Dockerfile` stage declares
|
||||||
- the steps that install system packages
|
`ARG CACHEBUST`.
|
||||||
- the steps that download Go's modules
|
|
||||||
- the step that runs `script/bootstrap` to install a Python `test` phase's
|
|
||||||
packages from `Pipfile.lock`
|
|
||||||
- [ ] A stage with none of these steps declares `ARG CACHEBUST` right after
|
|
||||||
`FROM`. A step that also installs anything else comes after
|
|
||||||
`ARG CACHEBUST` too. A `script/bootstrap` that also installs node packages
|
|
||||||
is one. The `script/` builds pass a new `CACHEBUST` value on every build,
|
|
||||||
which reruns every `RUN` step after that line and leaves the layers above
|
|
||||||
it and the cache mounts in place; `--no-cache` would build those layers
|
|
||||||
again and empty the mounts. A stage without the `ARG` line is served from
|
|
||||||
cache on an unchanged tree, so the scripts and the `ARG` lines are
|
|
||||||
re-vendored in one commit.
|
|
||||||
- [ ] Go: each Go stage downloads the modules (`COPY go.mod go.sum ./`,
|
- [ ] Go: each Go stage downloads the modules (`COPY go.mod go.sum ./`,
|
||||||
`RUN go mod download`) above `ARG CACHEBUST`; the steps that compile
|
`RUN go mod download`) before `COPY . .`; the steps that compile
|
||||||
(`golangci-lint run`, `go test`, `go build`) mount Go's build cache
|
(`golangci-lint run`, `go test`, `go build`) mount Go's build cache
|
||||||
(`--mount=type=cache,target=/root/.cache/go-build`), `golangci-lint run`
|
(`--mount=type=cache,target=/root/.cache/go-build`), `golangci-lint run`
|
||||||
also mounts golangci-lint's
|
also mounts golangci-lint's
|
||||||
(`--mount=type=cache,target=/root/.cache/golangci-lint`), and no step
|
(`--mount=type=cache,target=/root/.cache/golangci-lint`), and no step
|
||||||
mounts anything else; both `go test` runs carry `-count=1`; a first run
|
mounts anything else; both `go test` runs carry `-count=1`; a first run
|
||||||
that timed out gets no rerun, as in the canonical Go `Dockerfile` in
|
that timed out gets no rerun, as in `examples/go.Dockerfile` in the
|
||||||
`REPO_POLICIES.md`
|
`prompts` repo
|
||||||
- [ ] Python: a `test` phase that installs its packages from `Pipfile.lock` does
|
- [ ] Python: a `test` phase that installs its packages from `Pipfile.lock` does
|
||||||
it above `ARG CACHEBUST`, with `COPY script/ script/`,
|
it before `COPY . .`, with `COPY script/ script/`,
|
||||||
`COPY Pipfile Pipfile.lock ./` and `RUN script/bootstrap`. When
|
`COPY Pipfile Pipfile.lock ./` and `RUN script/bootstrap`. When
|
||||||
`script/bootstrap` runs in that step, it installs nothing beyond these:
|
`script/bootstrap` runs in that step, it installs nothing beyond these:
|
||||||
- system packages
|
- system packages
|
||||||
@@ -91,9 +79,8 @@ with your task.
|
|||||||
a package with no wheel for the image stops the install. In that step it
|
a package with no wheel for the image stops the install. In that step it
|
||||||
installs no Python, because a step above it already did. `Pipfile` names no
|
installs no Python, because a step above it already did. `Pipfile` names no
|
||||||
`python_version`, because `--deploy` stops when the distribution's Python
|
`python_version`, because `--deploy` stops when the distribution's Python
|
||||||
differs from it. The tests run after `ARG CACHEBUST`, and every other stage
|
differs from it. The tests run after `COPY . .`, as in
|
||||||
installs its Python packages after it, as in the Python `test` phase example
|
`examples/python-test-phase.Dockerfile` in the `prompts` repo
|
||||||
in `REPO_POLICIES.md`
|
|
||||||
|
|
||||||
- [ ] The gate phases invoke their tools directly, never through `make lint` or
|
- [ ] The gate phases invoke their tools directly, never through `make lint` or
|
||||||
`script/test` — those are themselves a `docker build` and would recurse
|
`script/test` — those are themselves a `docker build` and would recurse
|
||||||
@@ -223,23 +210,21 @@ with your task.
|
|||||||
- [ ] README has an **Entrypoints** section documenting the `script/`
|
- [ ] README has an **Entrypoints** section documenting the `script/`
|
||||||
entrypoints and linking the standard
|
entrypoints and linking the standard
|
||||||
- [ ] `script/lint` and `script/test` each run
|
- [ ] `script/lint` and `script/test` each run
|
||||||
`docker build --build-arg CACHEBUST="$(date +%s)-$$" --target <phase> --output type=cacheonly .`,
|
`docker build --target <phase> --output type=cacheonly .`, which builds
|
||||||
which builds their phase by name and writes no image, and no host
|
their phase by name and writes no image, and no host invocation anywhere
|
||||||
invocation anywhere in the repo can produce a lint verdict — grep for the
|
in the repo can produce a lint verdict — grep for the linter's own name
|
||||||
linter's own name across `script/`, the `Makefile` and CI config, not just
|
across `script/`, the `Makefile` and CI config, not just `script/lint`. A
|
||||||
`script/lint`. A second path is likeliest here: a `make lint-fast`, an
|
second path is likeliest here: a `make lint-fast`, an older
|
||||||
older host-versus-container branch, or a CI step calling the binary
|
host-versus-container branch, or a CI step calling the binary directly.
|
||||||
directly. `script/fmt` and `script/fmt-check` are expected hits and stay
|
`script/fmt` and `script/fmt-check` are expected hits and stay on the
|
||||||
on the host.
|
host.
|
||||||
- [ ] No `docker build` in `script/` leaves a dangling image behind:
|
- [ ] No `docker build` in `script/` leaves a dangling image behind:
|
||||||
`script/lint` and `script/test` write no image, and `script/docker` and
|
`script/lint` and `script/test` write no image, and `script/docker` and
|
||||||
`script/cibuild` tag theirs. A build that writes an untagged image leaves
|
`script/cibuild` tag theirs. A build that writes an untagged image leaves
|
||||||
one behind on every run, on every host and CI runner.
|
one behind on every run, on every host and CI runner.
|
||||||
- [ ] `script/cibuild` runs `script/bootstrap` before `script/check`, and builds
|
- [ ] `script/cibuild` runs `script/bootstrap` before `script/check`. Without
|
||||||
the image with a new `CACHEBUST` value on every build, like every
|
the bootstrap the CI run dies in `script/fmt-check`, which runs the
|
||||||
`docker build` in `script/`. Without the bootstrap the CI run dies in
|
formatter on the host and finds nothing installed.
|
||||||
`script/fmt-check`, which runs the formatter on the host and finds nothing
|
|
||||||
installed.
|
|
||||||
- [ ] `script/bootstrap` installs node, yarn and the node packages only when
|
- [ ] `script/bootstrap` installs node, yarn and the node packages only when
|
||||||
`yarn.lock` is in the tree. node and yarn come from the distribution when
|
`yarn.lock` is in the tree. node and yarn come from the distribution when
|
||||||
they are missing. It installs the node packages with
|
they are missing. It installs the node packages with
|
||||||
@@ -327,14 +312,7 @@ with your task.
|
|||||||
- [ ] `script/cibuild` succeeds in a fresh clone on a host carrying what CI has.
|
- [ ] `script/cibuild` succeeds in a fresh clone on a host carrying what CI has.
|
||||||
That host is the runner image
|
That host is the runner image
|
||||||
`docker.gitea.com/runner-images:ubuntu-latest`, which has docker, git and
|
`docker.gitea.com/runner-images:ubuntu-latest`, which has docker, git and
|
||||||
node 24. Take any yarn off `PATH` first. The run must show that the checks
|
node 24. Take any yarn off `PATH` first.
|
||||||
executed. A sub-second build means nothing ran. So does `CACHED` on a step
|
|
||||||
that lints or tests, one of the `RUN` steps below `ARG CACHEBUST`. Above
|
|
||||||
that line, these steps are expected to show `CACHED`:
|
|
||||||
- the steps that install system packages
|
|
||||||
- the steps that download Go's modules
|
|
||||||
- the step that runs `script/bootstrap` to install a Python `test` phase's
|
|
||||||
packages from `Pipfile.lock`
|
|
||||||
- [ ] A planted lint violation fails both `make lint` and a plain
|
- [ ] A planted lint violation fails both `make lint` and a plain
|
||||||
`docker build .`; revert it afterwards
|
`docker build .`; revert it afterwards
|
||||||
- [ ] Commit and merge fixes before starting your actual task
|
- [ ] Commit and merge fixes before starting your actual task
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
title: New Repo Checklist
|
title: New Repo Checklist
|
||||||
last_modified: 2026-11-09
|
last_modified: 2026-11-16
|
||||||
---
|
---
|
||||||
|
|
||||||
Use this checklist when creating a new repository from scratch. Follow the steps
|
Use this checklist when creating a new repository from scratch. Follow the steps
|
||||||
@@ -118,32 +118,17 @@ Template files can be fetched from:
|
|||||||
stage carries a `COPY --from=` of a harmless file from each so the image
|
stage carries a `COPY --from=` of a harmless file from each so the image
|
||||||
cannot be built unless both passed. Keep the final stage last: a stage
|
cannot be built unless both passed. Keep the final stage last: a stage
|
||||||
nothing depends on is built only when `--target` names it.
|
nothing depends on is built only when `--target` names it.
|
||||||
- In every stage, every step that lints, tests or compiles comes after
|
|
||||||
`ARG CACHEBUST`. `ARG CACHEBUST` comes right after these steps:
|
|
||||||
- the steps that install system packages
|
|
||||||
- the steps that download Go's modules
|
|
||||||
- the step that runs `script/bootstrap` to install a Python `test`
|
|
||||||
phase's packages from `Pipfile.lock`
|
|
||||||
- A stage with none of these steps declares `ARG CACHEBUST` right after
|
|
||||||
`FROM`. A step that also installs anything else comes after
|
|
||||||
`ARG CACHEBUST` too. A `script/bootstrap` that also installs node packages
|
|
||||||
is one. The `script/` builds pass a new `CACHEBUST` value on every build,
|
|
||||||
which reruns every `RUN` step after that line and leaves the layers above
|
|
||||||
it and the cache mounts in place; `--no-cache` would build those layers
|
|
||||||
again and empty the mounts. A stage without the `ARG` line is served from
|
|
||||||
cache on an unchanged tree, so the scripts and every stage's
|
|
||||||
`ARG CACHEBUST` line are added in the same commit.
|
|
||||||
- Go: each Go stage downloads the modules (`COPY go.mod go.sum ./`,
|
- Go: each Go stage downloads the modules (`COPY go.mod go.sum ./`,
|
||||||
`RUN go mod download`) above `ARG CACHEBUST`; the steps that compile
|
`RUN go mod download`) before `COPY . .`; the steps that compile
|
||||||
(`golangci-lint run`, `go test`, `go build`) mount Go's build cache
|
(`golangci-lint run`, `go test`, `go build`) mount Go's build cache
|
||||||
(`--mount=type=cache,target=/root/.cache/go-build`), `golangci-lint run`
|
(`--mount=type=cache,target=/root/.cache/go-build`), `golangci-lint run`
|
||||||
also mounts golangci-lint's
|
also mounts golangci-lint's
|
||||||
(`--mount=type=cache,target=/root/.cache/golangci-lint`), and no step
|
(`--mount=type=cache,target=/root/.cache/golangci-lint`), and no step
|
||||||
mounts anything else; both `go test` runs carry `-count=1`; a first run
|
mounts anything else; both `go test` runs carry `-count=1`; a first run
|
||||||
that timed out gets no rerun, as in the canonical Go `Dockerfile` in
|
that timed out gets no rerun, as in `examples/go.Dockerfile` in the
|
||||||
`REPO_POLICIES.md`
|
`prompts` repo
|
||||||
- Python: a `test` phase that installs its packages from `Pipfile.lock` does
|
- Python: a `test` phase that installs its packages from `Pipfile.lock` does
|
||||||
it above `ARG CACHEBUST`, with `COPY script/ script/`,
|
it before `COPY . .`, with `COPY script/ script/`,
|
||||||
`COPY Pipfile Pipfile.lock ./` and `RUN script/bootstrap`. When
|
`COPY Pipfile Pipfile.lock ./` and `RUN script/bootstrap`. When
|
||||||
`script/bootstrap` runs in that step, it installs nothing beyond these:
|
`script/bootstrap` runs in that step, it installs nothing beyond these:
|
||||||
- system packages
|
- system packages
|
||||||
@@ -161,9 +146,8 @@ Template files can be fetched from:
|
|||||||
for the image stops the install. In that step it installs no Python,
|
for the image stops the install. In that step it installs no Python,
|
||||||
because a step above it already did. `Pipfile` names no
|
because a step above it already did. `Pipfile` names no
|
||||||
`python_version`, because `--deploy` stops when the distribution's
|
`python_version`, because `--deploy` stops when the distribution's
|
||||||
Python differs from it. The tests run after `ARG CACHEBUST`, and every
|
Python differs from it. The tests run after `COPY . .`, as in
|
||||||
other stage installs its Python packages after it, as in the Python
|
`examples/python-test-phase.Dockerfile` in the `prompts` repo
|
||||||
`test` phase example in `REPO_POLICIES.md`
|
|
||||||
|
|
||||||
- Server: the final stage builds and runs the application
|
- Server: the final stage builds and runs the application
|
||||||
- Non-server: the final stage brings up the dev environment
|
- Non-server: the final stage brings up the dev environment
|
||||||
@@ -227,13 +211,12 @@ are thin shims calling them. Model scripts:
|
|||||||
- [ ] `script/setup` / `make setup` — readies a fresh clone: runs `bootstrap`,
|
- [ ] `script/setup` / `make setup` — readies a fresh clone: runs `bootstrap`,
|
||||||
then `install-precommit`, plus repo-specific init
|
then `install-precommit`, plus repo-specific init
|
||||||
- [ ] `script/test` / `make test` —
|
- [ ] `script/test` / `make test` —
|
||||||
`docker build --build-arg CACHEBUST="$(date +%s)-$$" --target test --output type=cacheonly .`,
|
`docker build --target test --output type=cacheonly .`, which writes no
|
||||||
which writes no image; the phase runs real tests, not a no-op (90-second
|
image; the phase runs real tests, not a no-op (90-second timeout,
|
||||||
timeout, 60-second hard cap on wall time)
|
60-second hard cap on wall time)
|
||||||
- [ ] `script/lint` / `make lint` —
|
- [ ] `script/lint` / `make lint` —
|
||||||
`docker build --build-arg CACHEBUST="$(date +%s)-$$" --target lint --output type=cacheonly .`,
|
`docker build --target lint --output type=cacheonly .`, which writes no
|
||||||
which writes no image. No lint verdict may come from a host invocation of
|
image. No lint verdict may come from a host invocation of the linter.
|
||||||
the linter.
|
|
||||||
- [ ] `script/fmt` / `make fmt` — formats code (writes; native, never in a
|
- [ ] `script/fmt` / `make fmt` — formats code (writes; native, never in a
|
||||||
container). Go code gets `gofmt`, then `golines -m 77`.
|
container). Go code gets `gofmt`, then `golines -m 77`.
|
||||||
- [ ] `script/fmt-check` / `make fmt-check` — checks formatting (read-only;
|
- [ ] `script/fmt-check` / `make fmt-check` — checks formatting (read-only;
|
||||||
@@ -245,16 +228,15 @@ are thin shims calling them. Model scripts:
|
|||||||
- [ ] `script/projectname` — outputs the project name (used by `script/docker`
|
- [ ] `script/projectname` — outputs the project name (used by `script/docker`
|
||||||
for the image tag)
|
for the image tag)
|
||||||
- [ ] `script/docker` / `make docker` — builds Docker image, tagged via
|
- [ ] `script/docker` / `make docker` — builds Docker image, tagged via
|
||||||
`script/projectname` (byte-identical across repos); a new `CACHEBUST`
|
`script/projectname` (byte-identical across repos), with the version as a
|
||||||
value on every build, plus the version as a build arg
|
build arg
|
||||||
- [ ] `script/cibuild` — cd to repo root, run `script/bootstrap`, run
|
- [ ] `script/cibuild` — cd to repo root, run `script/bootstrap`, run
|
||||||
`script/check`, then
|
`script/check`, then
|
||||||
`docker build --build-arg CACHEBUST="$(date +%s)-$$" --build-arg VERSION="$version" -t "$tag" .`
|
`docker build --build-arg VERSION="$version" -t "$tag" .` (what CI runs),
|
||||||
(what CI runs), with `$version` from
|
with `$version` from `git describe --tags --always --dirty` (`unknown` if
|
||||||
`git describe --tags --always --dirty` (`unknown` if empty) and `$tag`
|
empty) and `$tag` from `script/projectname`, each assigned on its own line
|
||||||
from `script/projectname`, each assigned on its own line before the build.
|
before the build. The bootstrap is required: CI checks out and runs this
|
||||||
The bootstrap is required: CI checks out and runs this alone, and
|
alone, and `script/fmt-check` runs the formatter on the host.
|
||||||
`script/fmt-check` runs the formatter on the host.
|
|
||||||
- [ ] `script/bootstrap`, `script/fmt` and `script/fmt-check` run yarn by
|
- [ ] `script/bootstrap`, `script/fmt` and `script/fmt-check` run yarn by
|
||||||
whichever name is present: `yarn`, or `yarnpkg` on Debian and Ubuntu. With
|
whichever name is present: `yarn`, or `yarnpkg` on Debian and Ubuntu. With
|
||||||
neither name on `PATH`, `script/fmt` and `script/fmt-check` print one line
|
neither name on `PATH`, `script/fmt` and `script/fmt-check` print one line
|
||||||
@@ -279,14 +261,7 @@ are thin shims calling them. Model scripts:
|
|||||||
- [ ] `script/cibuild` succeeds in a fresh clone on a host carrying what CI has.
|
- [ ] `script/cibuild` succeeds in a fresh clone on a host carrying what CI has.
|
||||||
That host is the runner image
|
That host is the runner image
|
||||||
`docker.gitea.com/runner-images:ubuntu-latest`, which has docker, git and
|
`docker.gitea.com/runner-images:ubuntu-latest`, which has docker, git and
|
||||||
node 24. Take any yarn off `PATH` first. The run must show that the checks
|
node 24. Take any yarn off `PATH` first.
|
||||||
executed. A sub-second build means nothing ran. So does `CACHED` on a step
|
|
||||||
that lints or tests, one of the `RUN` steps below `ARG CACHEBUST`. Above
|
|
||||||
that line, these steps are expected to show `CACHED`:
|
|
||||||
- the steps that install system packages
|
|
||||||
- the steps that download Go's modules
|
|
||||||
- the step that runs `script/bootstrap` to install a Python `test` phase's
|
|
||||||
packages from `Pipfile.lock`
|
|
||||||
- [ ] Plant a lint violation and confirm both `make lint` and a plain
|
- [ ] Plant a lint violation and confirm both `make lint` and a plain
|
||||||
`docker build .` fail on it; revert. A plain build that passes proves the
|
`docker build .` fail on it; revert. A plain build that passes proves the
|
||||||
final stage is missing its `COPY --from=` edge to the gate phases.
|
final stage is missing its `COPY --from=` edge to the gate phases.
|
||||||
|
|||||||
+575
-801
File diff suppressed because it is too large.
Load diff
+1
-9
@@ -2,12 +2,6 @@
|
|||||||
# script/cibuild: run the CI build. It bootstraps first: a CI runner
|
# script/cibuild: run the CI build. It bootstraps first: a CI runner
|
||||||
# checks out and runs this and nothing else, and script/fmt-check runs
|
# checks out and runs this and nothing else, and script/fmt-check runs
|
||||||
# the formatter on the host, which a pristine checkout cannot do.
|
# the formatter on the host, which a pristine checkout cannot do.
|
||||||
# A new CACHEBUST value reruns every RUN step after the ARG CACHEBUST
|
|
||||||
# line, since a cached gate phase is a check that did not run; unlike
|
|
||||||
# --no-cache, it keeps the layers above that line and the cache mounts.
|
|
||||||
# This relies on every stage of the Dockerfile declaring ARG CACHEBUST
|
|
||||||
# before every step that lints, tests or compiles; a stage without that
|
|
||||||
# line is served from cache on an unchanged tree, with no warning.
|
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd -P)"
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd -P)"
|
||||||
@@ -25,9 +19,7 @@ main() {
|
|||||||
version="$(git describe --tags --always --dirty 2>/dev/null || true)"
|
version="$(git describe --tags --always --dirty 2>/dev/null || true)"
|
||||||
[ -n "$version" ] || version="unknown"
|
[ -n "$version" ] || version="unknown"
|
||||||
tag="$("$SCRIPT_DIR/projectname")"
|
tag="$("$SCRIPT_DIR/projectname")"
|
||||||
docker build --build-arg CACHEBUST="$(date +%s)-$$" \
|
docker build --build-arg VERSION="$version" -t "$tag" .
|
||||||
--build-arg VERSION="$version" \
|
|
||||||
-t "$tag" .
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main "$@"
|
main "$@"
|
||||||
+1
-9
@@ -1,12 +1,6 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# script/docker: build the Docker image tagged with the project name.
|
# script/docker: build the Docker image tagged with the project name.
|
||||||
# Identical in all repos; the tag comes from script/projectname.
|
# Identical in all repos; the tag comes from script/projectname.
|
||||||
# A new CACHEBUST value reruns every RUN step after the ARG CACHEBUST
|
|
||||||
# line, since a cached gate phase is a check that did not run; unlike
|
|
||||||
# --no-cache, it keeps the layers above that line and the cache mounts.
|
|
||||||
# This relies on every stage of the Dockerfile declaring ARG CACHEBUST
|
|
||||||
# before every step that lints, tests or compiles; a stage without that
|
|
||||||
# line is served from cache on an unchanged tree, with no warning.
|
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd -P)"
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd -P)"
|
||||||
@@ -22,9 +16,7 @@ main() {
|
|||||||
version="$(git describe --tags --always --dirty 2>/dev/null || true)"
|
version="$(git describe --tags --always --dirty 2>/dev/null || true)"
|
||||||
[ -n "$version" ] || version="unknown"
|
[ -n "$version" ] || version="unknown"
|
||||||
tag="$("$SCRIPT_DIR/projectname")"
|
tag="$("$SCRIPT_DIR/projectname")"
|
||||||
docker build --build-arg CACHEBUST="$(date +%s)-$$" \
|
docker build --build-arg VERSION="$version" -t "$tag" .
|
||||||
--build-arg VERSION="$version" \
|
|
||||||
-t "$tag" .
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main "$@"
|
main "$@"
|
||||||
+2
-11
@@ -5,14 +5,7 @@
|
|||||||
# make its answer untrustworthy.
|
# make its answer untrustworthy.
|
||||||
#
|
#
|
||||||
# --target builds the lint phase and the stages it depends on, nothing
|
# --target builds the lint phase and the stages it depends on, nothing
|
||||||
# else. A new CACHEBUST value reruns every RUN step after
|
# else. --output type=cacheonly writes no image, since nothing uses one.
|
||||||
# the ARG CACHEBUST line, since a cached lint layer is a lint that did
|
|
||||||
# not run; unlike --no-cache, it keeps the layers above that line and
|
|
||||||
# the cache mounts. This relies on every stage of the Dockerfile
|
|
||||||
# declaring ARG CACHEBUST before every step that lints, tests or
|
|
||||||
# compiles; a stage without that line is served from cache on an
|
|
||||||
# unchanged tree, with no warning.
|
|
||||||
# --output type=cacheonly writes no image, since nothing uses one.
|
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd -P)"
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd -P)"
|
||||||
@@ -20,9 +13,7 @@ ROOT="$(cd "$SCRIPT_DIR/.." && pwd -P)"
|
|||||||
|
|
||||||
main() {
|
main() {
|
||||||
cd "$ROOT"
|
cd "$ROOT"
|
||||||
docker build --build-arg CACHEBUST="$(date +%s)-$$" \
|
docker build --target lint --output type=cacheonly .
|
||||||
--target lint \
|
|
||||||
--output type=cacheonly .
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main "$@"
|
main "$@"
|
||||||
+3
-10
@@ -2,13 +2,8 @@
|
|||||||
# script/test: run the test suite. Testing is a phase of the Dockerfile
|
# script/test: run the test suite. Testing is a phase of the Dockerfile
|
||||||
# and this builds that phase, on the same terms as script/lint:
|
# and this builds that phase, on the same terms as script/lint:
|
||||||
# --target so that only the test phase and the stages it depends on are
|
# --target so that only the test phase and the stages it depends on are
|
||||||
# built, and a new CACHEBUST value because a cached test layer is a test
|
# built, and --output type=cacheonly so that no image is written, since
|
||||||
# that did not run; unlike --no-cache, it keeps the layers above the ARG
|
# nothing uses one.
|
||||||
# CACHEBUST line and the cache mounts. This relies on every stage of the
|
|
||||||
# Dockerfile declaring ARG CACHEBUST before every step that lints, tests
|
|
||||||
# or compiles; a stage without that line is served from cache on an
|
|
||||||
# unchanged tree, with no warning. --output type=cacheonly writes no
|
|
||||||
# image, since nothing uses one.
|
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd -P)"
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd -P)"
|
||||||
@@ -16,9 +11,7 @@ ROOT="$(cd "$SCRIPT_DIR/.." && pwd -P)"
|
|||||||
|
|
||||||
main() {
|
main() {
|
||||||
cd "$ROOT"
|
cd "$ROOT"
|
||||||
docker build --build-arg CACHEBUST="$(date +%s)-$$" \
|
docker build --target test --output type=cacheonly .
|
||||||
--target test \
|
|
||||||
--output type=cacheonly .
|
|
||||||
}
|
}
|
||||||
|
|
||||||
main "$@"
|
main "$@"
|
||||||
Reference in new issue
Block a user