Files
ai/Dockerfile.kaniko
zeekayandHanzo Dev fa67e450e4 build: pin the Go builders to 1.26.5 and let the toolchain download
The official golang images set GOTOOLCHAIN=local, so a go.mod `go` directive
newer than the base image fails the build at the first go command:

    go: go.mod requires go >= 1.26.5 (running go 1.26.4; GOTOOLCHAIN=local)

Two orthogonal changes. Pinning the base to the exact patch go.mod names makes
the build hermetic — the versions match, so no toolchain is downloaded.
GOTOOLCHAIN=auto is the resilience half: when go.mod next moves ahead of the
pin, the toolchain is fetched and checksum-verified against sum.golang.org
instead of failing the build outright.

All three Dockerfiles carried a builder older than the module. riscv64 moves
from 1.23.11-alpine3.21 to 1.26.5-alpine: riscv64/golang publishes no
1.26.5-alpine3.21 or -alpine3.22 tag (both 404), only the unsuffixed variant.

Co-authored-by: Hanzo Dev <[email protected]>
2026-08-01 16:45:08 -07:00

70 lines
2.7 KiB
Docker

# Kaniko-native build for hanzoai/ai (the `aid` AI daemon).
#
# Identical artifact to the canonical BuildKit Dockerfile `standard` target,
# but authenticates private cross-org Go modules (github.com/hanzoai/*,
# github.com/luxfi/*, github.com/zap-proto/*) via a plain --build-arg instead
# of a BuildKit `--mount=type=secret`, which kaniko does not support.
#
# Build (in-cluster kaniko):
# --dockerfile=Dockerfile.kaniko
# --build-arg=GH_TOKEN=<classic PAT with hanzoai+luxfi read>
# --destination=ghcr.io/hanzoai/ai:<tag>-amd64
#
# The GH_TOKEN is consumed only inside the `back` builder stage and is never
# copied into the final `standard` image, so it does not leak into layers that
# get pushed (kaniko squashes per-RUN; the token lives only in the builder).
# syntax=docker/dockerfile:1
FROM --platform=$BUILDPLATFORM node:22-alpine AS front
RUN npm install -g [email protected]
WORKDIR /web
COPY ./web .
ENV NODE_OPTIONS="--max-old-space-size=4096"
RUN pnpm install --frozen-lockfile && pnpm build
FROM golang:1.26.5-alpine AS back
# go.mod pins the toolchain. The golang base image sets GOTOOLCHAIN=local,
# which turns a `go` directive newer than the image into a hard build
# failure instead of a download.
ENV GOTOOLCHAIN=auto
RUN apk add --no-cache git
WORKDIR /go/src/hanzo-cloud
ARG GH_TOKEN=""
# Private cross-org modules are fetched via authenticated git, bypassing the
# public proxy. Unconditional insteadOf (vs the BuildKit Dockerfile's guarded
# block) because kaniko provides the token as a build-arg, not a secret file.
ENV GOPRIVATE=github.com/hanzoai/*,github.com/lux-private/*,github.com/zap-proto/*
COPY go.mod go.sum ./
RUN if [ -n "$GH_TOKEN" ]; then \
git config --global url."https://x-access-token:${GH_TOKEN}@github.com/".insteadOf "https://github.com/"; \
fi && \
go mod download
COPY . .
RUN CGO_ENABLED=0 go build -ldflags="-w -s" -o server ./cmd/aid
FROM alpine:3.21 AS standard
LABEL maintainer="https://hanzo.ai/"
ARG USER=hanzo
RUN apk add --no-cache ca-certificates curl sudo \
&& update-ca-certificates \
&& adduser -D $USER -u 1000 \
&& echo "$USER ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/$USER \
&& chmod 0440 /etc/sudoers.d/$USER \
&& mkdir logs files \
&& chown -R $USER:$USER logs files
USER 1000
WORKDIR /
COPY --from=back --chown=$USER:$USER /go/src/hanzo-cloud/server ./server
COPY --from=back --chown=$USER:$USER /go/src/hanzo-cloud/data ./data
COPY --from=back --chown=$USER:$USER /go/src/hanzo-cloud/conf/app.conf ./conf/app.conf
COPY --from=back --chown=$USER:$USER /go/src/hanzo-cloud/conf/models.yaml ./conf/models.yaml
COPY --from=front --chown=$USER:$USER /web/build ./web/build
ENV RUNNING_IN_DOCKER=true
ENTRYPOINT ["/server"]