Skip to content

Commit 261cb06

Browse files
authored
Create ibm-cloud-code-engine.yml
Deploy to IBM Code Engine
1 parent a0807d8 commit 261cb06

File tree

1 file changed

+154
-0
lines changed

1 file changed

+154
-0
lines changed
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
# ===============================================================
2+
# ☁️ MCP Gateway ▸ Build, Cache & Deploy to IBM Code Engine
3+
# ===============================================================
4+
#
5+
# This workflow:
6+
# • Restores / updates a local BuildKit layer cache ❄️
7+
# • Builds the Docker image (Containerfile.lite) 🏗️
8+
# • Pushes it to IBM Container Registry (ICR) 📤
9+
# • Creates or updates a Code Engine app 🚀
10+
#
11+
# All sensitive values are read from GitHub **repository secrets**
12+
# ┌────────────────────────────┬────────────────────────────────┐
13+
# │ Secret name │ Example value │
14+
# ├────────────────────────────┼────────────────────────────────┤
15+
# │ IBM_CLOUD_API_KEY │ abcdef-123456… │
16+
# │ IBM_CLOUD_REGION │ us-south │
17+
# │ ICR_NAMESPACE │ myspace │
18+
# │ REGISTRY_HOSTNAME │ us.icr.io │
19+
# │ APP_NAME │ mcpgateway │
20+
# │ CODE_ENGINE_PROJECT │ my-ce-project │
21+
# │ CODE_ENGINE_REGISTRY_SECRET│ my-registry-secret │
22+
# │ CODE_ENGINE_PORT │ "4444" │
23+
# └────────────────────────────┴────────────────────────────────┘
24+
# ---------------------------------------------------------------
25+
26+
name: Deploy to IBM Code Engine
27+
28+
on:
29+
push:
30+
branches: [ "main" ]
31+
32+
permissions:
33+
contents: read # least-privilege
34+
35+
env:
36+
# Build metadata
37+
GITHUB_SHA: ${{ github.sha }}
38+
CACHE_DIR: /tmp/.buildx-cache # BuildKit layer cache dir
39+
40+
# IBM Cloud auth / region
41+
IBM_CLOUD_API_KEY: ${{ secrets.IBM_CLOUD_API_KEY }}
42+
IBM_CLOUD_REGION: ${{ secrets.IBM_CLOUD_REGION }}
43+
44+
# Registry coords
45+
REGISTRY_HOSTNAME: ${{ secrets.REGISTRY_HOSTNAME }}
46+
ICR_NAMESPACE: ${{ secrets.ICR_NAMESPACE }}
47+
48+
# Image / app naming
49+
IMAGE_NAME: ${{ secrets.APP_NAME }}
50+
IMAGE_TAG: ${{ github.sha }}
51+
52+
# Code Engine deployment
53+
CODE_ENGINE_APP_NAME: ${{ secrets.APP_NAME }}
54+
CODE_ENGINE_PROJECT: ${{ secrets.CODE_ENGINE_PROJECT }}
55+
CODE_ENGINE_REGISTRY_SECRET: ${{ secrets.CODE_ENGINE_REGISTRY_SECRET }}
56+
PORT: ${{ secrets.CODE_ENGINE_PORT }}
57+
58+
jobs:
59+
build-push-deploy:
60+
name: 🚀 Build, Cache, Push & Deploy
61+
runs-on: ubuntu-latest
62+
environment: production
63+
64+
steps:
65+
# -----------------------------------------------------------
66+
# 0️⃣ Checkout repository
67+
# -----------------------------------------------------------
68+
- name: ⬇️ Checkout source
69+
uses: actions/checkout@v4
70+
71+
# -----------------------------------------------------------
72+
# 1️⃣ Set up Docker Buildx
73+
# -----------------------------------------------------------
74+
- name: 🛠️ Set up Docker Buildx
75+
uses: docker/setup-buildx-action@v3
76+
77+
# -----------------------------------------------------------
78+
# 2️⃣ Restore BuildKit layer cache
79+
# -----------------------------------------------------------
80+
- name: 🔄 Restore BuildKit cache
81+
uses: actions/cache@v4
82+
with:
83+
path: ${{ env.CACHE_DIR }}
84+
key: ${{ runner.os }}-buildx-${{ github.sha }}
85+
restore-keys: ${{ runner.os }}-buildx-
86+
87+
# -----------------------------------------------------------
88+
# 3️⃣ Install IBM Cloud CLI + plugins
89+
# -----------------------------------------------------------
90+
- name: 🧰 Install IBM Cloud CLI
91+
run: |
92+
curl -fsSL https://clis.cloud.ibm.com/install/linux | sh
93+
ibmcloud config --check-version=false
94+
ibmcloud plugin install -f container-registry
95+
ibmcloud plugin install -f code-engine
96+
ibmcloud --version
97+
98+
# -----------------------------------------------------------
99+
# 4️⃣ Authenticate to IBM Cloud & select CE project
100+
# -----------------------------------------------------------
101+
- name: 🔐 IBM Cloud login
102+
run: |
103+
ibmcloud login --apikey "$IBM_CLOUD_API_KEY" -r "$IBM_CLOUD_REGION" -g default
104+
ibmcloud cr region-set "$IBM_CLOUD_REGION"
105+
ibmcloud cr login
106+
ibmcloud ce project select --name "$CODE_ENGINE_PROJECT"
107+
108+
# -----------------------------------------------------------
109+
# 5️⃣ Build & tag image (uses cache, updates cache dir)
110+
# -----------------------------------------------------------
111+
- name: 🏗️ Build Docker image (with cache)
112+
run: |
113+
docker buildx build \
114+
--file Containerfile.lite \
115+
--tag "$REGISTRY_HOSTNAME/$ICR_NAMESPACE/$IMAGE_NAME:$IMAGE_TAG" \
116+
--cache-from type=local,src=${{ env.CACHE_DIR }} \
117+
--cache-to type=local,dest=${{ env.CACHE_DIR }},mode=max \
118+
--load \
119+
.
120+
121+
# -----------------------------------------------------------
122+
# 6️⃣ Push image to IBM Container Registry
123+
# -----------------------------------------------------------
124+
- name: 📤 Push image to ICR
125+
run: |
126+
docker push "$REGISTRY_HOSTNAME/$ICR_NAMESPACE/$IMAGE_NAME:$IMAGE_TAG"
127+
128+
# -----------------------------------------------------------
129+
# 7️⃣ Deploy (create or update) Code Engine application
130+
# -----------------------------------------------------------
131+
- name: 🚀 Deploy to Code Engine
132+
run: |
133+
if ibmcloud ce application get --name "$CODE_ENGINE_APP_NAME" > /dev/null 2>&1; then
134+
echo "🔁 Updating existing application…"
135+
ibmcloud ce application update \
136+
--name "$CODE_ENGINE_APP_NAME" \
137+
--image "$REGISTRY_HOSTNAME/$ICR_NAMESPACE/$IMAGE_NAME:$IMAGE_TAG" \
138+
--registry-secret "$CODE_ENGINE_REGISTRY_SECRET" \
139+
--cpu 1 --memory 2G
140+
else
141+
echo "🆕 Creating new application…"
142+
ibmcloud ce application create \
143+
--name "$CODE_ENGINE_APP_NAME" \
144+
--image "$REGISTRY_HOSTNAME/$ICR_NAMESPACE/$IMAGE_NAME:$IMAGE_TAG" \
145+
--registry-secret "$CODE_ENGINE_REGISTRY_SECRET" \
146+
--port "$PORT" \
147+
--cpu 1 --memory 2G
148+
fi
149+
150+
# -----------------------------------------------------------
151+
# 8️⃣ Show deployment status
152+
# -----------------------------------------------------------
153+
- name: 📈 Display deployment status
154+
run: ibmcloud ce application get --name "$CODE_ENGINE_APP_NAME"

0 commit comments

Comments
 (0)