-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
optimize Dockerfile, and stage cache
- Loading branch information
Showing
1 changed file
with
24 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,40 @@ | ||
FROM --platform=$TARGETPLATFORM golang:1.22-bullseye as build | ||
ARG GO_VERSION=1.22 | ||
ARG BASE_IMAGE="golang:${GO_VERSION}-bullseye" | ||
|
||
FROM --platform=$TARGETPLATFORM ${BASE_IMAGE} as build | ||
|
||
ENV PROJ_ROOT="/go/src/github.com/erda-project/erda-infra" | ||
COPY . "${PROJ_ROOT}" | ||
WORKDIR "${PROJ_ROOT}" | ||
|
||
ARG GOPROXY=https://goproxy.cn,direct | ||
RUN go env -w GO111MODULE=on && go env -w GOPROXY="${GOPROXY}" | ||
ENV GOPROXY=https://goproxy.cn,direct \ | ||
GO111MODULE=on \ | ||
CGO_ENABLED=0 | ||
|
||
# Copy go.mod and go.sum to leverage Docker cache | ||
COPY go.mod go.sum ./ | ||
RUN --mount=type=cache,target=/go/pkg/mod \ | ||
go mod download | ||
|
||
# Copy all project files | ||
COPY . . | ||
|
||
# Install goimports and gohub | ||
RUN go install golang.org/x/tools/cmd/goimports@latest | ||
|
||
RUN --mount=type=cache,target=/root/.cache/go-build\ | ||
# Build gohub with cache mechanism | ||
RUN --mount=type=cache,target=/root/.cache/go-build \ | ||
--mount=type=cache,target=/go/pkg/mod \ | ||
cd ./tools && \ | ||
go install ./gohub && \ | ||
go install ./tools/gohub && \ | ||
gohub tools install --verbose --local | ||
|
||
|
||
FROM --platform=$TARGETPLATFORM golang:1.22-bullseye | ||
FROM --platform=$TARGETPLATFORM ${BASE_IMAGE} | ||
|
||
RUN go install golang.org/x/tools/cmd/goimports@latest | ||
|
||
# Copy built tools from build stage | ||
COPY --from=build /root/.gohub /root/.gohub | ||
COPY --from=build /go/bin/* /go/bin/ | ||
|
||
WORKDIR /go | ||
|
||
CMD gohub | ||
CMD ["gohub"] |