-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Optimize Docker build with bind mounts #208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
db3d8f7
bc3a1cc
011ce96
4ebc718
240d41a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| .github | ||
| .vscode | ||
| script | ||
| third-party | ||
| .dockerignore | ||
| .gitignore | ||
| **/*.yml | ||
| **/*.yaml | ||
| **/*.md | ||
| **/*_test.go | ||
| LICENSE |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,26 @@ | ||
| FROM golang:1.24.2-alpine AS build | ||
| ARG VERSION="dev" | ||
|
|
||
| FROM golang:1.24.2 AS build | ||
| # allow this step access to build arg | ||
| ARG VERSION | ||
| # Set the working directory | ||
| WORKDIR /build | ||
|
|
||
| RUN go env -w GOMODCACHE=/root/.cache/go-build | ||
| # Install git | ||
| RUN --mount=type=cache,target=/var/cache/apk \ | ||
| apk add git | ||
|
|
||
| # Install dependencies | ||
| COPY go.mod go.sum ./ | ||
| RUN --mount=type=cache,target=/root/.cache/go-build go mod download | ||
|
|
||
| COPY . ./ | ||
| # Build the server | ||
| RUN --mount=type=cache,target=/root/.cache/go-build CGO_ENABLED=0 go build -ldflags="-s -w -X main.version=${VERSION} -X main.commit=$(git rev-parse HEAD) -X main.date=$(date -u +%Y-%m-%dT%H:%M:%SZ)" \ | ||
| -o github-mcp-server cmd/github-mcp-server/main.go | ||
| # go build automatically download required module dependencies to /go/pkg/mod | ||
| RUN --mount=type=cache,target=/go/pkg/mod \ | ||
| --mount=type=cache,target=/root/.cache/go-build \ | ||
| --mount=type=bind,target=. \ | ||
| CGO_ENABLED=0 go build -ldflags="-s -w -X main.version=${VERSION} -X main.commit=$(git rev-parse HEAD) -X main.date=$(date -u +%Y-%m-%dT%H:%M:%SZ)" \ | ||
| -o /bin/github-mcp-server cmd/github-mcp-server/main.go | ||
|
Comment on lines
-11
to
+17
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Size of Size of Running The |
||
|
|
||
| # Make a stage to run the app | ||
| FROM gcr.io/distroless/base-debian12 | ||
| # Set the working directory | ||
| WORKDIR /server | ||
| # Copy the binary from the build stage | ||
| COPY --from=build /build/github-mcp-server . | ||
| COPY --from=build /bin/github-mcp-server . | ||
| # Command to run the server | ||
| CMD ["./github-mcp-server", "stdio"] | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, this breaks building with
podman.Maybe I fail to see the optimization here since this is in the
buildstage.Is it a big issue with a few fatter layers here?
The issue is that
git rev-parsedoesn't work below when not using BuildKitThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adding
--security-opt label=disablewhen building with podman is a workaround