CI/CD Pipeline Tutorial: GitHub Actions + Docker for .NET 8 Deployment

Automatic testing, building, and Docker image publishing on every push. How we build CI/CD pipelines that enable safe zero-downtime deployments to production.

Goal: Every Commit Should Be a Safe Deploy

The only way out of "I don't know if it works, let's try" culture is an automated, repeatable, observable CI/CD process. We share the pipeline we use across NWTsoft projects.

Pipeline Flow

Push to main
    │
    ├─► CI: Build & Test (dotnet restore → build → test)
    ├─► Docker: Build & Push (multi-stage → ghcr.io)
    └─► Deploy: SSH to server (pull → stop old → run new)

Key Points

  • Secrets management: Database connection strings and API keys live in GitHub Secrets—never baked into images
  • Health check: If container is unhealthy after deploy, automatic rollback to previous image
  • PR-only testing: Docker push only triggers on main branch push, not PRs
  • SHA-based image tagging: Every deploy is traceable and reversible
  • Multi-stage Dockerfile: SDK image for build (~900MB), ASP.NET runtime image for production (~220MB)

The full GitHub Actions workflow includes three jobs: test, build-and-push (depends on test), and deploy (depends on build-and-push, only runs on main).