Skip to content

Commit 616c9a8

Browse files
authored
Merge pull request #28 from strowk/docker-build
Docker build
2 parents 925f670 + 943f2a4 commit 616c9a8

File tree

5 files changed

+110
-48
lines changed

5 files changed

+110
-48
lines changed

.github/workflows/install.yaml

+6-9
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,13 @@ jobs:
2121
- arm64
2222
runs-on: ${{ matrix.os }}
2323
steps:
24-
- name: Checkout
25-
uses: actions/checkout@v2
26-
27-
- name: Install mcp-k8s
24+
- name: Install mcp-k8s from docker
25+
if: ${{ matrix.os == 'ubuntu-latest' }}
2826
run: |
29-
npm install -g @strowk/mcp-k8s
27+
docker pull mcpk8s/server:latest
28+
docker run --rm mcpk8s/server:latest version
3029
31-
- name: Test mcp-k8s
30+
- name: Install mcp-k8s from npm
3231
run: |
32+
npm install -g @strowk/mcp-k8s
3333
mcp-k8s version
34-
35-
36-

.github/workflows/release.yaml

+79-4
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
1-
name: Release mcp-k8s to npm
1+
name: Release mcp-k8s
22

33
on:
44
workflow_dispatch:
55
push:
66
tags:
77
- '*'
88

9+
permissions:
10+
contents: write
11+
912
jobs:
1013
call-run-tests:
1114
uses: strowk/mcp-k8s-go/.github/workflows/test.yaml@main
1215
release:
1316
needs: call-run-tests
17+
services:
18+
registry:
19+
image: registry:2
20+
ports:
21+
- 5000:5000
1422
runs-on: ubuntu-latest
1523
steps:
1624
- name: Checkout
17-
uses: actions/checkout@v2
25+
uses: actions/checkout@v4
26+
with:
27+
fetch-depth: 0
1828

1929
- name: Set up Go
2030
uses: actions/setup-go@v5
@@ -23,12 +33,77 @@ jobs:
2333

2434
- name: Install goreleaser
2535
run: |
26-
go install github.com/goreleaser/goreleaser/v2@latest
36+
go install github.com/goreleaser/goreleaser/v2@v2.8.1
2737
which goreleaser
2838
2939
- name: Run goreleaser build
3040
run: |
31-
goreleaser build --clean
41+
goreleaser release --clean
42+
env:
43+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44+
45+
- name: Set up Docker Buildx
46+
uses: docker/setup-buildx-action@v3
47+
with:
48+
driver-opts: network=host
49+
50+
- name: Login to Docker Hub
51+
uses: docker/login-action@v3
52+
with:
53+
username: mcpk8s
54+
password: ${{ secrets.DOCKERHUB_TOKEN }}
55+
56+
# This bit is a workaround because docker can only do what we need
57+
# when pushing directly from build to docker hub (i.e push by digest)
58+
# and corresponding github action is unable to push without building
59+
- name: Precreate temp context dir
60+
run: |
61+
mkdir -p /tmp/mcpk8s/arm64
62+
echo 'FROM localhost:5000/mcpk8s/server:tmp-linux-arm64' > /tmp/mcpk8s/arm64/Dockerfile
63+
mkdir -p /tmp/mcpk8s/amd64
64+
echo 'FROM localhost:5000/mcpk8s/server:tmp-linux-amd64' > /tmp/mcpk8s/amd64/Dockerfile
65+
66+
- name: Build and push arm64 by digest
67+
id: build-arm64
68+
uses: docker/build-push-action@v6
69+
with:
70+
context: /tmp/mcpk8s/arm64
71+
platforms: linux/arm64
72+
tags: mcpk8s/server
73+
outputs: type=image,push-by-digest=true,name-canonical=true,push=true
74+
75+
- name: Build and push amd64 by digest
76+
id: build-amd64
77+
uses: docker/build-push-action@v6
78+
with:
79+
context: /tmp/mcpk8s/amd64
80+
platforms: linux/amd64
81+
tags: mcpk8s/server
82+
outputs: type=image,push-by-digest=true,name-canonical=true,push=true
83+
84+
- name: Create manifest list and push
85+
run: |
86+
goreleaser_tag=$(cat dist/metadata.json | jq -r '.tag')
87+
echo "goreleaser_tag: ${goreleaser_tag}"
88+
89+
# the magic here is simply taking outputs from build- actions
90+
# and removing sha256: prefix from them, cause we need to pass
91+
# digests further to imagetools without the prefix
92+
93+
digest_arm64="${{ steps.build-arm64.outputs.digest }}"
94+
digest_arm64="${digest_arm64#sha256:}"
95+
digest_amd64="${{ steps.build-amd64.outputs.digest }}"
96+
digest_amd64="${digest_amd64#sha256:}"
97+
98+
echo "crate multi-arch image for tag mcpk8s/server:${goreleaser_tag} with images:"
99+
echo " arm64: mcpk8s/server@sha256:${digest_arm64}"
100+
echo " amd64: mcpk8s/server@sha256:${digest_amd64}"
101+
102+
docker buildx imagetools create \
103+
-t mcpk8s/server:${goreleaser_tag} \
104+
-t mcpk8s/server:latest \
105+
mcpk8s/server@sha256:${digest_arm64} \
106+
mcpk8s/server@sha256:${digest_amd64}
32107
33108
- name: Publish to npm
34109
env:

