Build and run are two images, from one recipe #7
+31
-38
@@ -1,40 +1,32 @@
|
|||||||
# The tool runtime: the base every module written in this toolchain is compiled on top of, and the
|
# Two images from one recipe: the one modules are COMPILED in, and the one they RUN in.
|
||||||
# container a node runs to serve them. It is handed the broker credential and the assigned modules'
|
|
||||||
# entrypoints at deploy time and serves them.
|
|
||||||
#
|
#
|
||||||
# **Built from this repository alone.** It used to copy in a compiled output directory that is not
|
# **They were the same image, and that was a mistake.** A module's recipe starts from this and
|
||||||
# in source control, and resolve the mesh's own toolkit to a sibling checkout on the same disk — so
|
# invokes the compiler out of it, so the compiler had to be here — and because the same image was
|
||||||
# it could only be produced on a workstation with two repositories laid out side by side, and its
|
# also what every module ran in, every running container on every machine carried a TypeScript
|
||||||
# fingerprint was then typed into every module's recipe by hand. That put the one artifact the whole
|
# compiler it would never invoke. 23 of the 28 MB of libraries were that compiler. It was defended
|
||||||
# toolchain stands on outside the toolchain: nothing could rebuild it, so nothing could check it,
|
# in a comment, which made a workaround look like a decision: the earlier attempt to prune the build
|
||||||
# and the rule that catches a base moving had no version on the far end of its edge and could never
|
# tools produced a smaller image that nothing could be built on, and the answer to that is two
|
||||||
# fire (novox/hq issue 044).
|
# images rather than one image that is bad at both jobs.
|
||||||
#
|
#
|
||||||
# Debian rather than Alpine, and root rather than an unprivileged user, because that is what the
|
# Kept in one recipe deliberately. They must agree about the operating system, the language version
|
||||||
# image actually in service is — and modules have already been built against it, one of which
|
# and the library, and two files drift. `build.artifacts` in module.json names a stage each.
|
||||||
# installs a package with Debian's package manager. This recipe said Alpine while serving Debian for
|
|
||||||
# as long as nobody could rebuild it to notice. Changing the operating system under every module is
|
# ---- toolchain: what a module is compiled in -------------------------------------------------
|
||||||
# a separate decision from making this buildable, and is not being taken here.
|
FROM node:22-bookworm-slim AS toolchain
|
||||||
FROM node:22-bookworm-slim AS build
|
|
||||||
# git, because a dependency named by a git URL is fetched by git and this image does not carry it.
|
# git, because a dependency named by a git URL is fetched by git and this image does not carry it.
|
||||||
# Only in the build stage: what it is needed for happens here, and a runtime that can clone is a
|
# Only here: what it is needed for happens at build time, and an image that can clone is an image
|
||||||
# runtime that can be made to clone.
|
# that can be made to clone.
|
||||||
RUN apt-get update \
|
RUN apt-get update \
|
||||||
&& apt-get install -y --no-install-recommends git ca-certificates \
|
&& apt-get install -y --no-install-recommends git ca-certificates \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY package.json package-lock.json ./
|
COPY package.json package-lock.json ./
|
||||||
# Development dependencies included: the compiler is one of them, and so is the toolkit's own — it
|
# Development dependencies included: the compiler is one, and so is the toolkit's own.
|
||||||
# builds itself on install, which is what lets it be named by a git URL rather than fetched from a
|
|
||||||
# package registry this mesh does not yet run.
|
|
||||||
RUN npm install --no-audit --no-fund
|
RUN npm install --no-audit --no-fund
|
||||||
# **And then compile the toolkit, because npm did not.** It declares a `prepare` script, which is
|
# **And then compile the toolkit, because npm did not.** It declares a `prepare` script, the hook a
|
||||||
# the hook npm is supposed to run after installing a package from git — and this npm does not run
|
# package manager is supposed to run after installing from git, and this one does not run it — so
|
||||||
# it, so the package arrives as sources with every one of its entry points pointing at a compiled
|
# the package arrives as sources with every entry point pointing at a compiled directory that is not
|
||||||
# directory that is not there. The compile is therefore done here, explicitly: install the toolkit's
|
# there. Done explicitly rather than relying on a hook firing, which would break the day it stopped.
|
||||||
# own build dependencies inside it, build it, then drop them again so they do not travel into the
|
|
||||||
# image. Doing it by hand rather than relying on the hook is also the honest arrangement — a build
|
|
||||||
# that silently depended on a hook firing would break the day it stopped, in the same invisible way.
|
|
||||||
RUN npm --prefix node_modules/@novox/mesh-sdk install --no-audit --no-fund \
|
RUN npm --prefix node_modules/@novox/mesh-sdk install --no-audit --no-fund \
|
||||||
&& npm --prefix node_modules/@novox/mesh-sdk run build \
|
&& npm --prefix node_modules/@novox/mesh-sdk run build \
|
||||||
&& npm --prefix node_modules/@novox/mesh-sdk prune --omit=dev
|
&& npm --prefix node_modules/@novox/mesh-sdk prune --omit=dev
|
||||||
@@ -42,16 +34,17 @@ COPY tsconfig.json ./
|
|||||||
COPY src ./src
|
COPY src ./src
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
# Everything the modules compile against and run on.
|
# ---- what the running image needs, and nothing else -------------------------------------------
|
||||||
#
|
# Its own stage so the toolchain image keeps its build tools while the runtime image does not. The
|
||||||
# **The build dependencies stay, and that is deliberate.** This image is not only what a module runs
|
# prune has to happen somewhere, and doing it in the toolchain stage would take the compiler out of
|
||||||
# in — it is also what every module is *compiled* in: a module's recipe starts from this and invokes
|
# the image whose whole purpose is to have one.
|
||||||
# the compiler out of these same directories. Dropping them would halve the image and break every
|
FROM toolchain AS lean
|
||||||
# module that builds on it, which is the sort of tidy-looking change that only fails somewhere else.
|
RUN npm prune --omit=dev
|
||||||
# If the two roles are ever separated, they should be separated deliberately and named separately.
|
|
||||||
FROM node:22-bookworm-slim
|
# ---- runtime: what a module runs in -----------------------------------------------------------
|
||||||
|
FROM node:22-bookworm-slim AS runtime
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY package.json ./
|
COPY package.json ./
|
||||||
COPY --from=build /app/node_modules ./node_modules
|
COPY --from=lean /app/node_modules ./node_modules
|
||||||
COPY --from=build /app/dist ./dist
|
COPY --from=toolchain /app/dist ./dist
|
||||||
ENTRYPOINT ["node", "dist/main.js"]
|
ENTRYPOINT ["node", "dist/main.js"]
|
||||||
|
|||||||
+12
-1
@@ -4,7 +4,18 @@
|
|||||||
"slug": "tools",
|
"slug": "tools",
|
||||||
"build": {
|
"build": {
|
||||||
"artifacts": [
|
"artifacts": [
|
||||||
{ "name": "runtime", "kind": "image", "from": "Dockerfile" }
|
{
|
||||||
|
"name": "build",
|
||||||
|
"kind": "image",
|
||||||
|
"from": "Dockerfile",
|
||||||
|
"target": "toolchain"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "runtime",
|
||||||
|
"kind": "image",
|
||||||
|
"from": "Dockerfile",
|
||||||
|
"target": "runtime"
|
||||||
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"resources": []
|
"resources": []
|
||||||
|
|||||||
Reference in New Issue
Block a user