diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index b4583b01..4c370ebe 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -23,7 +23,7 @@ env: jobs: build: - runs-on: ubuntu-latest + runs-on: ubuntu-latest-xl permissions: contents: read packages: write @@ -67,6 +67,17 @@ jobs: with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + - name: Go Build Cache for Docker + uses: actions/cache@v4 + with: + path: go-build-cache + key: ${{ runner.os }}-go-build-cache-${{ hashFiles('**/go.sum') }} + + - name: Inject go-build-cache + uses: reproducible-containers/buildkit-cache-dance@4b2444fec0c0fb9dbf175a96c094720a692ef810 # v2.1.4 + with: + cache-source: go-build-cache + # Build and push Docker image with Buildx (don't push on PR) # https://github.com/docker/build-push-action - name: Build and push Docker image diff --git a/Dockerfile b/Dockerfile index 6b96ffec..05fe1ddd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,13 +5,18 @@ FROM golang:1.23.7 AS build ARG VERSION # Set the working directory WORKDIR /build -# Copy the current directory contents into the working directory -COPY . . + +RUN go env -w GOMODCACHE=/root/.cache/go-build + # Install dependencies -RUN go mod download +COPY go.mod go.sum ./ +RUN --mount=type=cache,target=/root/.cache/go-build go mod download + +COPY . ./ # Build the server -RUN 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)" \ +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 + # Make a stage to run the app FROM gcr.io/distroless/base-debian12 # Set the working directory