Skip to content

Commit 24207fa

Browse files
authored
Merge pull request #112 from Azure/feature/issue-111-multiarch-docker
chore: add support for multiarch container image
2 parents c09d30b + 99ed8c6 commit 24207fa

File tree

4 files changed

+168
-28
lines changed

4 files changed

+168
-28
lines changed

.github/workflows/ci.yml

Lines changed: 65 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ jobs:
1717
uses: actions/[email protected]
1818
with:
1919
fetch-depth: 0
20-
20+
2121
- name: Set up Go
2222
uses: actions/setup-go@v5
2323
with:
2424
go-version: '1.24'
2525
check-latest: true
2626
cache: true
27-
27+
2828
- name: Check formatting
2929
run: |
3030
if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then
@@ -33,7 +33,7 @@ jobs:
3333
echo "Please run 'go fmt ./...' to fix formatting issues."
3434
exit 1
3535
fi
36-
36+
3737
- name: Run go vet
3838
run: go vet ./...
3939

@@ -46,20 +46,20 @@ jobs:
4646
uses: actions/[email protected]
4747
with:
4848
fetch-depth: 0
49-
49+
5050
- name: Set up Go
5151
uses: actions/setup-go@v5
5252
with:
5353
go-version: '1.24'
5454
check-latest: true
5555
cache: true
56-
56+
5757
- name: Lint
5858
uses: golangci/golangci-lint-action@v8
5959
with:
6060
version: latest
6161
args: --timeout=5m
62-
62+
6363
test:
6464
name: Test
6565
runs-on: ubuntu-latest
@@ -69,27 +69,27 @@ jobs:
6969
uses: actions/[email protected]
7070
with:
7171
fetch-depth: 0
72-
72+
7373
- name: Set up Go
7474
uses: actions/setup-go@v5
7575
with:
7676
go-version: '1.24'
7777
check-latest: true
7878
cache: true
79-
79+
8080
- name: Install dependencies
8181
run: go mod download
82-
82+
8383
- name: Run tests with coverage
8484
run: go test -race -coverprofile=coverage.txt -covermode=atomic ./...
85-
85+
8686
- name: Upload coverage to Codecov
8787
uses: codecov/codecov-action@v5
8888
with:
8989
file: ./coverage.txt
9090
fail_ci_if_error: false
9191
continue-on-error: true
92-
92+
9393
- name: Archive code coverage results
9494
uses: actions/upload-artifact@v4
9595
with:
@@ -106,25 +106,67 @@ jobs:
106106
uses: actions/[email protected]
107107
with:
108108
fetch-depth: 0
109-
109+
110110
- name: Set up Go
111111
uses: actions/setup-go@v5
112112
with:
113113
go-version: '1.24'
114114
check-latest: true
115115
cache: true
116-
117-
- name: Build binary
116+
117+
- name: Build Linux binary
118118
run: |
119119
go build -o aks-mcp ./cmd/aks-mcp
120-
121-
- name: Build Docker image
122-
run: docker build -t aks-mcp:test .
123-
124-
- name: Check Docker image
120+
121+
- name: Build Windows binary
122+
run: |
123+
GOOS=windows GOARCH=amd64 go build -trimpath -tags withoutebpf -o aks-mcp.exe ./cmd/aks-mcp
124+
125+
- name: Set up Docker Buildx
126+
uses: docker/setup-buildx-action@v3
127+
128+
- name: Build Linux Docker image
129+
uses: docker/build-push-action@v6
130+
with:
131+
push: false
132+
platforms: linux/amd64
133+
tags: aks-mcp:linux-test
134+
file: ./Dockerfile
135+
load: true
136+
137+
- name: Validate Linux Docker image
125138
run: |
126-
docker images aks-mcp:test
127-
docker run --rm aks-mcp:test --help || true
139+
docker images aks-mcp:linux-test
140+
docker run --rm aks-mcp:linux-test --help || true
141+
142+
build-windows:
143+
name: Build Windows
144+
runs-on: windows-latest
145+
needs: [lint, test]
146+
steps:
147+
- name: Checkout code
148+
uses: actions/[email protected]
149+
with:
150+
fetch-depth: 0
151+
152+
- name: Set up Go
153+
uses: actions/setup-go@v5
154+
with:
155+
go-version: '1.24'
156+
check-latest: true
157+
cache: true
158+
159+
- name: Build Windows binary
160+
run: |
161+
go build -trimpath -tags withoutebpf -o aks-mcp.exe ./cmd/aks-mcp
162+
163+
- name: Build Windows Docker image
164+
run: docker build --platform windows/amd64 -f Dockerfile.windows -t aks-mcp:windows-test .
165+
166+
- name: Validate Windows Docker image
167+
run: |
168+
docker images aks-mcp:windows-test
169+
docker run --rm aks-mcp:windows-test --help || true
128170
129171
security:
130172
name: Security Scan
@@ -134,8 +176,8 @@ jobs:
134176
uses: actions/[email protected]
135177
with:
136178
fetch-depth: 0
137-
179+
138180
- name: Run Gosec Security Scanner
139181
uses: securego/gosec@master
140182
with:
141-
args: ./...
183+
args: ./...

.github/workflows/go-ossf-slsa3-publish.yml

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ jobs:
7575
needs: args
7676
outputs:
7777
image: ${{ steps.image.outputs.image }}
78-
digest: ${{ steps.build.outputs.digest }}
78+
digest: ${{ steps.image.outputs.digest }}
7979
runs-on: ubuntu-latest
8080
steps:
8181
- name: Checkout the repository
@@ -97,25 +97,67 @@ jobs:
9797
with:
9898
images: ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}
9999

