Google Cloud
Com ele, cada versão na main publica o site no App Engine (só arquivos estáticos, atrás do Identity-Aware Proxy) e o corpus num bucket do Cloud Storage, e sobe uma imagem nova do MCP no Cloud Run. O GitHub entra no Google Cloud por Workload Identity Federation, sem chave guardada no repositório.
Para ligar, copie os workflows de deploy/gcp/ para .github/workflows/, descomente os jobs deploy-docs e deploy-mcp no fim do .github/workflows/release.yml, crie os recursos de Publicar o site e de Operar o MCP e preencha as variáveis do repositório no GitHub: GCP_PROJECT_ID, GCP_REGION, GCP_WIF_PROVIDER, GCP_DEPLOY_SA, CONTENT_BUCKET e MCP_SERVICE. Sem GCP_PROJECT_ID, os jobs são pulados.
O site no App Engine
O App Engine serve o build como está. O app.yaml só diz como uma rota vira arquivo: /docs/intro/ é a pasta com o index.html que o Docusaurus gerou.
# App Engine standard, static files only: the Docusaurus build is served as it is, no container.
# CI copies this file into build/ and deploys from there (only the site is uploaded).
# Access is limited to the Google accounts of the login domain (site.loginDomain in project.json) by
# Identity-Aware Proxy (IAP), set on the app.
runtime: python312
service: default
default_expiration: 10m
handlers:
- url: /
static_files: index.html
upload: index\.html
secure: always
# Any file with an extension: assets, .md pages for AI tools, llms*.txt, sitemap
- url: /(.*\.[A-Za-z0-9]+)$
static_files: \1
upload: .*\.[A-Za-z0-9]+$
secure: always
# A route (/docs/intro or /docs/intro/) is a folder with an index.html
- url: /(.*?)/?$
static_files: \1/index.html
upload: .*/index\.html$
secure: always
O deploy das docs
Roda a cada versão do monorepo (release.yml) e à mão, pela aba Actions. Mantém as 5 versões mais novas do App Engine para voltar com um clique.
name: Deploy docs
# TEMPLATE (GCP): copy it to .github/workflows/ and uncomment the deploy-docs job of release.yml to turn it on.
# Example deploy on GCP (the template is provider-agnostic: on AWS, Azure or own servers, replace this job; the
# equivalents are on /sobre-a-doc/publicar-o-site). Parameterized by repo variables: App Engine standard
# (static files only) behind IAP, plus the AI
# corpus published to the bucket the MCP server reads. Runs after every docs release (release.yml) and by hand.
# Repo variables: GCP_PROJECT_ID, GCP_WIF_PROVIDER, GCP_DEPLOY_SA, CONTENT_BUCKET. Without GCP_PROJECT_ID the job
# is skipped. The resources to create are listed on /sobre-a-doc/publicar-o-site.
on:
workflow_call:
inputs:
ref:
description: 'Version tag to deploy (v<x.y.z>)'
required: false
type: string
workflow_dispatch:
inputs:
ref:
description: 'Version tag to deploy (empty = the ref this run was started from)'
required: false
type: string
permissions:
contents: read
id-token: write
concurrency:
group: docs-deploy
cancel-in-progress: false
env:
LEFTHOOK: 0
jobs:
deploy:
if: vars.GCP_PROJECT_ID != ''
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
# Full history: the AI corpus dates each page by the last commit of its source file
fetch-depth: 0
- name: Install pnpm
uses: pnpm/action-setup@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: pnpm
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build
run: pnpm turbo run build --filter @exemplo/docs
# Workload Identity Federation: a short-lived token for this repo, no key stored
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
workload_identity_provider: ${{ vars.GCP_WIF_PROVIDER }}
service_account: ${{ vars.GCP_DEPLOY_SA }}
- name: Set up gcloud
uses: google-github-actions/setup-gcloud@v2
# The version name is the release (1.34.0 → v1-34-0); --promote moves all traffic to it
- name: Deploy to App Engine
working-directory: apps/docs
run: |
version="v$(node -p "require('./package.json').version" | tr '.' '-')"
cp ../../deploy/gcp/app.yaml build/app.yaml
gcloud app deploy build/app.yaml --project "${{ vars.GCP_PROJECT_ID }}" \
--version "$version" --promote --quiet
# The MCP server reads the corpus from this bucket and reloads it within minutes. Gzip-encoded: GCS
# decompresses it for clients that do not accept gzip. Keep object versioning on for a rollback.
- name: Publish the AI corpus
if: vars.CONTENT_BUCKET != ''
run: |
gcloud storage cp apps/docs/build/ai-corpus.json \
"gs://${{ vars.CONTENT_BUCKET }}/ai-corpus.json" \
--gzip-local-all --cache-control=no-cache
# Keep the 5 newest production versions, so a rollback is one click in the console
- name: Prune old versions
run: |
gcloud app versions list --project "${{ vars.GCP_PROJECT_ID }}" --service default \
--filter="version.id:v* AND traffic_split=0" --sort-by="~version.createTime" \
--format="value(version.id)" | tail -n +6 | xargs -r \
gcloud app versions delete --project "${{ vars.GCP_PROJECT_ID }}" --service default --quiet
O deploy do MCP
Só troca a imagem. Variáveis de ambiente, segredos, escala e acesso do serviço ficam como foram criados.
name: Deploy MCP
# TEMPLATE (GCP): copy it to .github/workflows/ and uncomment the deploy-mcp job of release.yml to turn it on.
# Example deploy on GCP (any container runtime works: App Runner, ECS, Container Apps, Kubernetes; replace this job
# on another provider). Parameterized by repo variables: a new image of the docs MCP server on Cloud Run. Runs after every
# MCP release (release.yml) and by hand. Only the image changes: env, secrets, scaling and access stay as they were
# set up (see /sobre-a-doc/operar-o-mcp). Repo variables: GCP_PROJECT_ID, GCP_REGION,
# GCP_WIF_PROVIDER, GCP_DEPLOY_SA, MCP_SERVICE (default docs-mcp). Without GCP_PROJECT_ID the job is skipped.
on:
workflow_call:
inputs:
ref:
description: 'Version tag to deploy (v<x.y.z>)'
required: false
type: string
workflow_dispatch:
inputs:
ref:
description: 'Version tag to deploy (empty = the ref this run was started from)'
required: false
type: string
permissions:
contents: read
id-token: write
concurrency:
group: mcp-deploy
cancel-in-progress: false
env:
REGION: ${{ vars.GCP_REGION }}
SERVICE: ${{ vars.MCP_SERVICE || 'docs-mcp' }}
jobs:
deploy:
if: vars.GCP_PROJECT_ID != ''
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
# Workload Identity Federation: a short-lived token for this repo, no key stored
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
workload_identity_provider: ${{ vars.GCP_WIF_PROVIDER }}
service_account: ${{ vars.GCP_DEPLOY_SA }}
- name: Set up gcloud
uses: google-github-actions/setup-gcloud@v2
# Built from the monorepo root; the image never builds the docs (the server reads the corpus from the bucket)
- name: Build and push the image
id: image
run: |
version="$(node -p "require('./apps/mcp/package.json').version")"
image="${REGION}-docker.pkg.dev/${{ vars.GCP_PROJECT_ID }}/${SERVICE}/${SERVICE}:${version}"
gcloud auth configure-docker "${REGION}-docker.pkg.dev" --quiet
docker build --file apps/mcp/Dockerfile --tag "$image" .
docker push "$image"
echo "image=$image" >> "$GITHUB_OUTPUT"
- name: Deploy to Cloud Run
run: |
gcloud run deploy "$SERVICE" --project "${{ vars.GCP_PROJECT_ID }}" --region "$REGION" \
--image "${{ steps.image.outputs.image }}" --quiet
O preview de cada PR
Opcional. Cada PR vira a versão pr-<n> do App Engine, sem tráfego e atrás do mesmo IAP, com a URL comentada no PR. Quando o PR fecha, a versão é apagada. Copie os dois arquivos juntos.
# TEMPLATE (GCP): publishes the docs of each PR as the App Engine version pr-<n> (no traffic), behind the same IAP as
# production, and comments its URL on the PR. Copy it to .github/workflows/ together with preview-cleanup.yml, which
# deletes the version when the PR closes. Fork PRs get no OIDC token, and a repo without GCP_PROJECT_ID is skipped.
name: Docs Preview
on:
pull_request:
branches:
- main
permissions:
contents: read
env:
LEFTHOOK: 0
jobs:
preview:
name: Publish docs preview
if: github.event.pull_request.head.repo.full_name == github.repository && vars.GCP_PROJECT_ID != ''
runs-on: ubuntu-latest
# Same queue as preview-cleanup.yml for this PR, never cancelled: a cleanup waits for a deploy in progress
concurrency:
group: docs-preview-${{ github.event.pull_request.number }}
cancel-in-progress: false
permissions:
contents: read
id-token: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: pnpm
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build the docs
run: pnpm turbo run build --filter @exemplo/docs
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
workload_identity_provider: ${{ vars.GCP_WIF_PROVIDER }}
service_account: ${{ vars.GCP_DEPLOY_SA }}
- name: Set up gcloud
uses: google-github-actions/setup-gcloud@v2
# The PR may have closed while the build ran: never publish a preview the cleanup already passed
- name: Check the PR is still open
id: open
env:
GH_TOKEN: ${{ github.token }}
run: |
state=$(gh api "repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}" --jq .state)
echo "open=$([ "$state" = "open" ] && echo true || echo false)" >> "$GITHUB_OUTPUT"
- name: Deploy the preview version
if: steps.open.outputs.open == 'true'
id: deploy
env:
VERSION: pr-${{ github.event.pull_request.number }}
run: |
cp deploy/gcp/app.yaml apps/docs/build/app.yaml
gcloud app deploy apps/docs/build/app.yaml --project "${{ vars.GCP_PROJECT_ID }}" \
--version "$VERSION" --no-promote --quiet
url=$(gcloud app versions describe "$VERSION" --service default \
--project "${{ vars.GCP_PROJECT_ID }}" --format="value(versionUrl)")
echo "url=$url" >> "$GITHUB_OUTPUT"
- name: Comment the preview URL on the PR
if: steps.open.outputs.open == 'true'
env:
GH_TOKEN: ${{ github.token }}
PR_NUMBER: ${{ github.event.pull_request.number }}
SHA: ${{ github.event.pull_request.head.sha }}
URL: ${{ steps.deploy.outputs.url }}
run: |
marker='<!-- docs-preview -->'
body="${marker}
📖 **Docs preview**: ${URL}
Commit \`${SHA:0:7}\`. Mesmo acesso da produção. Removido quando o PR fecha."
comment_id=$(gh api "repos/${{ github.repository }}/issues/${PR_NUMBER}/comments" \
--paginate --jq ".[] | select(.body | startswith(\"${marker}\")) | .id" | head -n1)
if [ -n "$comment_id" ]; then
gh api -X PATCH "repos/${{ github.repository }}/issues/comments/${comment_id}" -f body="$body"
else
gh api "repos/${{ github.repository }}/issues/${PR_NUMBER}/comments" -f body="$body"
fi
name: Preview Cleanup
# TEMPLATE (GCP): deletes the PR's docs preview version (published by docs-preview.yml) when the PR is closed or
# merged. Copy it to .github/workflows/ together with docs-preview.yml.
on:
pull_request:
branches:
- main
types: [closed]
permissions:
contents: read
id-token: write
jobs:
cleanup:
name: Delete preview
if: github.event.pull_request.head.repo.full_name == github.repository && vars.GCP_PROJECT_ID != ''
runs-on: ubuntu-latest
# Same queue as the docs-preview.yml: waits for a deploy in progress, then deletes it
concurrency:
group: docs-preview-${{ github.event.pull_request.number }}
cancel-in-progress: false
steps:
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
workload_identity_provider: ${{ vars.GCP_WIF_PROVIDER }}
service_account: ${{ vars.GCP_DEPLOY_SA }}
- name: Set up gcloud
uses: google-github-actions/setup-gcloud@v2
- name: Delete the preview version
run: |
gcloud app versions delete "pr-${{ github.event.pull_request.number }}" \
--service default --project "${{ vars.GCP_PROJECT_ID }}" --quiet || true