Skip to content

Commit cf6243e

Browse files
authored
Merge pull request #24 from aojea/service_discovery
deploy public mesh
2 parents 531a99f + 8df75f8 commit cf6243e

5 files changed

Lines changed: 334 additions & 105 deletions

File tree

‎.github/k8s/sam-hub-template.yaml‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: sam-hub-${ENV_NAME}
5+
namespace: ${NAMESPACE}
6+
spec:
7+
type: LoadBalancer
8+
loadBalancerClass: "networking.gke.io/l4-regional-external"
9+
loadBalancerIP: ${LOAD_BALANCER_IP}
10+
ports:
11+
- port: 4001
12+
targetPort: 4001
13+
protocol: TCP
14+
name: libp2p-tcp
15+
- port: 4001
16+
targetPort: 4001
17+
protocol: UDP
18+
name: libp2p-udp
19+
selector:
20+
app: sam-hub-${ENV_NAME}
21+
---
22+
apiVersion: apps/v1
23+
kind: Deployment
24+
metadata:
25+
name: sam-hub-${ENV_NAME}
26+
namespace: ${NAMESPACE}
27+
spec:
28+
replicas: 1
29+
selector:
30+
matchLabels:
31+
app: sam-hub-${ENV_NAME}
32+
template:
33+
metadata:
34+
labels:
35+
app: sam-hub-${ENV_NAME}
36+
spec:
37+
containers:
38+
- name: sam-hub
39+
image: your-registry/sam-hub:${IMAGE_TAG}
40+
ports:
41+
- containerPort: 4001
42+
protocol: TCP
43+
- containerPort: 4001
44+
protocol: UDP
45+
args:
46+
- "--listen=/ip4/0.0.0.0/tcp/4001,/ip4/0.0.0.0/udp/4001/quic-v1"
47+
- "--external-multiaddr=${EXTERNAL_MULTIADDR}"
48+
49+
# Critical for multi-tenant clusters: prevent testnet from starving prod
50+
resources:
51+
requests:
52+
cpu: 100m
53+
memory: 128Mi
54+
limits:
55+
cpu: 500m
56+
memory: 512Mi

‎.github/k8s/sam-node-template.yaml‎

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: sam-canary-config-${ENV_NAME}
5+
namespace: sam-canary-${ENV_NAME}
6+
data:
7+
sam-node.yaml: |
8+
version: "v1alpha1"
9+
attenuation:
10+
policies: []
11+
checks: []
12+
rules: []
13+
services:
14+
- type: mcp
15+
name: dummy-http
16+
description: "Canary HTTP tool (k8s agnhost)"
17+
# agnhost netexec responds with request info on the root path
18+
target_url: "http://localhost:9090/"
19+
- type: mcp
20+
name: dummy-stdio
21+
description: "Canary Stdio tool via injected busybox"
22+
# We call the injected busybox binary explicitly
23+
command: ["/shared/busybox", "sh", "-c", "while read line; do echo '{\"jsonrpc\": \"2.0\", \"id\": 1, \"result\": {\"status\": \"canary-alive\"}}'; done"]
24+
---
25+
apiVersion: apps/v1
26+
kind: Deployment
27+
metadata:
28+
name: sam-canary-${ENV_NAME}
29+
namespace: sam-canary-${ENV_NAME}
30+
spec:
31+
replicas: 2
32+
selector:
33+
matchLabels:
34+
app: sam-canary-${ENV_NAME}
35+
template:
36+
metadata:
37+
labels:
38+
app: sam-canary-${ENV_NAME}
39+
spec:
40+
# 1. The Init Container: Copies busybox to the shared volume
41+
initContainers:
42+
- name: inject-busybox
43+
image: busybox:1.36.1
44+
command: ["cp", "/bin/busybox", "/shared/busybox"]
45+
volumeMounts:
46+
- name: shared-bin
47+
mountPath: /shared
48+
49+
containers:
50+
# 2. The SAM Agent (Distroless)
51+
- name: sam-node
52+
image: ghcr.io/google/sam-node:${IMAGE_TAG}
53+
args:
54+
- "run"
55+
- "--config=/etc/sam/sam-node.yaml"
56+
- "--hub=/dns4/sam-hub-${ENV_NAME}.sam-${ENV_NAME}.svc.cluster.local/udp/4001/quic-v1"
57+
ports:
58+
- containerPort: 8080
59+
resources:
60+
requests:
61+
cpu: 50m
62+
memory: 64Mi
63+
limits:
64+
cpu: 200m
65+
memory: 256Mi
66+
volumeMounts:
67+
- name: config-volume
68+
mountPath: /etc/sam
69+
- name: shared-bin
70+
mountPath: /shared
71+
72+
# 3. The Dummy MCP Backend Sidecar
73+
- name: mock-mcp-server
74+
image: registry.k8s.io/e2e-test-images/agnhost:2.39
75+
# agnhost's netexec subcommand spins up a robust test HTTP server
76+
args: ["netexec", "--http-port=9090"]
77+
ports:
78+
- containerPort: 9090
79+
80+
volumes:
81+
- name: config-volume
82+
configMap:
83+
name: sam-canary-config-${ENV_NAME}
84+
- name: shared-bin
85+
emptyDir: {}

