forked from IBM/mcp-context-forge
-
Notifications
You must be signed in to change notification settings - Fork 0
178 lines (160 loc) · 8.31 KB
/
ibm-cloud-code-engine.yml
File metadata and controls
178 lines (160 loc) · 8.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# ===============================================================
# ☁️ MCP Gateway ▸ Build, Cache & Deploy to IBM Code Engine
# ===============================================================
#
# This workflow:
# - Restores / updates a local **BuildKit layer cache** ❄️
# - Builds the Docker image from **Containerfile.lite** 🏗️
# - Pushes the image to **IBM Container Registry (ICR)** 📤
# - Creates / updates an **IBM Cloud Code Engine** app 🚀
#
# ---------------------------------------------------------------
# Required repository **secret**
# ---------------------------------------------------------------
# ┌────────────────────┬──────────────────────────────────────┐
# │ Secret name │ Example value │
# ├────────────────────┼──────────────────────────────────────┤
# │ IBM_CLOUD_API_KEY │ abcdef-1234567890abcdef-1234567890 │
# └────────────────────┴──────────────────────────────────────┘
#
# ---------------------------------------------------------------
# Required repository **variables**
# ---------------------------------------------------------------
# ┌────────────────────────────┬──────────────────────────────┐
# │ Variable name │ Example value │
# ├────────────────────────────┼──────────────────────────────┤
# │ IBM_CLOUD_REGION │ us-south │
# │ REGISTRY_HOSTNAME │ us.icr.io │
# │ ICR_NAMESPACE │ myspace │
# │ APP_NAME │ mcpgateway │
# │ CODE_ENGINE_PROJECT │ my-ce-project │
# │ CODE_ENGINE_REGISTRY_SECRET│ my-registry-secret │
# │ CODE_ENGINE_PORT │ "4444" │
# └────────────────────────────┴──────────────────────────────┘
# * Note: CODE_ENGINE_REGISTRY_SECRET is the name of the secret,
# not the secret value.
# Triggers:
# - Every push to `main`
# - Expects a secret called `mcpgateway-dev` in Code Engine. Ex:
# ibmcloud ce secret create \
# --name mcpgateway-dev \
# --from-env-file .env
# ---------------------------------------------------------------
name: Deploy to IBM Code Engine
on:
push:
branches: ["main"]
# -----------------------------------------------------------------
# Minimal permissions (Principle of Least Privilege)
# -----------------------------------------------------------------
permissions:
contents: read
# -----------------------------------------------------------------
# Global environment (secrets & variables)
# -----------------------------------------------------------------
env:
# Build metadata
GITHUB_SHA: ${{ github.sha }}
CACHE_DIR: /tmp/.buildx-cache # BuildKit layer cache dir
# IBM Cloud region (variable)
IBM_CLOUD_REGION: ${{ vars.IBM_CLOUD_REGION }}
# Registry coordinates (variables)
REGISTRY_HOSTNAME: ${{ vars.REGISTRY_HOSTNAME }}
ICR_NAMESPACE: ${{ vars.ICR_NAMESPACE }}
# Image / app naming (variables)
IMAGE_NAME: ${{ vars.APP_NAME }}
IMAGE_TAG: ${{ github.sha }}
# Code Engine deployment (variables)
CODE_ENGINE_APP_NAME: ${{ vars.APP_NAME }}
CODE_ENGINE_PROJECT: ${{ vars.CODE_ENGINE_PROJECT }}
CODE_ENGINE_REGISTRY_SECRET: ${{ vars.CODE_ENGINE_REGISTRY_SECRET }}
PORT: ${{ vars.CODE_ENGINE_PORT }}
jobs:
build-push-deploy:
name: 🚀 Build, Cache, Push & Deploy
runs-on: ubuntu-latest
environment: production
steps:
# -----------------------------------------------------------
# 0️⃣ Checkout repository
# -----------------------------------------------------------
- name: ⬇️ Checkout source
uses: actions/checkout@v5
# -----------------------------------------------------------
# 1️⃣ Set up Docker Buildx
# -----------------------------------------------------------
- name: 🛠️ Set up Docker Buildx
uses: docker/setup-buildx-action@v3.11.1
# -----------------------------------------------------------
# 2️⃣ Restore BuildKit layer cache
# -----------------------------------------------------------
- name: 🔄 Restore BuildKit cache
uses: actions/cache@v4
with:
path: ${{ env.CACHE_DIR }}
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: ${{ runner.os }}-buildx-
# -----------------------------------------------------------
# 3️⃣ Install IBM Cloud CLI + plugins & login
# -----------------------------------------------------------
- name: 🧰 Install IBM Cloud CLI
uses: IBM/actions-ibmcloud-cli@v1
with:
api_key: ${{ secrets.IBM_CLOUD_API_KEY }}
region: ${{ vars.IBM_CLOUD_REGION }}
plugins: container-registry, code-engine
# -----------------------------------------------------------
# 4️⃣ Authenticate to IBM Cloud Code Engine project
# -----------------------------------------------------------
- name: 🔐 IBM Cloud Code Engine login
run: |
ibmcloud cr region-set "$IBM_CLOUD_REGION"
ibmcloud cr login
ibmcloud ce project select --name "$CODE_ENGINE_PROJECT"
# -----------------------------------------------------------
# 5️⃣ Build & tag image (cache-aware, amd64 platform)
# -----------------------------------------------------------
- name: 🏗️ Build Docker image (with cache)
run: |
docker buildx build \
--platform linux/amd64 \
--file Containerfile.lite \
--tag "$REGISTRY_HOSTNAME/$ICR_NAMESPACE/$IMAGE_NAME:$IMAGE_TAG" \
--cache-from type=local,src=${{ env.CACHE_DIR }} \
--cache-to type=local,dest=${{ env.CACHE_DIR }},mode=max \
--load \
.
# -----------------------------------------------------------
# 6️⃣ Push image to IBM Container Registry
# -----------------------------------------------------------
- name: 📤 Push image to ICR
run: |
docker push "$REGISTRY_HOSTNAME/$ICR_NAMESPACE/$IMAGE_NAME:$IMAGE_TAG"
# -----------------------------------------------------------
# 7️⃣ Deploy (create or update) Code Engine application
# -----------------------------------------------------------
- name: 🚀 Deploy to Code Engine
run: |
if ibmcloud ce application get --name "$CODE_ENGINE_APP_NAME" > /dev/null 2>&1; then
echo "🔁 Updating existing application..."
ibmcloud ce application update \
--name "$CODE_ENGINE_APP_NAME" \
--image "$REGISTRY_HOSTNAME/$ICR_NAMESPACE/$IMAGE_NAME:$IMAGE_TAG" \
--registry-secret "$CODE_ENGINE_REGISTRY_SECRET" \
--env-from-secret mcpgateway-dev \
--cpu 1 --memory 2G
else
echo "🆕 Creating new application..."
ibmcloud ce application create \
--name "$CODE_ENGINE_APP_NAME" \
--image "$REGISTRY_HOSTNAME/$ICR_NAMESPACE/$IMAGE_NAME:$IMAGE_TAG" \
--registry-secret "$CODE_ENGINE_REGISTRY_SECRET" \
--port "$PORT" \
--env-from-secret mcpgateway-dev \
--cpu 1 --memory 2G
fi
# -----------------------------------------------------------
# 8️⃣ Show deployment status
# -----------------------------------------------------------
- name: 📈 Display deployment status
run: ibmcloud ce application get --name "$CODE_ENGINE_APP_NAME"