diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..8f302e7c --- /dev/null +++ b/.dockerignore @@ -0,0 +1,11 @@ +.github +.vscode +script +third-party +.dockerignore +.gitignore +**/*.yml +**/*.yaml +**/*.md +**/*_test.go +LICENSE diff --git a/Dockerfile b/Dockerfile index 22c405c4..ae2a1505 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 # 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"]