|
| 1 | +# GitHub Actions Workflows |
| 2 | + |
| 3 | +This directory contains GitHub Actions workflows for building and deploying the MCP BigQuery server. |
| 4 | + |
| 5 | +## Docker Hub Publishing |
| 6 | + |
| 7 | +The `docker-publish.yml` workflow automatically builds and publishes Docker images to Docker Hub. |
| 8 | + |
| 9 | +### Setup Instructions |
| 10 | + |
| 11 | +1. **Create a Docker Hub account** (if you don't have one): |
| 12 | + - Go to https://hub.docker.com/signup |
| 13 | + |
| 14 | +2. **Create an access token**: |
| 15 | + - Log in to Docker Hub |
| 16 | + - Go to Account Settings → Security → New Access Token |
| 17 | + - Name: `github-actions` |
| 18 | + - Permissions: Read, Write, Delete |
| 19 | + - Copy the token (you won't see it again!) |
| 20 | + |
| 21 | +3. **Configure GitHub Secrets**: |
| 22 | + |
| 23 | + Go to your GitHub repository → Settings → Secrets and variables → Actions, and add: |
| 24 | + |
| 25 | + | Secret Name | Description | Example Value | |
| 26 | + | -------------------- | ------------------------------ | ------------------ | |
| 27 | + | `DOCKERHUB_USERNAME` | Your Docker Hub username | `yourusername` | |
| 28 | + | `DOCKERHUB_TOKEN` | Docker Hub access token | `dckr_pat_xxx...` | |
| 29 | + |
| 30 | +4. **Push to trigger build**: |
| 31 | + ```bash |
| 32 | + git push origin main |
| 33 | + ``` |
| 34 | + |
| 35 | +### Workflow Features |
| 36 | + |
| 37 | +- ✅ **Multi-architecture builds** (linux/amd64, linux/arm64) |
| 38 | +- ✅ **Automatic tagging** based on git tags and branches |
| 39 | +- ✅ **Pull request builds** (without pushing) |
| 40 | +- ✅ **Build caching** for faster builds |
| 41 | +- ✅ **README sync** to Docker Hub |
| 42 | +- ✅ **Manual trigger** via workflow_dispatch |
| 43 | + |
| 44 | +### Image Tags |
| 45 | + |
| 46 | +The workflow creates the following tags: |
| 47 | + |
| 48 | +- `latest` - Latest build from main branch |
| 49 | +- `main` - Latest build from main branch |
| 50 | +- `v1.2.3` - Semantic version tags (when you push a git tag) |
| 51 | +- `v1.2` - Major.minor version |
| 52 | +- `v1` - Major version |
| 53 | +- `main-abc1234` - Branch name with commit SHA |
| 54 | +- `pr-123` - Pull request number |
| 55 | + |
| 56 | +### Using the Published Image |
| 57 | + |
| 58 | +```bash |
| 59 | +# Pull the latest image |
| 60 | +docker pull yourusername/mcp-server-bigquery:latest |
| 61 | + |
| 62 | +# Pull a specific version |
| 63 | +docker pull yourusername/mcp-server-bigquery:v0.3.0 |
| 64 | + |
| 65 | +# Run the container |
| 66 | +docker run -p 8080:8080 \ |
| 67 | + -e BIGQUERY_PROJECT=your-project-id \ |
| 68 | + -e BIGQUERY_LOCATION=us-central1 \ |
| 69 | + -e MCP_TRANSPORT=http \ |
| 70 | + yourusername/mcp-server-bigquery:latest |
| 71 | +``` |
| 72 | + |
| 73 | +### Creating a Release |
| 74 | + |
| 75 | +To publish a versioned release: |
| 76 | + |
| 77 | +```bash |
| 78 | +# Tag the release |
| 79 | +git tag -a v0.3.0 -m "Release v0.3.0" |
| 80 | +git push origin v0.3.0 |
| 81 | + |
| 82 | +# The workflow will automatically build and push: |
| 83 | +# - yourusername/mcp-server-bigquery:v0.3.0 |
| 84 | +# - yourusername/mcp-server-bigquery:v0.3 |
| 85 | +# - yourusername/mcp-server-bigquery:v0 |
| 86 | +# - yourusername/mcp-server-bigquery:latest |
| 87 | +``` |
| 88 | + |
| 89 | +## Cloud Run Deployment |
| 90 | + |
| 91 | +The `deploy-cloud-run.yml.example` file provides an example workflow for deploying to Google Cloud Run. |
| 92 | + |
| 93 | +### Setup Instructions |
| 94 | + |
| 95 | +1. **Copy the example file:** |
| 96 | + ```bash |
| 97 | + cp .github/workflows/deploy-cloud-run.yml.example .github/workflows/deploy-cloud-run.yml |
| 98 | + ``` |
| 99 | + |
| 100 | +2. **Create an Artifact Registry repository:** |
| 101 | + ```bash |
| 102 | + gcloud artifacts repositories create mcp-server-bigquery \ |
| 103 | + --repository-format=docker \ |
| 104 | + --location=us-central1 \ |
| 105 | + --description="MCP BigQuery Server Docker images" |
| 106 | + ``` |
| 107 | + |
| 108 | +3. **Set up Workload Identity Federation (Recommended):** |
| 109 | + |
| 110 | + This is the secure, keyless authentication method for GitHub Actions. |
| 111 | + |
| 112 | + ```bash |
| 113 | + # Set variables |
| 114 | + export PROJECT_ID="your-gcp-project-id" |
| 115 | + export POOL_NAME="github-actions-pool" |
| 116 | + export PROVIDER_NAME="github-provider" |
| 117 | + export SERVICE_ACCOUNT_NAME="github-actions-sa" |
| 118 | + export REPO="your-github-username/mcp-server-bigquery" |
| 119 | + |
| 120 | + # Create Workload Identity Pool |
| 121 | + gcloud iam workload-identity-pools create $POOL_NAME \ |
| 122 | + --location="global" \ |
| 123 | + --display-name="GitHub Actions Pool" |
| 124 | + |
| 125 | + # Create Workload Identity Provider |
| 126 | + gcloud iam workload-identity-pools providers create-oidc $PROVIDER_NAME \ |
| 127 | + --location="global" \ |
| 128 | + --workload-identity-pool=$POOL_NAME \ |
| 129 | + --display-name="GitHub Provider" \ |
| 130 | + --attribute-mapping="google.subject=assertion.sub,attribute.actor=assertion.actor,attribute.repository=assertion.repository" \ |
| 131 | + --issuer-uri="https://token.actions.githubusercontent.com" |
| 132 | + |
| 133 | + # Create Service Account |
| 134 | + gcloud iam service-accounts create $SERVICE_ACCOUNT_NAME \ |
| 135 | + --display-name="GitHub Actions Service Account" |
| 136 | + |
| 137 | + # Grant permissions to the service account |
| 138 | + gcloud projects add-iam-policy-binding $PROJECT_ID \ |
| 139 | + --member="serviceAccount:$SERVICE_ACCOUNT_NAME@$PROJECT_ID.iam.gserviceaccount.com" \ |
| 140 | + --role="roles/run.admin" |
| 141 | + |
| 142 | + gcloud projects add-iam-policy-binding $PROJECT_ID \ |
| 143 | + --member="serviceAccount:$SERVICE_ACCOUNT_NAME@$PROJECT_ID.iam.gserviceaccount.com" \ |
| 144 | + --role="roles/artifactregistry.writer" |
| 145 | + |
| 146 | + gcloud projects add-iam-policy-binding $PROJECT_ID \ |
| 147 | + --member="serviceAccount:$SERVICE_ACCOUNT_NAME@$PROJECT_ID.iam.gserviceaccount.com" \ |
| 148 | + --role="roles/iam.serviceAccountUser" |
| 149 | + |
| 150 | + # Allow GitHub Actions to impersonate the service account |
| 151 | + gcloud iam service-accounts add-iam-policy-binding \ |
| 152 | + $SERVICE_ACCOUNT_NAME@$PROJECT_ID.iam.gserviceaccount.com \ |
| 153 | + --role="roles/iam.workloadIdentityUser" \ |
| 154 | + --member="principalSet://iam.googleapis.com/projects/PROJECT_NUMBER/locations/global/workloadIdentityPools/$POOL_NAME/attribute.repository/$REPO" |
| 155 | + ``` |
| 156 | + |
| 157 | + Note: Replace `PROJECT_NUMBER` with your actual GCP project number (find it with `gcloud projects describe $PROJECT_ID --format="value(projectNumber)"`). |
| 158 | + |
| 159 | +4. **Configure GitHub Secrets:** |
| 160 | + |
| 161 | + Go to your GitHub repository → Settings → Secrets and variables → Actions, and add: |
| 162 | + |
| 163 | + | Secret Name | Description | Example Value | |
| 164 | + | ------------------------ | --------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------ | |
| 165 | + | `GCP_PROJECT_ID` | Your GCP project ID | `my-project-123` | |
| 166 | + | `WIF_PROVIDER` | Workload Identity Federation provider resource name | `projects/PROJECT_NUMBER/locations/global/workloadIdentityPools/github-actions-pool/providers/github-provider` | |
| 167 | + | `WIF_SERVICE_ACCOUNT` | Service account email for Workload Identity Federation | `[email protected]` | |
| 168 | + | `BIGQUERY_PROJECT` | BigQuery project ID (can be same as GCP_PROJECT_ID or different) | `my-data-project` | |
| 169 | + | `BIGQUERY_LOCATION` | BigQuery location/region | `us-central1` or `europe-west4` | |
| 170 | + |
| 171 | +5. **Optional: Service Account Key (Alternative to Workload Identity Federation):** |
| 172 | + |
| 173 | + If you prefer using a service account key instead of Workload Identity Federation: |
| 174 | + |
| 175 | + ```bash |
| 176 | + # Create service account |
| 177 | + gcloud iam service-accounts create github-actions \ |
| 178 | + --display-name="GitHub Actions" |
| 179 | + |
| 180 | + # Grant permissions |
| 181 | + gcloud projects add-iam-policy-binding $PROJECT_ID \ |
| 182 | + --member="serviceAccount:github-actions@$PROJECT_ID.iam.gserviceaccount.com" \ |
| 183 | + --role="roles/run.admin" |
| 184 | + |
| 185 | + gcloud projects add-iam-policy-binding $PROJECT_ID \ |
| 186 | + --member="serviceAccount:github-actions@$PROJECT_ID.iam.gserviceaccount.com" \ |
| 187 | + --role="roles/artifactregistry.writer" |
| 188 | + |
| 189 | + # Create and download key |
| 190 | + gcloud iam service-accounts keys create key.json \ |
| 191 | + --iam-account=github-actions@$PROJECT_ID.iam.gserviceaccount.com |
| 192 | + ``` |
| 193 | + |
| 194 | + Then update the workflow to use `google-github-actions/auth@v2` with `credentials_json` instead of Workload Identity Federation. |
| 195 | + |
| 196 | +6. **Customize the workflow:** |
| 197 | + |
| 198 | + Edit `.github/workflows/deploy-cloud-run.yml` and adjust: |
| 199 | + - `REGION`: Your preferred Cloud Run region |
| 200 | + - `SERVICE_NAME`: Your service name |
| 201 | + - Resource limits (memory, CPU, instances) |
| 202 | + - Environment variables |
| 203 | + |
| 204 | +7. **Push to trigger deployment:** |
| 205 | + ```bash |
| 206 | + git add .github/workflows/deploy-cloud-run.yml |
| 207 | + git commit -m "Add Cloud Run deployment workflow" |
| 208 | + git push origin main |
| 209 | + ``` |
| 210 | + |
| 211 | +### Workflow Features |
| 212 | + |
| 213 | +- ✅ **Keyless authentication** using Workload Identity Federation |
| 214 | +- ✅ **Multi-architecture support** (builds for linux/amd64) |
| 215 | +- ✅ **Image tagging** with both commit SHA and `latest` |
| 216 | +- ✅ **Automatic deployment** on push to main branch |
| 217 | +- ✅ **Manual trigger** via workflow_dispatch |
| 218 | +- ✅ **Secure secrets management** via GitHub Secrets |
| 219 | +- ✅ **Auto-scaling** with configurable min/max instances |
| 220 | + |
| 221 | +### Testing the Deployment |
| 222 | + |
| 223 | +After deployment, test your Cloud Run service: |
| 224 | + |
| 225 | +```bash |
| 226 | +# Get the service URL |
| 227 | +SERVICE_URL=$(gcloud run services describe mcp-server-bigquery \ |
| 228 | + --region us-central1 \ |
| 229 | + --format 'value(status.url)') |
| 230 | + |
| 231 | +# Test health endpoint |
| 232 | +curl $SERVICE_URL/health |
| 233 | + |
| 234 | +# Expected response: |
| 235 | +# {"status":"healthy","service":"bigquery-mcp-server"} |
| 236 | +``` |
| 237 | + |
| 238 | +### Troubleshooting |
| 239 | + |
| 240 | +**Build fails:** |
| 241 | +- Check that Artifact Registry repository exists |
| 242 | +- Verify service account has `artifactregistry.writer` role |
| 243 | + |
| 244 | +**Deployment fails:** |
| 245 | +- Verify service account has `run.admin` role |
| 246 | +- Check that all required secrets are set in GitHub |
| 247 | +- Review Cloud Run logs: `gcloud run services logs read mcp-server-bigquery --region us-central1` |
| 248 | + |
| 249 | +**Service fails to start:** |
| 250 | +- Check environment variables are set correctly |
| 251 | +- Verify BigQuery permissions for the Cloud Run service account |
| 252 | +- Review logs for authentication errors |
| 253 | + |
| 254 | +### Cost Optimization |
| 255 | + |
| 256 | +The example workflow configures: |
| 257 | +- `--min-instances 0`: Scales to zero when not in use (no cost when idle) |
| 258 | +- `--max-instances 10`: Limits maximum concurrent instances |
| 259 | +- `--memory 512Mi`: Minimal memory allocation |
| 260 | +- `--cpu 1`: Single CPU core |
| 261 | + |
| 262 | +Adjust these based on your usage patterns and budget. |
0 commit comments