github.com/koko1123/flow-go-1@v0.29.6/cmd/Dockerfile (about) 1 # syntax = docker/dockerfile:experimental 2 # NOTE: Must be run in the context of the repo's root directory 3 4 #################################### 5 ## (1) Setup the build environment 6 FROM golang:1.19-bullseye AS build-setup 7 8 RUN apt-get update 9 RUN apt-get -y install cmake zip 10 11 ## (2) Setup crypto dependencies 12 FROM build-setup AS build-env 13 14 # Build the app binary in /app 15 RUN mkdir /app 16 WORKDIR /app 17 18 ARG TARGET 19 ARG COMMIT 20 ARG VERSION 21 22 COPY . . 23 24 RUN --mount=type=cache,sharing=locked,target=/go/pkg/mod \ 25 --mount=type=cache,target=/root/.cache/go-build \ 26 make crypto_setup_gopath 27 28 #################################### 29 ## (3) Build the production app binary 30 FROM build-env as build-production 31 WORKDIR /app 32 33 ARG GOARCH=amd64 34 35 # TAGS can be overriden to modify the go build tags (e.g. build without netgo) 36 ARG TAGS="relic,netgo" 37 38 # Keep Go's build cache between builds. 39 # https://github.com/golang/go/issues/27719#issuecomment-514747274 40 RUN --mount=type=cache,sharing=locked,target=/go/pkg/mod \ 41 --mount=type=cache,target=/root/.cache/go-build \ 42 CGO_ENABLED=1 GOOS=linux go build --tags "${TAGS}" -ldflags "-extldflags -static \ 43 -X 'github.com/onflow/flow-go/cmd/build.commit=${COMMIT}' -X 'github.com/onflow/flow-go/cmd/build.semver=${VERSION}'" \ 44 -o ./app ${TARGET} 45 46 RUN chmod a+x /app/app 47 48 ## (4) Add the statically linked production binary to a distroless image 49 FROM gcr.io/distroless/base-debian11 as production 50 51 COPY --from=build-production /app/app /bin/app 52 53 ENTRYPOINT ["/bin/app"] 54 55 #################################### 56 ## (3) Build the debug app binary 57 FROM build-env as build-debug 58 WORKDIR /app 59 ARG GOARCH=amd64 60 RUN --mount=type=ssh \ 61 --mount=type=cache,sharing=locked,target=/go/pkg/mod \ 62 --mount=type=cache,target=/root/.cache/go-build \ 63 CGO_ENABLED=1 GOOS=linux go build --tags "relic,netgo" -ldflags "-extldflags -static \ 64 -X 'github.com/onflow/flow-go/cmd/build.commit=${COMMIT}' -X 'github.com/onflow/flow-go/cmd/build.semver=${VERSION}'" \ 65 -gcflags="all=-N -l" -o ./app ${TARGET} 66 67 RUN chmod a+x /app/app 68 69 ## (4) Add the statically linked debug binary to a distroless image configured for debugging 70 FROM golang:1.19-bullseye as debug 71 72 RUN go install github.com/go-delve/delve/cmd/dlv@latest 73 74 COPY --from=build-debug /app/app /bin/app 75 76 ENTRYPOINT ["dlv", "--listen=:2345", "--headless=true", "--api-version=2", "--accept-multiclient", "exec", "/bin/app", "--"] 77 78 79 FROM build-setup as environment-clean