Skip to content

Commit 5db2179

Browse files
authored
Merge pull request #34 from IBM/update-gcr-docs
Update GCR docs
2 parents 80ebc86 + e7b868a commit 5db2179

File tree

2 files changed

+172
-23
lines changed

2 files changed

+172
-23
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.env.gcr
12
packages-lock.json
23
packages.json
34
node_modules/

docs/docs/deployment/google-cloud-run.md

Lines changed: 171 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,26 @@ Install the Google Cloud SDK:
3535

3636
* **Debian/Ubuntu:**
3737

38+
> These steps also apply to WSL2 running Ubuntu.
39+
3840
```bash
39-
sudo apt-get install google-cloud-cli
41+
# Update package lists and install necessary utilities
42+
sudo apt-get update
43+
sudo apt-get install -y apt-transport-https ca-certificates gnupg curl
44+
45+
# Import the Google Cloud public key securely
46+
# This is for newer distributions (Debian 9+ or Ubuntu 18.04+).
47+
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo gpg --dearmor -o /usr/share/keyrings/cloud.google.gpg
48+
49+
# Add the Google Cloud SDK distribution URI as a package source
50+
# This is for newer distributions, ensuring packages are signed by the key we just added.
51+
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
52+
53+
# Update your package lists again to recognize the new repository
54+
sudo apt-get update
55+
56+
# Install the Google Cloud CLI
57+
sudo apt-get install -y google-cloud-cli
4058
```
4159

4260
* **Windows (PowerShell):**
@@ -57,11 +75,18 @@ Authenticate with your Google Cloud account:
5775
gcloud auth login
5876
```
5977

78+
Set a project ID:
79+
80+
```bash
81+
gcloud config set project PROJECT_ID
82+
```
83+
6084
### 2. Enable Required APIs
6185

6286
Enable the necessary Google Cloud APIs:
6387

6488
```bash
89+
# This might take a minute..
6590
gcloud services enable \
6691
run.googleapis.com \
6792
sqladmin.googleapis.com \
@@ -87,6 +112,35 @@ Prepare the following environment variables:
87112
| `CACHE_TYPE` | Set to `redis` for production environments |
88113
| `PORT` | Port number the application listens on (e.g., `4444`) |
89114

115+
Consider creating a `.env.gcr` file where you will record the various settings used during deployment.
116+
117+
```bash
118+
# ─── Google Cloud project ───────────────────────────────────
119+
PROJECT_ID=
120+
REGION=us-central1
121+
SERVICE_NAME=mcpgateway
122+
123+
# ─── Authentication ─────────────────────────────────────────
124+
JWT_SECRET_KEY=
125+
BASIC_AUTH_USER=
126+
BASIC_AUTH_PASSWORD=
127+
AUTH_REQUIRED=true
128+
129+
# ─── Cloud SQL (PostgreSQL) ─────────────────────────────────
130+
SQL_INSTANCE=mcpgw-db
131+
SQL_REGION=us-central1
132+
DATABASE_URL=postgresql://postgres:<PASSWORD>@<SQL_IP>:5432/mcpgw
133+
134+
# ─── Memorystore (Redis) ────────────────────────────────────
135+
REDIS_INSTANCE=mcpgw-redis
136+
REDIS_REGION=us-central1
137+
REDIS_URL=redis://<REDIS_IP>:6379/0
138+
CACHE_TYPE=redis
139+
140+
# ─── Application ────────────────────────────────────────────
141+
PORT=4444
142+
```
143+
90144
---
91145

92146
## ⚙️ Setup Steps
@@ -96,8 +150,10 @@ Prepare the following environment variables:
96150
Create a PostgreSQL instance using the `db-f1-micro` tier for cost efficiency:
97151

