GitLab e servidor próprio
Para o projeto que vive no GitLab e publica num servidor da empresa, muitas vezes dentro da rede interna. O pipeline inteiro sai do GitHub Actions e vai para o GitLab CI: a verificação de cada merge request, o release de cada app e o deploy por tag. No servidor, o nginx serve o site, e o MCP roda num container que lê o corpus direto do disco, então não há bucket nem URL de conteúdo para proteger.
É um ponto de partida: revise contra os seus runners e o seu servidor antes do primeiro deploy.
O que preparar
- No repositório: copie o
.gitlab-ci.ymlpara a raiz e apague a pasta.github/. No release, troque@semantic-release/githubpor@semantic-release/gitlabno.releaserc.cjsda raiz e nas dependências dopackage.jsonda raiz. - Nas variáveis de CI/CD do GitLab:
GITLAB_TOKEN(escopoapi, para o release),DEPLOY_HOST,DEPLOY_USER,DEPLOY_SSH_KEY(variável do tipo arquivo, com a chave privada) eDEPLOY_KNOWN_HOSTS. - No servidor: a pasta
/srv/docscomsite/,content/, odocker-compose.ymle ummcp.envcom os segredos do MCP; o Docker com acesso ao registry do GitLab; e o nginx com o site abaixo.
O pipeline
# TEMPLATE (GitLab): the whole pipeline on GitLab CI, for a repository hosted on GitLab, deploying to the
# company's own server: the site served by nginx, the MCP server as a container, the corpus read from disk.
# To use it, copy it to the repository root as .gitlab-ci.yml (and delete .github/). A starting point: review it
# against your runners and server before the first run.
#
# CI/CD variables (Settings > CI/CD > Variables): GITLAB_TOKEN (api scope, for semantic-release), DEPLOY_HOST,
# DEPLOY_USER, DEPLOY_SSH_KEY (file variable, the private key), DEPLOY_KNOWN_HOSTS (the server's host key line).
default:
image: node:24
before_script:
- corepack enable
- pnpm config set store-dir .pnpm-store
- pnpm install --frozen-lockfile
cache:
key:
files: [pnpm-lock.yaml]
paths: [.pnpm-store, .turbo/cache]
variables:
LEFTHOOK: '0'
# Full history: the AI corpus dates each page by the last commit of its source file
GIT_DEPTH: '0'
stages: [verify, release, deploy]
# Fails on broken links, a page outside LLMS_FILES, a project.json drift and a corpus that breaks the contract;
# the MCP tests run against the corpus this same build writes
verify:
stage: verify
script:
- pnpm turbo run lint check-types test build
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
# Merge requests are squash-merged: the title becomes the commit on the default branch and decides the release
mr-title:
stage: verify
script:
- printf '%s\n' "$CI_MERGE_REQUEST_TITLE" | pnpm exec commitlint
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
# The monorepo releases as a whole (tag v<x.y.z>). On GitLab, swap @semantic-release/github for
# @semantic-release/gitlab in .releaserc.cjs and in the root devDependencies
release:
stage: release
script:
- pnpm exec semantic-release
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_COMMIT_MESSAGE !~ /^chore\(release\)/
# A version tag: build, copy the site and the corpus to the server. The MCP container reads the corpus from disk
deploy-docs:
stage: deploy
script:
- pnpm turbo run build --filter @exemplo/docs
- apt-get update -qq && apt-get install -y -qq rsync openssh-client > /dev/null
- install -m 600 "$DEPLOY_SSH_KEY" ~/.deploy-key && mkdir -p ~/.ssh && echo "$DEPLOY_KNOWN_HOSTS" > ~/.ssh/known_hosts
- rsync -az --delete -e "ssh -i ~/.deploy-key" --exclude ai-corpus.json apps/docs/build/ "$DEPLOY_USER@$DEPLOY_HOST:/srv/docs/site/"
- rsync -az -e "ssh -i ~/.deploy-key" apps/docs/build/ai-corpus.json "$DEPLOY_USER@$DEPLOY_HOST:/srv/docs/content/ai-corpus.json"
rules:
- if: $CI_COMMIT_TAG =~ /^v\d/
# The same tag: build the MCP image into the GitLab registry and restart the container on the server
deploy-mcp:
stage: deploy
image: docker:27
services: [docker:27-dind]
before_script: []
script:
- version="${CI_COMMIT_TAG#v}"
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" "$CI_REGISTRY"
- docker build --file apps/mcp/Dockerfile --tag "$CI_REGISTRY_IMAGE/mcp:$version" --tag "$CI_REGISTRY_IMAGE/mcp:latest" .
- docker push "$CI_REGISTRY_IMAGE/mcp:$version"
- docker push "$CI_REGISTRY_IMAGE/mcp:latest"
- apk add --no-cache openssh-client > /dev/null
- install -m 600 "$DEPLOY_SSH_KEY" ~/.deploy-key && mkdir -p ~/.ssh && echo "$DEPLOY_KNOWN_HOSTS" > ~/.ssh/known_hosts
- ssh -i ~/.deploy-key "$DEPLOY_USER@$DEPLOY_HOST" "cd /srv/docs && docker compose pull mcp && docker compose up -d mcp"
rules:
- if: $CI_COMMIT_TAG =~ /^v\d/
O MCP no servidor
O deploy das docs copia o ai-corpus.json para /srv/docs/content, e o MCP lê de lá (CONTENT_FILE), recarregando quando o arquivo muda.
# TEMPLATE (own server): the docs MCP server on the company's server, in /srv/docs/docker-compose.yml.
# The docs deploy copies ai-corpus.json to /srv/docs/content; the server reads it from disk (CONTENT_FILE) and reloads
# when the file changes. Secrets go in /srv/docs/mcp.env (never in the repository), e.g.:
# PUBLIC_URL=https://docs-mcp.example.com
# GOOGLE_CLIENT_ID=… GOOGLE_CLIENT_SECRET=… TOKEN_SIGNING_KEY=… ALLOWED_DOMAIN=example.com
services:
mcp:
image: registry.gitlab.com/<group>/<project>/mcp:latest
restart: unless-stopped
env_file: mcp.env
environment:
CONTENT_FILE: /data/ai-corpus.json
volumes:
- ./content:/data:ro
ports:
- '127.0.0.1:8080:8080'
O nginx
Na VPN, o site fica só na rede interna. Para ter login, ponha um proxy com o SSO da empresa (o oauth2-proxy, ou o proxy do próprio provedor de identidade) na frente do primeiro bloco. O MCP tem login próprio, então o nginx só cuida do TLS.
# TEMPLATE (own server): nginx site of the docs and of its MCP server. Docusaurus writes each route as a folder with
# an index.html, so try_files resolves /docs/intro to /docs/intro/index.html.
# Access: on the company VPN, keep it on the internal network; for a login in front of the site, put a reverse proxy
# with the company SSO (oauth2-proxy, the identity provider's own proxy) before these locations.
server {
listen 443 ssl;
server_name docs.example.com;
ssl_certificate /etc/ssl/docs/fullchain.pem;
ssl_certificate_key /etc/ssl/docs/privkey.pem;
root /srv/docs/site;
location / {
try_files $uri $uri/index.html $uri.html =404;
}
}
# The MCP server has its own sign-in (OAuth); nginx only terminates TLS and forwards
server {
listen 443 ssl;
server_name docs-mcp.example.com;
ssl_certificate /etc/ssl/docs-mcp/fullchain.pem;
ssl_certificate_key /etc/ssl/docs-mcp/privkey.pem;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}