Skip to content

Commit e0d621e

Browse files
authored
refactor!: re-implement oras-mcp in golang (#6)
Signed-off-by: Shiwei Zhang <[email protected]>
1 parent 22510a0 commit e0d621e

32 files changed

Lines changed: 1186 additions & 1950 deletions

.github/workflows/build.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright The ORAS Authors.
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
14+
name: build
15+
16+
on:
17+
push:
18+
branches:
19+
- main
20+
- release-*
21+
pull_request:
22+
branches:
23+
- main
24+
- release-*
25+
jobs:
26+
build:
27+
runs-on: ubuntu-latest
28+
strategy:
29+
matrix:
30+
go-version: ['1.25']
31+
fail-fast: true
32+
steps:
33+
- name: Checkout
34+
uses: actions/checkout@v5
35+
- name: Setup Go ${{ matrix.go-version }}
36+
uses: actions/setup-go@v6
37+
with:
38+
go-version: ${{ matrix.go-version }}
39+
check-latest: true
40+
- name: Build CLI
41+
run: make build-linux-amd64
42+
- name: Run Unit Tests
43+
run: make test
44+
- name: Check Version
45+
run: bin/linux/amd64/oras-mcp version

.github/workflows/release-ghcr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
packages: write
2727
steps:
2828
- name: Checkout
29-
uses: actions/checkout@v4
29+
uses: actions/checkout@v5
3030
- name: prepare
3131
id: prepare
3232
run: |

.gitignore

Lines changed: 46 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -1,136 +1,46 @@
1-
# Logs
2-
logs
3-
*.log
4-
npm-debug.log*
5-
yarn-debug.log*
6-
yarn-error.log*
7-
lerna-debug.log*
8-
.pnpm-debug.log*
9-
10-
# Diagnostic reports (https://nodejs.org/api/report.html)
11-
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
12-
13-
# Runtime data
14-
pids
15-
*.pid
16-
*.seed
17-
*.pid.lock
18-
19-
# Directory for instrumented libs generated by jscoverage/JSCover
20-
lib-cov
21-
22-
# Coverage directory used by tools like istanbul
23-
coverage
24-
*.lcov
25-
26-
# nyc test coverage
27-
.nyc_output
28-
29-
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
30-
.grunt
31-
32-
# Bower dependency directory (https://bower.io/)
33-
bower_components
34-
35-
# node-waf configuration
36-
.lock-wscript
37-
38-
# Compiled binary addons (https://nodejs.org/api/addons.html)
39-
build/Release
40-
41-
# Dependency directories
42-
node_modules/
43-
jspm_packages/
44-
45-
# Snowpack dependency directory (https://snowpack.dev/)
46-
web_modules/
47-
48-
# TypeScript cache
49-
*.tsbuildinfo
50-
51-
# Optional npm cache directory
52-
.npm
53-
54-
# Optional eslint cache
55-
.eslintcache
56-
57-
# Optional stylelint cache
58-
.stylelintcache
59-
60-
# Microbundle cache
61-
.rpt2_cache/
62-
.rts2_cache_cjs/
63-
.rts2_cache_es/
64-
.rts2_cache_umd/
65-
66-
# Optional REPL history
67-
.node_repl_history
68-
69-
# Output of 'npm pack'
70-
*.tgz
71-
72-
# Yarn Integrity file
73-
.yarn-integrity
74-
75-
# dotenv environment variable files
76-
.env
77-
.env.development.local
78-
.env.test.local
79-
.env.production.local
80-
.env.local
81-
82-
# parcel-bundler cache (https://parceljs.org/)
83-
.cache
84-
.parcel-cache
85-
86-
# Next.js build output
87-
.next
88-
out
89-
90-
# Nuxt.js build / generate output
91-
.nuxt
92-
dist
93-
94-
# Gatsby files
95-
.cache/
96-
# Comment in the public line in if your project uses Gatsby and not Next.js
97-
# https://nextjs.org/blog/next-9-1#public-directory-support
98-
# public
99-
100-
# vuepress build output
101-
.vuepress/dist
102-
103-
# vuepress v2.x temp and cache directory
104-
.temp
105-
.cache
106-
107-
# vitepress build output
108-
**/.vitepress/dist
109-
110-
# vitepress cache directory
111-
**/.vitepress/cache
112-
113-
# Docusaurus cache and generated files
114-
.docusaurus
115-
116-
# Serverless directories
117-
.serverless/
118-
119-
# FuseBox cache
120-
.fusebox/
121-
122-
# DynamoDB Local files
123-
.dynamodb/
124-
125-
# TernJS port file
126-
.tern-port
127-
128-
# Stores VSCode versions used for testing VSCode extensions
129-
.vscode-test
130-
131-
# yarn v2
132-
.yarn/cache
133-
.yarn/unplugged
134-
.yarn/build-state.yml
135-
.yarn/install-state.gz
136-
.pnp.*
1+
# Copyright The ORAS Authors.
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
14+
# Binaries for programs and plugins
15+
*.exe
16+
*.exe~
17+
*.dll
18+
*.so
19+
*.dylib
20+
21+
# Test binary, build with `go test -c`
22+
*.test
23+
24+
# Output of the go coverage tool, specifically when used with LiteIDE
25+
*.out
26+
coverage.html
27+
28+
# VS Code
29+
debug
30+
31+
# Jetbrains
32+
.idea
33+
34+
# vi
35+
*.sw*
36+
37+
# Custom
38+
coverage.txt
39+
**/covcounters.*
40+
**/covmeta.*
41+
bin/
42+
dist/
43+
*.tar.gz
44+
vendor/
45+
_dist/
46+
.DS_Store

.vscode/launch.json

Lines changed: 0 additions & 26 deletions
This file was deleted.

.vscode/mcp.json

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
1+
// Copyright The ORAS Authors.
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
113
{
214
"servers": {
315
"oras-mcp-server-stdio": {
416
"type": "stdio",
5-
"command": "node",
6-
"args": ["${workspaceFolder}/dist/index.js"]
17+
"command": "go",
18+
"args": ["run", "${workspaceFolder}/cmd/oras-mcp", "serve"]
719
}
8-
// "oras-mcp-server-streamable-http": {
9-
// "type": "http",
10-
// "url": "http://localhost:3088/mcp"
11-
// },
1220
}
1321
}

.vscode/tasks.json

Lines changed: 0 additions & 16 deletions
This file was deleted.

Dockerfile

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
1-
FROM --platform=$BUILDPLATFORM docker.io/library/node:22-alpine AS builder
2-
ADD . /app
3-
WORKDIR /app
4-
RUN npm install --ignore-scripts
5-
RUN npm run build
1+
# Copyright The ORAS Authors.
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
#
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
#
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
613

7-
# remove unnecessary files in order to reduce the number of layers
8-
FROM --platform=$BUILDPLATFORM docker.io/library/node:22-alpine AS packer
9-
COPY --from=builder /app/dist /app/dist
10-
COPY --from=builder /app/package*.json /app/
14+
FROM --platform=$BUILDPLATFORM docker.io/library/golang:1.25.1-alpine AS builder
15+
ARG TARGETPLATFORM
16+
RUN apk add git make
17+
ENV CLI_PKG=/oras-mcp
18+
ADD . ${CLI_PKG}
19+
WORKDIR ${CLI_PKG}
20+
RUN make "build-$(echo $TARGETPLATFORM | tr / -)"
21+
RUN mv ${CLI_PKG}/bin/${TARGETPLATFORM}/oras-mcp /go/bin/oras-mcp
1122

12-
FROM --platform=$BUILDPLATFORM ghcr.io/oras-project/oras:v1.3.0-beta.2 AS oras
23+
FROM --platform=$BUILDPLATFORM ghcr.io/oras-project/oras:v1.3.0 AS oras
1324

14-
FROM --platform=$BUILDPLATFORM docker.io/library/node:22-alpine
25+
FROM docker.io/library/alpine:3.22.1
1526
RUN apk --update add ca-certificates
1627
COPY --from=oras /bin/oras /bin/oras
17-
COPY --from=packer /app /oras-mcp-server
18-
WORKDIR /oras-mcp-server
19-
RUN npm install --production --ignore-scripts
20-
21-
ENTRYPOINT ["node", "dist/index.js"]
28+
COPY --from=builder /go/bin/oras-mcp /bin/oras-mcp
29+
RUN mkdir /workspace
30+
WORKDIR /workspace
31+
ENTRYPOINT ["/bin/oras-mcp"]

0 commit comments

Comments
 (0)