98152
```bash
153+
# POSTGRES_16 and POSTGRES_17 default to Enterprise Plus; adding --edition=ENTERPRISE lets you pick db-f1-micro
99154
gcloud sql instances create mcpgw-db \
100155
--database-version=POSTGRES_17 \
156+
--edition=ENTERPRISE \
101157
--tier=db-f1-micro \
102158
--region=us-central1
103159
```
@@ -148,32 +204,131 @@ gcloud redis instances describe mcpgw-redis \
148204
149205
### 3. Deploy to Google Cloud Run
150206

151-
Deploy the MCP Gateway container with minimal resource allocation:
207+
Cloud Run only accepts container images that live in Artifact Registry or the older Container Registry endpoints; anything pulled from the public internet (for example ghcr.io) must first be proxied or copied into Artifact Registry.
208+
209+
210+
#### Set Your Project ID
211+
212+
Begin by setting your Google Cloud project ID as an environment variable:
213+
214+
```bash
215+
export PROJECT_ID="your-project-id"
216+
```
217+
218+
Replace `"your-project-id"` with your actual Google Cloud project ID.
219+
220+
#### Enable Required APIs
221+
222+
Ensure that the necessary Google Cloud APIs are enabled:
223+
224+
```bash
225+
gcloud services enable artifactregistry.googleapis.com
226+
```
227+
228+
#### Create a Remote Repository
229+
230+
Set up a remote repository in Artifact Registry that proxies GitHub Container Registry (GHCR):
231+
232+
```bash
233+
gcloud artifacts repositories create ghcr-remote \
234+
--project=$PROJECT_ID \
235+
--repository-format=docker \
236+
--location=us-central1 \
237+
--description="Proxy for GitHub Container Registry" \
238+
--mode=remote-repository \
239+
--remote-docker-repo=https://ghcr.io
240+
```
241+
242+
#### Retrieve Cloud SQL Instance Connection Name
243+
244+
```bash
245+
gcloud sql instances describe mcpgw-db \
246+
--format="value(connectionName)"
247+
```
248+
249+
It will output something like this:
250+
251+
```
252+
your-project-id:us-central1:mcpgw-db
253+
```
254+
255+
256+
#### Allow ingress to your database.
257+
258+
Consider only allowing the Cloud Run IP range.
259+
260+
```bash
261+
gcloud sql instances patch mcpgw-db \
262+
--authorized-networks=0.0.0.0/0
263+
```
264+
265+
#### Deploy the MCP Gateway container with minimal resource allocation:
152266

153267
```bash
154268
gcloud run deploy mcpgateway \
155-
--image=ghcr.io/ibm/mcp-context-forge:latest \
269+
--image=us-central1-docker.pkg.dev/$PROJECT_ID/ghcr-remote/ibm/mcp-context-forge:latest
156270
--region=us-central1 \
157271
--platform=managed \
158272
--allow-unauthenticated \
159273
--port=4444 \
160274
--cpu=1 \
161-
--memory=256Mi \
275+
--memory=512i \
162276
--max-instances=1 \
163277
--set-env-vars=\
164-
JWT_SECRET_KEY=your-secret,\
278+
JWT_SECRET_KEY=jwt-secret-key,\
165279
BASIC_AUTH_USER=admin,\
166280
BASIC_AUTH_PASSWORD=changeme,\
167281
AUTH_REQUIRED=true,\
168282
DATABASE_URL=postgresql://postgres:mysecretpassword@<SQL_IP>:5432/mcpgw,\
169283
REDIS_URL=redis://<REDIS_IP>:6379/0,\
170-
CACHE_TYPE=redis
284+
CACHE_TYPE=redis,\
285+
HOST=0.0.0.0,\
286+
GUNICORN_WORKERS=1
171287
```
172288

173289
> **Replace `<SQL_IP>` and `<REDIS_IP>`** with the actual IP addresses obtained from the previous steps.
290+
> Do not leave out the HOST=0.0.0.0 to ensure the container listens on all ports, or the container engine won't be able to reach the container.
291+
> Setting the number of GUNICORN_WORKERS lets you control how much memory the service consumes.
292+
293+
#### Check the logs
174294

