# syntax=docker/dockerfile:1 ARG GO_VERSION=1.24.0 FROM golang:${GO_VERSION} AS build WORKDIR /app RUN mkdir bin/ RUN apt-get update && \ apt-get install -y --no-install-recommends git=1:2.* musl-tools=1.2.* && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* # Install Delve debugger with static linking for Alpine RUN CGO_ENABLED=0 go install github.com/go-delve/delve/cmd/dlv@latest RUN go install -a -installsuffix cgo std COPY --link go.mod . COPY --link go.sum . COPY --link vendor/ vendor/ RUN go mod verify COPY --link cmd/ cmd/ COPY --link api/ api/ COPY --link internal/ internal/ ARG TARGETARCH ENV CGO_ENABLED=1 ENV GOARCH=${TARGETARCH} ENV CC=musl-gcc ARG GIT_VERSION=dev ARG GIT_COMMIT=unknown ARG BUILD_TIME=unknown # Build with debug symbols (remove -s -w flags) RUN go build \ -mod vendor \ -tags musl \ -trimpath \ -installsuffix cgo \ -gcflags="all=-N -l" \ -ldflags "-linkmode external -extldflags '-static -Wl,--as-needed -Wl,--gc-sections -Wl,-O1' -X queryorchestration/internal/serviceconfig/build.version=${GIT_VERSION} -X queryorchestration/internal/serviceconfig/build.gitCommit=${GIT_COMMIT} -X queryorchestration/internal/serviceconfig/build.buildTime=${BUILD_TIME}" \ -o bin/ ./cmd/... FROM golang:${GO_VERSION}-alpine AS final ENV PWD=/app WORKDIR ${PWD} # Install ca-certificates RUN apk --no-cache add ca-certificates # Copy Delve from build stage COPY --from=build /go/bin/dlv /dlv COPY --from=build /app/bin/ . EXPOSE 8080 2345 HEALTHCHECK --interval=30s --timeout=3s --start-period=1s --retries=10 \ CMD ["./healthcheck"]