# Define argument for linker flags ARG LDFLAGS=-s -w # Use a temporary build image based on Golang 1.22-alpine FROM golang:1.22-alpine as builder # Set environment variables: linker flags and disable CGO ENV LDFLAGS=$LDFLAGS CGO_ENABLED=0 # Install git RUN apk add --no-cache git # Set the working directory WORKDIR /work # Copy go.mod and go.sum files first to leverage Docker cache COPY go.mod go.sum ./ # Download dependencies - this layer will be cached as long as go.mod and go.sum don't change RUN go mod download # Now copy the rest of the source code COPY . . # Build the application RUN go build -ldflags="$LDFLAGS" -o localagent ./ FROM scratch # Copy the webui binary from the builder stage to the final image COPY --from=builder /work/localagent /localagent COPY --from=builder /etc/ssl/ /etc/ssl/ # Define the command that will be run when the container is started ENTRYPOINT ["/localagent"]