Enterprise Reference

Developer Documentation & Multi-Git Architecture

StageDock automates the lifecycle of ephemeral pull request environments, static AST quality gates, and database seed fixtures across GitHub, GitLab, Bitbucket, and self-hosted Git repositories.

1. CLI Quickstart & Diagnostic Check

Set up StageDock locally or inside your CI/CD runner using the official Node CLI.

The StageDock CLI inspects your local environment for Docker Engine (v24+), PostgreSQL (v16), Redis, and network bridge health. Run the command below in your project root:

terminal ~ bash / zshbash
1# Initialize StageDock in your project repository
2pnpm dlx stagedock@latest init
3
4# Run infrastructure pre-flight diagnostics
5pnpm dlx stagedock@latest doctor
6
7# Optional: Link to an existing remote workspace
8stagedock link --workspace main-workspace

2. Universal Git Webhook Integration

Connect GitHub, GitLab Cloud/Omnibus, Bitbucket, or self-hosted Git repositories to trigger automated previews.

In GitHub: Go to Repository Settings ➔ Webhooks ➔ Add webhook. Configure with:

  • Payload URL: https://api.stagedock.dev/api/webhooks/git (or /api/webhooks/github)
  • Content type: application/json
  • Secret: Your generated HMAC Secret
  • Security Verification: Validated via X-Hub-Signature-256
  • Events: Pull requests (opened, synchronize, closed, reopened)
github-webhook-spec.confbash
1Payload URL: https://api.stagedock.dev/api/webhooks/git
2Content type: application/json
3Secret: [Your Webhook Secret from Project Settings]
4SSL verification: Enable SSL verification
5
6Header Sent: X-Hub-Signature-256: sha256=<hmac_hash>
7Events to trigger:
8[X] Let me select individual events
9 [X] Pull requests (opened, synchronize, closed, reopened)
10 [X] Pushes (optional for trunk validation)

3. Multi-Stage Dockerfile Format

Deterministic image builds, layer caching, and unprivileged user security.

StageDock compiles an isolated container for each pull request. Ensure your project provides a standard multi-stage Dockerfile in the repository root. Containers must listen on port 3000 and run under an unprivileged user (USER node):

Dockerfile (Multi-Stage Production)dockerfile
1# Multi-stage corporate Node.js Dockerfile for StageDock
2FROM node:20-alpine AS base
3WORKDIR /app
4RUN apk add --no-cache libc6-compat
5ENV NODE_ENV=production
6
7# Install dependencies
8FROM base AS deps
9COPY package.json pnpm-lock.yaml* package-lock.json* ./
10RUN npm ci --omit=dev
11
12# Builder stage
13FROM base AS builder
14COPY --from=deps /app/node_modules ./node_modules
15COPY . .
16RUN npm run build
17
18# Runner stage (unprivileged non-root user)
19FROM base AS runner
20USER node
21COPY --from=builder /app ./
22EXPOSE 3000
23ENV PORT=3000
24CMD ["npm", "start"]

4. Project .env Secret Vault

Encrypted environment configuration injected directly into ephemeral containers.

Store your API tokens, payment credentials, and microservice hosts inside the Project Vault in the Client Portal. StageDock injects these variables during container creation, replacing database connection strings with the dynamically provisioned ephemeral PostgreSQL instance:

.env.sandbox.vaultbash
1# Runtime Vault Variables (Injected automatically per PR container)
2DATABASE_URL=postgresql://sandbox_user:secret@postgres-sandbox:5432/pr_42_db
3NEXT_PUBLIC_API_URL=https://api.stagedock.dev
4REDIS_URL=redis://redis:6379/1
5JWT_SECRET=stagedock_ephemeral_runtime_token_key

5. Traefik Wildcard Routing & SSL Ingress

Automatic subdomain assignment and zero-downtime routing table registration.

Every preview environment is assigned a scoped wildcard domain, such as pr-42.stagedock.localhost (locally) or pr-42-orders.stagedock.dev (production). Traefik dynamically binds incoming requests to the target container:

traefik-dynamic-routing.ymlyaml
1# Traefik Ingress Dynamic Routing Rule
2# Automatically generated for each PR sandbox container
3
4http:
5 routers:
6 pr-42-router:
7 rule: "Host(`pr-42.stagedock.localhost`) || Host(`pr-42.stagedock.dev`)"
8 service: pr-42-service
9 entryPoints:
10 - web
11 - websecure
12 tls:
13 certResolver: letsencrypt
14 services:
15 pr-42-service:
16 loadBalancer:
17 servers:
18 - url: "http://sandbox-container-42:3000"