Files
ai/Dockerfile
zeekayandHanzo Dev 0c08bd1d94 Go 1.27.1, and the code it can say more simply
Modules declare go 1.27.1 and the build images follow. go fix applied the
modernizers; omitzero is not applied, since it changes what the JSON says.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-17 01:01:10 -07:00

94 lines
3.4 KiB
Docker

# syntax=docker/dockerfile:1
FROM --platform=$BUILDPLATFORM public.ecr.aws/docker/library/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 public.ecr.aws/docker/library/golang:1.27.1-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
# Private cross-org modules (hanzoai/*, zap-proto/*) are fetched via authenticated
# git, bypassing the public proxy. gh_token is the shared docker-build.yml BuildKit
# secret; no-op when absent (local/dev).
#
# Only the private hanzoai modules resolve straight from git; GOPRIVATE already
# implies GONOPROXY and GONOSUMDB for them. Everything else — luxfi, zap-proto
# and the rest — comes through the module proxy, which holds each version
# immutably and verifies it against the checksum database, so a tag that moves
# upstream cannot change the bytes this build compiles.
ENV GOPRIVATE=github.com/hanzoai/*
COPY go.mod go.sum ./
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=secret,id=gh_token \
if [ -s /run/secrets/gh_token ]; then \
export GIT_CONFIG_COUNT=1 \
GIT_CONFIG_KEY_0="url.https://x-access-token:$(cat /run/secrets/gh_token)@github.com/.insteadOf" \
GIT_CONFIG_VALUE_0="https://github.com/"; \
fi; \
go mod download
COPY . .
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
CGO_ENABLED=0 go build -tags metrics -ldflags="-w -s" -o server ./cmd/aid
FROM public.ecr.aws/docker/library/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"]
FROM public.ecr.aws/docker/library/debian:13 AS db
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
mariadb-server \
mariadb-client \
&& rm -rf /var/lib/apt/lists/*
FROM db AS allinone
LABEL maintainer="https://hanzo.ai/"
RUN apt-get update \
&& apt-get install -y --no-install-recommends ca-certificates \
&& update-ca-certificates \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /
COPY --from=back /go/src/hanzo-cloud/server ./server
COPY --from=back /go/src/hanzo-cloud/data ./data
COPY --from=back /go/src/hanzo-cloud/docker-entrypoint.sh /docker-entrypoint.sh
COPY --from=back /go/src/hanzo-cloud/conf/app.conf ./conf/app.conf
COPY --from=back /go/src/hanzo-cloud/conf/models.yaml ./conf/models.yaml
COPY --from=front /web/build ./web/build
ENV RUNNING_IN_DOCKER=true
ENTRYPOINT ["/bin/bash"]
CMD ["/docker-entrypoint.sh"]