Dart Deployment

This lesson covers production-ready deployment for Dart CLI, server, and web targets with repeatable CI/CD and rollback-safe releases.

Build Artifacts

Build once and deploy immutable artifacts rather than deploying directly from local, unverified source. Before compiling, run formatting, static analysis, and unit tests as a strict quality gate so broken builds never reach a release artifact. Dart compiles ahead-of-time (AOT) into self-contained native executables for CLI tools and backend services, or compiles to optimized JavaScript for browser targets.

# Verify quality gates
dart format --set-exit-if-changed .
dart analyze
dart test

# Compile executable (server/cli)
dart compile exe bin/server.dart -o build/server

# Compile web app
dart compile js web/main.dart -o build/main.js

Release Strategy

Predictable releases rely on immutable version tags and environment separation. Rather than rebuilding per environment, promote the exact same tested binary or bundle from staging to production while injecting configuration through environment variables at runtime.

  • Use semantic versioning and tag every production release.
  • Promote the same artifact from staging to production.
  • Store environment-specific secrets outside source control.

Pushing an annotated or lightweight Git tag triggers automated release pipelines and gives operators an exact commit reference for rollbacks.

git tag v1.4.0
git push origin v1.4.0

CI/CD Pipeline

Automate lint, test, build, and deploy in one pipeline with manual approval gates for production.

name: dart-release
on:
  push:
    tags:
      - 'v*'

jobs:
  quality-and-build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dart-lang/setup-dart@v1
      - run: dart pub get
      - run: dart analyze
      - run: dart test
      - run: dart compile exe bin/server.dart -o build/server

Deploy Targets

Choose deployment by runtime profile:

  • CLI tool: package binary and distribute through internal release registry.
  • Server API: deploy executable behind reverse proxy/load balancer.
  • Web build: publish static assets to CDN hosting.

Operations Checklist

Shipping an executable is only half of deployment; production services need observability and a tested recovery path before real traffic arrives.

  1. Define health endpoint and startup checks.
  2. Configure structured logging and metrics.
  3. Create rollback command and verify it in staging.
  4. Document incident ownership and escalation path.

Deployment Lab

Practice the full release cycle on a small Dart service before wiring production infrastructure:

  1. Compile a Dart executable and run smoke tests locally.
  2. Create a CI workflow that blocks deploy on failed analyze/test steps.
  3. Deploy to staging, validate logs, then promote to production.