Skip to content

Commit

Permalink
Merge branch 'main' into refactor/flagd/build-dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
toddbaert committed Jul 5, 2023
2 parents 19104d7 + 06f3d2e commit 3fd4d2e
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions flagd-proxy/build.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,43 @@
# Build the manager binary
FROM --platform=$BUILDPLATFORM golang:1.20-alpine AS builder

WORKDIR /workspace
WORKDIR /src

ARG TARGETOS
ARG TARGETARCH
ARG VERSION
ARG COMMIT
ARG DATE

# Copy source code
COPY flagd-proxy/ flagd-proxy
COPY core/ core
COPY flagd/ flagd

# Setup go workspace
RUN go work init
RUN go work use ./flagd-proxy
RUN go work use ./core
RUN go work use ./flagd

# Go get dependencies
RUN cd flagd-proxy && go mod download
# Download dependencies as a separate step to take advantage of Docker's caching.
# Leverage a cache mount to /go/pkg/mod/ to speed up subsequent builds.
# Leverage bind mounts to go.sum and go.mod to avoid having to copy them into
# the container.
RUN --mount=type=cache,target=/go/pkg/mod/ \
--mount=type=bind,source=./core/go.mod,target=./core/go.mod \
--mount=type=bind,source=./core/go.sum,target=./core/go.sum \
--mount=type=bind,source=./flagd/go.mod,target=./flagd/go.mod \
--mount=type=bind,source=./flagd/go.sum,target=./flagd/go.sum \
--mount=type=bind,source=./flagd-proxy/go.mod,target=./flagd-proxy/go.mod \
--mount=type=bind,source=./flagd-proxy/go.sum,target=./flagd-proxy/go.sum \
go work init ./core ./flagd ./flagd-proxy && go mod download

# # Build
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -a -ldflags "-X main.version=${VERSION} -X main.commit=${COMMIT} -X main.date=${DATE}" -o flagd-build flagd-proxy/main.go
# Build the application.
# Leverage a cache mount to /go/pkg/mod/ to speed up subsequent builds.
# Leverage a bind mount to the current directory to avoid having to copy the
# source code into the container.
RUN --mount=type=cache,target=/go/pkg/mod/ \
--mount=type=cache,target=/root/.cache/go-build \
--mount=type=bind,source=./core,target=./core \
--mount=type=bind,source=./flagd,target=./flagd \
--mount=type=bind,source=./flagd-proxy,target=./flagd-proxy \
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -a -ldflags "-X main.version=${VERSION} -X main.commit=${COMMIT} -X main.date=${DATE}" -o /bin/flagd-build flagd-proxy/main.go

# # Use distroless as minimal base image to package the manager binary
# # Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot
WORKDIR /
COPY --from=builder /workspace/flagd-build .
COPY --from=builder /bin/flagd-build .
USER 65532:65532

ENTRYPOINT ["/flagd-build"]

0 comments on commit 3fd4d2e

Please sign in to comment.