295+
```bash
296+
gcloud run services logs read mcpgateway --region=us-central1
297+
```
175298
---
176299

300+
#### Check that the database is created:
301+
302+
You can use any PostgreSQL client, such as `psql`. You should see the list of tables when using `dt;`
303+
304+
```bash
305+
psql postgresql://postgres:mysecretpassword@<SQL_IP>:5432/mcpgw
306+
307+
mcpgw=> \dt;
308+
List of relations
309+
Schema | Name | Type | Owner
310+
--------+------------------------------+-------+----------
311+
public | gateways | table | postgres
312+
public | mcp_messages | table | postgres
313+
public | mcp_sessions | table | postgres
314+
public | prompt_gateway_association | table | postgres
315+
public | prompt_metrics | table | postgres
316+
public | prompts | table | postgres
317+
public | resource_gateway_association | table | postgres
318+
public | resource_metrics | table | postgres
319+
public | resource_subscriptions | table | postgres
320+
public | resources | table | postgres
321+
public | server_metrics | table | postgres
322+
public | server_prompt_association | table | postgres
323+
public | server_resource_association | table | postgres
324+
public | server_tool_association | table | postgres
325+
public | servers | table | postgres
326+
public | tool_gateway_association | table | postgres
327+
public | tool_metrics | table | postgres
328+
public | tools | table | postgres
329+
(18 rows)
330+
```
331+
177332
## 🔒 Authentication and Access
178333

179334
### Generate a JWT Bearer Token
@@ -182,7 +337,7 @@ Use the MCP Gateway container to generate a JWT token:
182337

183338
```bash
184339
docker run -it --rm ghcr.io/ibm/mcp-context-forge:latest \
185-
python3 -m mcpgateway.utils.create_jwt_token -u admin
340+
python3 -m mcpgateway.utils.create_jwt_token -u admin --secret jwt-secret-key
186341
```
187342

188343
Export the token as an environment variable:
@@ -193,12 +348,18 @@ export MCPGATEWAY_BEARER_TOKEN=<paste-token-here>
193348

194349
### Perform Smoke Tests
195350

196-
Test the `/health` and `/tools` endpoints:
351+
Test the `/health`, `/version`, and `/tools` endpoints:
197352

198353
```bash
354+
# Check that the service is healthy
199355
curl -H "Authorization: Bearer $MCPGATEWAY_BEARER_TOKEN" \
200356
https://<your-cloud-run-url>/health
201357

358+
# Check that version reports the version and show Postgres/Redis as connected
359+
curl -H "Authorization: Bearer $MCPGATEWAY_BEARER_TOKEN" \
360+
https://<your-cloud-run-url>/health
361+
362+
# Check that tools return an empty list []
202363
curl -H "Authorization: Bearer $MCPGATEWAY_BEARER_TOKEN" \
203364
https://<your-cloud-run-url>/tools
204365
```
@@ -211,24 +372,11 @@ curl -H "Authorization: Bearer $MCPGATEWAY_BEARER_TOKEN" \
211372

212373
### View Logs via CLI
213374

214-
Tail real-time logs:
375+
Tailing real-time logs requires `google-cloud-cli-log-streaming`. Ex: `sudo apt-get install google-cloud-cli-log-streaming`:
215376

216377
```bash
217-
gcloud run services logs tail mcpgateway --region us-central1
378+
gcloud beta run services logs tail mcpgateway --region=us-central1
218379
```
219-
220-
Read recent logs:
221-
222-
```bash
223-
gcloud run services logs read mcpgateway --limit 50
224-
```
225-
226-
Filter logs by severity:
227-
228-
```bash
229-
gcloud run services logs read mcpgateway --severity=ERROR
230-
```
231-
232380
### Access Logs via Console
233381

234382
Navigate to the [Cloud Run Console](https://console.cloud.google.com/run) and select your service to view logs and metrics.

0 commit comments

Comments
 (0)