perf: shrink images and harden downloads

- Keep Go module/build and bun caches in cache mounts instead of layers.
- Split base tool downloads into layers ordered by change frequency.
- Use curl -f and pipefail so failed downloads break the build.
- Resolve the lazygit version from the release redirect instead of the
  rate-limited GitHub API.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Job79andClaude Opus 5.5 committed 2026-11-08 11:46:59 +01:00
1 parent 0397174460
commit 9c6569fa29
2 files changed
+32 -15

No files matched your search

+18 -9
View File
@@ -2,14 +2,23 @@ ARG TAG
FROM job79/base:${TAG}
USER root
RUN GO_VERSION=$(curl -sL "https://go.dev/VERSION?m=text" | head -n 1 | tr -d '\r\n') && \
curl -sL "https://go.dev/dl/${GO_VERSION}.linux-amd64.tar.gz" | tar xz -C /usr/local && \
ln -sf /usr/local/go/bin/go /usr/local/bin/go && \
ln -sf /usr/local/go/bin/gofmt /usr/local/bin/gofmt && \
GOBIN=/usr/local/bin /usr/local/go/bin/go install golang.org/x/tools/gopls@latest && \
GOBIN=/usr/local/bin /usr/local/go/bin/go install mvdan.cc/gofumpt@latest && \
GOBIN=/usr/local/bin /usr/local/go/bin/go install golang.org/x/tools/cmd/goimports@latest && \
GOBIN=/usr/local/bin /usr/local/go/bin/go install github.com/go-delve/delve/cmd/dlv@latest && \
BUN_INSTALL="/usr/local" bun install -g typescript typescript-language-server @tailwindcss/language-server svelte-language-server @biomejs/biome
RUN set -o pipefail && \
GO_VERSION=$(curl -fsSL "https://go.dev/VERSION?m=text" | head -n 1 | tr -d '\r\n') && \
curl -fsSL "https://go.dev/dl/${GO_VERSION}.linux-amd64.tar.gz" | tar xz -C /usr/local && \
ln -sf /usr/local/go/bin/go /usr/local/go/bin/gofmt /usr/local/bin/
# Build caches live in cache mounts so they don't end up in the image.
RUN --mount=type=cache,id=go-mod,target=/root/go/pkg/mod \
--mount=type=cache,id=go-build,target=/root/.cache/go-build \
for pkg in \
golang.org/x/tools/gopls \
golang.org/x/tools/cmd/goimports \
mvdan.cc/gofumpt \
github.com/go-delve/delve/cmd/dlv; \
do GOBIN=/usr/local/bin go install "$pkg@latest" || exit 1; done
RUN --mount=type=cache,id=bun-cache,target=/root/.bun-cache \
BUN_INSTALL=/usr/local BUN_INSTALL_CACHE_DIR=/root/.bun-cache bun install -g \
typescript typescript-language-server @tailwindcss/language-server svelte-language-server @biomejs/biome
USER user