Session 05
Project Link
✨ What is this?
A production-ready full-stack starter kit built using modern technologies and best practices:
- Frontend: Angular 20 with Signals, Material Design, and TailwindCSS
- Backend: .NET 9 API implementing Clean Architecture
- Database: PostgreSQL 16 using Dapper ORM
- DevOps: Docker, GitHub Actions, and NGINX
Perfect for developers who want to focus on business logic instead of spending time setting up infrastructure.
🏗️ Why Clean Architecture?
Clean Architecture helps in creating maintainable, testable, and scalable applications by separating concerns and enforcing clear boundaries between layers.
Benefits:
- Independent of frameworks and UI
- Emphasizes testability and loose coupling
- Simplifies onboarding and feature extension
- Ensures long-term maintainability
🚀 Application Demo
A Contact Management Application with:
- Role-Based Access Control (RBAC)
- Secure API endpoints
- Modular and extensible design
🔧 Technologies Used
| Layer | Stack |
|---|---|
| Frontend | Angular 20, Signals, TailwindCSS, Material |
| Backend | .NET 9, Clean Architecture, Dapper ORM |
| Database | PostgreSQL 16 |
| DevOps | Docker, GitHub Actions, NGINX |
🚀 Getting Started to deploy to container using docker compose
🔃 Clone the Repository
git clone https://github.com/nirpendra83/clean-architecture-docker-dotnet-angular.git clean-app
cd clean-app- Create .env File
cp .env.example .env- Run the below command
docker-compose up
docker-compose up -d🚀 Deploy the Application to Kubernetes
1. Clone the Repository
git clone https://github.com/nirpendra83/clean-architecture-docker-dotnet-angular.git clean-app
cd clean-app2. Navigate to the Kubernetes Deployment Directory and Apply Resources
cd kubernetes
kubectl apply -f .3. Verify the Deployment
kubectl get podsJenkins Declarative Pipeline for Deploying to Kubernetes
This pipeline performs the following:
- Clones the Git repository (main branch)
- Navigates to the
kubernetesfolder - Applies all Kubernetes YAML manifests using
kubectl apply -f . - Uses a Jenkins secret file credential for kubeconfig (
kubeconfig-cred-id)
Jenkinsfile (Declarative Pipeline)
pipeline {
agent any
environment {
REPO_URL = 'https://github.com/nirpendra83/clean-architecture-docker-dotnet-angular.git'
BRANCH = 'main'
}
stages {
stage('Clone Repository') {
steps {
git branch: "${BRANCH}", url: "${REPO_URL}"
}
}
stage('Deploy to Kubernetes') {
steps {
withCredentials([file(credentialsId: 'kubeconfig-cred-id', variable: 'KUBECONFIG')]) {
dir('kubernetes') {
sh 'kubectl apply -f .'
}
}
}
}
}
}Configuring Jenkins to Use kubeconfig as a Secret File Credential
To enable your Jenkins pipeline to authenticate with the Kubernetes cluster, follow these steps to store your kubeconfig file securely and use it in your pipeline.
Step 1: Add kubeconfig as a Secret File in Jenkins
- Go to Jenkins Dashboard → Manage Jenkins → Manage Credentials
- Select the appropriate scope (e.g.,
(global)or a specific folder) - Click Add Credentials
- Choose Kind:
Secret file - Upload your
kubeconfigfile - ID: Set it as
kubeconfig-cred-id(or use a custom ID and update the pipeline accordingly) - Optionally, add a description
- Click OK to save
Step 2: Use the kubeconfig Secret File in Your Jenkins Pipeline
In your Jenkinsfile, reference the kubeconfig credential using the withCredentials block:
withCredentials([file(credentialsId: 'kubeconfig-cred-id', variable: 'KUBECONFIG')]) {
sh 'kubectl get pods'
}GitHub Hook Trigger for GITScm Polling
1️⃣ Install Required Plugins
- In Jenkins, go to Manage Jenkins → Plugins → Available Plugins
- Install:
- Git
- GitHub Integration (or GitHub plugin)
- GitHub Branch Source (optional but useful for multibranch)
2️⃣ Configure GitHub in Jenkins
- Go to Manage Jenkins → Configure System
- Find GitHub section.
- Add a new GitHub server:
- Name:
GitHub - Credentials: Add your GitHub Personal Access Token (PAT)
(Permissions:repo,admin:repo_hook) - Click Test Connection to ensure connectivity.
- Name:
3️⃣ Configure the Jenkins Job
- Create or edit your Jenkins pipeline/freestyle job.
- In Source Code Management, select Git and:
- Enter repository URL.
- Add credentials (if private repo).
- Under Build Triggers, check:
- ✅ GitHub hook trigger for GITScm polling
4️⃣ Set Up GitHub Webhook
- Open your GitHub repository in the browser.
- Go to Settings → Webhooks → Add webhook.
- Payload URL:Example:
http://<jenkins-server>/github-webhook/http://jenkins.example.com/github-webhook/ - Content type:
application/json - Select Just the push event (or required events).
- Save the webhook.
5️⃣ Test the Integration
- Push a commit to the GitHub repository.
- Jenkins should start the job automatically without manual polling.
📄 Sample Jenkinsfile for Testing (Windows-Friendly)
pipeline {
agent any
triggers {
githubPush()
}
stages {
stage('Checkout') {
steps {
echo "Checking out code..."
checkout scm
}
}
stage('Build') {
steps {
bat 'echo Building the project...'
}
}
stage('Test') {
steps {
bat 'echo Running tests...'
}
}
stage('Deploy') {
steps {
bat 'echo Deploying application...'
}
}
}
post {
always {
bat 'echo Pipeline finished!'
}
}
}