‎.github/workflows/deploy.yaml‎

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
name: Deploy SAM Hub
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- 'v*.*.*'
9+
workflow_dispatch:
10+
11+
env:
12+
REGISTRY: ghcr.io
13+
14+
jobs:
15+
publish:
16+
name: Publish Images
17+
runs-on: ubuntu-latest
18+
permissions:
19+
packages: write
20+
contents: read
21+
timeout-minutes: 100
22+
23+
steps:
24+
- name: Check out code
25+
uses: actions/checkout@v4
26+
27+
- name: Set up QEMU
28+
uses: docker/setup-qemu-action@v3
29+
30+
- name: Set up Docker Buildx
31+
uses: docker/setup-buildx-action@v3
32+
33+
- name: Log in to the Container registry
34+
uses: docker/login-action@v3
35+
with:
36+
registry: ${{ env.REGISTRY }}
37+
username: ${{ github.actor }}
38+
password: ${{ secrets.GITHUB_TOKEN }}
39+
40+
- name: Extract metadata for Hub
41+
id: meta-hub
42+
uses: docker/metadata-action@v5
43+
with:
44+
images: ${{ env.REGISTRY }}/google/sam-hub
45+
tags: |
46+
type=ref,event=branch
47+
type=ref,event=tag
48+
type=raw,value=${{ github.sha }}
49+
type=raw,value=latest,enable={{is_default_branch}}
50+
type=raw,value=stable,enable=${{ startsWith(github.ref, 'refs/tags/v') }}
51+
52+
- name: Build and push Hub image
53+
uses: docker/build-push-action@v6
54+
with:
55+
context: .
56+
file: Dockerfile.sam-hub
57+
platforms: linux/amd64,linux/arm64
58+
push: true
59+
tags: ${{ steps.meta-hub.outputs.tags }}
60+
labels: ${{ steps.meta-hub.outputs.labels }}
61+
62+
- name: Extract metadata for Node
63+
id: meta-node
64+
uses: docker/metadata-action@v5
65+
with:
66+
images: ${{ env.REGISTRY }}/google/sam-node
67+
tags: |
68+
type=ref,event=branch
69+
type=ref,event=tag
70+
type=raw,value=${{ github.sha }}
71+
type=raw,value=latest,enable={{is_default_branch}}
72+
type=raw,value=stable,enable=${{ startsWith(github.ref, 'refs/tags/v') }}
73+
74+
- name: Build and push Node image
75+
uses: docker/build-push-action@v6
76+
with:
77+
context: .
78+
file: Dockerfile.sam-node
79+
platforms: linux/amd64,linux/arm64
80+
push: true
81+
tags: ${{ steps.meta-node.outputs.tags }}
82+
labels: ${{ steps.meta-node.outputs.labels }}
83+
84+
deploy:
85+
name: Deploy to GKE
86+
runs-on: ubuntu-latest
87+
needs: publish
88+
# Dynamically select the GitHub Environment based on the trigger
89+
environment: ${{ github.ref_type == 'tag' && 'hub' || 'bananas' }}
90+
permissions:
91+
contents: 'read'
92+
id-token: 'write'
93+
94+
steps:
95+
- name: Checkout code
96+
uses: actions/checkout@v4
97+
98+
- name: Determine Image Tag
99+
run: |
100+
if [[ "${{ github.ref_type }}" == "tag" ]]; then
101+
echo "IMAGE_TAG=${{ github.ref_name }}" >> $GITHUB_ENV
102+
else
103+
echo "IMAGE_TAG=${{ github.sha }}" >> $GITHUB_ENV
104+
fi
105+
106+
- name: Google Auth
107+
uses: google-github-actions/auth@v2
108+
with:
109+
workload_identity_provider: ${{ vars.WIF_PROVIDER_NAME }}
110+
service_account: ${{ vars.SERVICE_ACCOUNT_EMAIL }}
111+
112+
- name: Set up GKE credentials
113+
uses: google-github-actions/get-gke-credentials@v2
114+
with:
115+
cluster_name: ${{ vars.CLUSTER_NAME }}
116+
location: ${{ vars.CLUSTER_REGION }}
117+
118+
- name: Prepare Namespaces
119+
run: |
120+
export ENV_NAME="${{ vars.ENV_NAME }}"
121+
export NAMESPACE="sam-${ENV_NAME}"
122+
export CANARY_NAMESPACE="sam-canary-${ENV_NAME}"
123+
124+
kubectl create namespace ${NAMESPACE} --dry-run=client -o yaml | kubectl apply -f -
125+
kubectl create namespace ${CANARY_NAMESPACE} --dry-run=client -o yaml | kubectl apply -f -
126+
127+
- name: Deploy Hub
128+
run: |
129+
sudo apt-get install -y gettext-base
130+
131+
export ENV_NAME="${{ vars.ENV_NAME }}"
132+
export LOAD_BALANCER_IP="${{ vars.LOAD_BALANCER_IP }}"
133+
export EXTERNAL_MULTIADDR="${{ vars.EXTERNAL_MULTIADDR }}"
134+
export NAMESPACE="sam-${ENV_NAME}"
135+
export IMAGE_TAG="${{ env.IMAGE_TAG }}"
136+
137+
envsubst < .github/k8s/sam-hub-template.yaml | kubectl apply -f -
138+
139+
kubectl rollout status deployment/sam-hub-${ENV_NAME} -n ${NAMESPACE} --timeout=120s || {
140+
echo "Hub Deployment failed! Rolling back..."
141+
kubectl rollout undo deployment/sam-hub-${ENV_NAME} -n ${NAMESPACE}
142+
kubectl rollout status deployment/sam-hub-${ENV_NAME} -n ${NAMESPACE}
143+
exit 1
144+
}
145+
146+
- name: Deploy Canaries
147+
run: |
148+
export ENV_NAME="${{ vars.ENV_NAME }}"
149+
export CANARY_NAMESPACE="sam-canary-${ENV_NAME}"
150+
export IMAGE_TAG="${{ env.IMAGE_TAG }}"
151+
152+
envsubst < .github/k8s/sam-canary-template.yaml | kubectl apply -f -
153+
154+
kubectl rollout status deployment/sam-canary-${ENV_NAME} -n ${CANARY_NAMESPACE} --timeout=120s || {
155+
echo "Canary Deployment failed! Rolling back..."
156+
kubectl rollout undo deployment/sam-canary-${ENV_NAME} -n ${CANARY_NAMESPACE}
157+
kubectl rollout status deployment/sam-canary-${ENV_NAME} -n ${CANARY_NAMESPACE}
158+
exit 1
159+
}

‎.github/workflows/release.yaml‎

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

0 commit comments

Comments
 (0)