100-
- name: Build and push Docker image
100+
- name: Build and push Linux Docker images
101101
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
102-
id: build
102+
id: build-linux
103103
with:
104104
push: true
105+
platforms: linux/amd64,linux/arm64
105106
tags: ${{ steps.meta.outputs.tags }}
106107
labels: ${{ steps.meta.outputs.labels }}
108+
file: ./Dockerfile
107109
build-args: |
108110
VERSION=${{ needs.args.outputs.version }}
109111
GIT_COMMIT=${{ needs.args.outputs.commit }}
110112
BUILD_DATE=${{ needs.args.outputs.commit-date }}
111113
GIT_TREE_STATE=${{ needs.args.outputs.tree-state }}
114+
112115
- name: Output image
113116
id: image
114117
run: |
115118
# NOTE: Set the image as an output because the `env` context is not
116119
# available to the inputs of a reusable workflow call.
117120
image_name=$(echo "${IMAGE_REGISTRY}/${IMAGE_NAME}"| tr '[:upper:]' '[:lower:]')
118121
echo "image=$image_name" >> "$GITHUB_OUTPUT"
122+
# Use the Linux build digest for provenance (primary platform)
123+
echo "digest=${{ steps.build-linux.outputs.digest }}" >> "$GITHUB_OUTPUT"
124+
125+
build-windows-image:
126+
permissions:
127+
contents: read
128+
packages: write
129+
needs: args
130+
runs-on: windows-latest
131+
steps:
132+
- name: Checkout the repository
133+
uses: actions/checkout@85e6279cec87321a52edac9c87bce653a07cf6c2 # v2.3.4
134+
135+
- name: Authenticate Docker
136+
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772 # v3.4.0
137+
with:
138+
registry: ${{ env.IMAGE_REGISTRY }}
139+
username: ${{ github.actor }}
140+
password: ${{ secrets.GITHUB_TOKEN }}
141+
142+
- name: Extract metadata (tags, labels) for Docker
143+
id: meta
144+
uses: docker/metadata-action@902fa8ec7d6ecbf8d84d538b9b233a880e428804 # v5.7.0
145+
with:
146+
images: ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAME }}
147+
148+
- name: Build and push Windows Docker images
149+
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
150+
with:
151+
push: true
152+
platforms: windows/amd64
153+
tags: ${{ steps.meta.outputs.tags }}
154+
labels: ${{ steps.meta.outputs.labels }}
155+
file: ./Dockerfile.windows
156+
build-args: |
157+
VERSION=${{ needs.args.outputs.version }}
158+
GIT_COMMIT=${{ needs.args.outputs.commit }}
159+
BUILD_DATE=${{ needs.args.outputs.commit-date }}
160+
GIT_TREE_STATE=${{ needs.args.outputs.tree-state }}
119161
# This step calls the container workflow to generate provenance and push it to
120162
# the container registry.
121163
provenance:

Dockerfile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
# Linux Dockerfile for aks-mcp
12
# Build stage
23
FROM golang:1.24-alpine AS builder
4+
ARG TARGETOS=linux
5+
ARG TARGETARCH
36
ARG VERSION
47
ARG GIT_COMMIT
58
ARG BUILD_DATE
69
ARG GIT_TREE_STATE
10+
711
# Set working directory
812
WORKDIR /app
913

@@ -16,8 +20,8 @@ RUN go mod download
1620
# Copy source code
1721
COPY . .
1822

19-
# Build the application
20-
RUN CGO_ENABLED=0 GOOS=linux go build -o aks-mcp ./cmd/aks-mcp
23+
# Build the application for target platform
24+
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o aks-mcp ./cmd/aks-mcp
2125

2226
# Runtime stage
2327
FROM alpine:3.22

Dockerfile.windows

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Windows Dockerfile for aks-mcp
2+
# Build stage
3+
FROM golang:1.24-windowsservercore-ltsc2022 AS builder
4+
ARG TARGETOS=windows
5+
ARG TARGETARCH=amd64
6+
ARG VERSION
7+
ARG GIT_COMMIT
8+
ARG BUILD_DATE
9+
ARG GIT_TREE_STATE
10+
11+
# Set working directory
12+
WORKDIR "C:\\app"
13+
14+
# Copy go mod and sum files
15+
COPY go.mod go.sum ./
16+
17+
# Download dependencies
18+
RUN go mod download
19+
20+
# Copy source code
21+
COPY . .
22+
23+
# Build the application for Windows
24+
RUN go build -trimpath -tags withoutebpf -o aks-mcp.exe ./cmd/aks-mcp
25+
26+
# Runtime stage
27+
FROM mcr.microsoft.com/windows/servercore:ltsc2022
28+
29+
# Set working directory
30+
WORKDIR "C:\\app"
31+
32+
# Use cmd shell
33+
SHELL ["cmd.exe", "/S", "/C"]
34+
35+
# Download and install Chocolatey using cmd and PowerShell inline
36+
RUN @"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "[System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
37+
38+
# Install Azure CLI using Chocolatey
39+
RUN choco install azure-cli -y
40+
41+
# Copy binary from builder
42+
COPY --from=builder "C:\\app\\aks-mcp.exe" "C:\\app\\aks-mcp.exe"
43+
44+
# Expose the default port for sse/streamable-http transports
45+
EXPOSE 8000
46+
47+
# Set environment variables
48+
ENV PATH="C:\\app;${PATH}"
49+
50+
# Command to run
51+
ENTRYPOINT ["C:\\app\\aks-mcp.exe"]
52+
CMD ["--transport", "streamable-http", "--host", "0.0.0.0"]

0 commit comments

Comments
 (0)