.goreleaser.yaml

+22
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,28 @@ builds:
2323
- windows
2424
- darwin
2525

26+
dockers:
27+
- image_templates:
28+
- localhost:5000/mcpk8s/server:tmp-linux-amd64
29+
skip_push: false
30+
goarch: amd64
31+
build_flag_templates:
32+
- "--platform=linux/amd64"
33+
- "--label=org.opencontainers.image.version={{.Version}}"
34+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
35+
- "--label=org.opencontainers.image.created={{.Date}}"
36+
- "--label=org.opencontainers.image.title={{.ProjectName}}"
37+
- image_templates:
38+
- localhost:5000/mcpk8s/server:tmp-linux-arm64
39+
skip_push: false
40+
goarch: arm64
41+
build_flag_templates:
42+
- "--platform=linux/arm64"
43+
- "--label=org.opencontainers.image.version={{.Version}}"
44+
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
45+
- "--label=org.opencontainers.image.created={{.Date}}"
46+
- "--label=org.opencontainers.image.title={{.ProjectName}}"
47+
2648
archives:
2749
- format: tar.gz
2850
# this name template makes the OS and Arch compatible with the results of `uname`.

Dockerfile

+3-33
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,3 @@
1-
# Generated by https://smithery.ai. See: https://smithery.ai/docs/config#dockerfile
2-
# Start with the official Golang image to use Go tools
3-
FROM golang:1.24-alpine AS builder
4-
5-
# Set the working directory
6-
WORKDIR /app
7-
8-
# Copy the Go mod and sum files for dependency installation
9-
COPY go.mod go.sum ./
10-
11-
# Download the dependencies
12-
RUN go mod download
13-
14-
# Copy the entire source code
15-
COPY . .
16-
17-
# Build the Go application
18-
RUN go build -o mcp-k8s-go main.go
19-
20-
# Use a minimal base image for the final binary
21-
FROM alpine:latest
22-
23-
# Set the working directory
24-
WORKDIR /app
25-
26-
# Copy the compiled binary from the builder
27-
COPY --from=builder /app/mcp-k8s-go .
28-
29-
# Set the KUBECONFIG environment variable to the default path (can be overridden)
30-
ENV KUBECONFIG=/root/.kube/config
31-
32-
# Command to run the binary
33-
ENTRYPOINT ["/app/mcp-k8s-go"]
1+
FROM scratch
2+
ENTRYPOINT ["/mcp-k8s-go"]
3+
COPY mcp-k8s-go /

tools/release.sh

-2
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,3 @@ git commit -m "chore: update npm packages versions to $new_version" && git push
2525

2626
git tag -a "v$new_version" -m "release v$new_version"
2727
git push origin "v$new_version"
28-
29-
goreleaser release --clean

0 commit comments

Comments
 (0)