Repository navigation
Expand file tree
/
Copy pathDockerfile.init
More file actions
56 lines (43 loc) · 2.31 KB
/
Copy pathDockerfile.init
File metadata and controls
56 lines (43 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
FROM nixos/nix:2.32.8 AS nix
ARG NIXPKGS_REF=github:NixOS/nixpkgs/e7a3ca8092b61ff85b6a45bf863ea2b2d6a661b3
RUN nix --extra-experimental-features 'nix-command flakes' \
flake prefetch "$NIXPKGS_REF" >/dev/null && \
nix --extra-experimental-features 'nix-command flakes' \
eval --raw --impure \
--expr "(builtins.getFlake \"$NIXPKGS_REF\").outPath" \
>/tmp/agentz-nixpkgs.path
# Build the agentz binary
FROM --platform=$BUILDPLATFORM golang:1.26 AS builder
ARG TARGETOS
ARG TARGETARCH
WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download
# Copy the Go source (relies on .dockerignore to filter)
COPY . .
# Build
# the GOARCH has no default value to allow the binary to be built according to the host where the command
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -trimpath -ldflags="-s -w" -a -o agentz ./cmd/agentz
FROM debian:trixie-slim
COPY --from=nix /nix /nix
COPY --from=nix /etc/nix /etc/nix
COPY --from=nix /tmp/agentz-nixpkgs.path /etc/agentz/nixpkgs.path
COPY --from=builder /workspace/agentz /usr/local/bin/agentz
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates bash coreutils xz-utils && rm -rf /var/lib/apt/lists/*
RUN ln -sf /nix/var/nix/profiles/default /root/.nix-profile \
&& echo "build-users-group =" >> /etc/nix/nix.conf \
&& echo "experimental-features = nix-command flakes" >> /etc/nix/nix.conf \
&& echo "sandbox = false" >> /etc/nix/nix.conf
ENV PATH="/root/.nix-profile/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
ENV NIX_PROFILES="/nix/var/nix/profiles/default /root/.nix-profile"
ENV NIX_SSL_CERT_FILE="/etc/ssl/certs/ca-certificates.crt"
COPY hack/nix-init.sh /usr/local/bin/nix-init.sh
RUN chmod +x /usr/local/bin/nix-init.sh
ENTRYPOINT ["/usr/local/bin/nix-init.sh"]