@john.klaumann/devops-deploy-cli
v1.1.0
Published
CLI tool to generate Dockerfile, Terraform and deployment scripts for .NET microservices
Downloads
5
Maintainers
Readme
DevOps Deploy CLI
A CLI tool to automate the generation of deployment files for .NET microservices, eliminating dependency on DevOps team for basic deployment tasks.
🚀 Features
- Automatic Dockerfile: Generates optimized Dockerfile based on your .NET project
- Complete Terraform: Creates full configuration for AWS ECR + Kubernetes
- Deploy scripts: Ready-to-use bash scripts for AWS deployment
- Auto-discovery: Automatically finds .sln and launchSettings.json files
- Multi-environment: Support for dev, staging and production
📦 Installation
Option 1: Global Installation (Recommended)
npm install -g @john.klaumann/devops-deploy-cliOption 2: Use with npx (No installation)
npx @john.klaumann/devops-deploy-cli generate --allOption 3: Install in Project
npm install @john.klaumann/devops-deploy-cli --save-dev🛠️ Basic Usage
1. Generate all deployment files
# In your .NET project directory
devops-deploy generate --allThis will generate:
Dockerfilemain.tf,variables.tf,outputs.tfterraform.tfvars.exampledeploy.sh,quick-deploy.sh,rollback.sh,status.shREADME.mdwith instructions
2. Generate only Dockerfile
devops-deploy generate --docker3. Generate only Terraform files
devops-deploy generate --terraform4. Generate only deployment scripts
devops-deploy generate --deploy🎯 Available Commands
generate
Generates deployment files based on your .NET project.
devops-deploy generate [options]Options:
--docker: Generate only Dockerfile--terraform: Generate only Terraform files--deploy: Generate only deployment scripts--all: Generate all files (default if no option specified)--solution <path>: Path to solution file (.sln) (auto-detected if not specified)--settings <path>: Path to launchSettings.json (auto-detected if not specified)--output <path>: Output directory (default: ./deploy-output)
Examples:
# Generate everything in current directory
devops-deploy generate --all
# Generate only Dockerfile in specific directory
devops-deploy generate --docker --output ./docker-files
# Specify files manually
devops-deploy generate --all --solution ./MySolution.sln --settings ./Properties/launchSettings.jsoninit
Initialize project configuration with interactive wizard.
devops-deploy initThis will create a devops-config.json file with your project settings.
📁 Generated Files Structure
deploy-output/
├── Dockerfile # Docker multi-stage build
├── main.tf # Terraform main configuration
├── variables.tf # Terraform variables
├── outputs.tf # Terraform outputs
├── terraform.tfvars.example # Example variables file
├── deploy.sh # Full deployment script
├── quick-deploy.sh # Quick update script
├── rollback.sh # Rollback script
├── status.sh # Status check script
└── README.md # Deployment guide🐳 Using the Generated Dockerfile
The generated Dockerfile is optimized for .NET with:
- Multi-stage build
- Non-root user for security
- Configured health check
- Optimized dependency caching
- Environment variables from launchSettings.json
# Build image
docker build -t my-microservice .
# Local run for testing
docker run -p 8080:8080 my-microservice☁️ Deploy with Terraform
Configure variables:
cp terraform.tfvars.example terraform.tfvars # Edit terraform.tfvars with your valuesRun Terraform:
terraform init terraform plan terraform apply
This will create:
- ECR Repository on AWS
- Kubernetes Deployment
- Kubernetes Service
- ConfigMaps and Secrets
- Horizontal Pod Autoscaler
- Health checks
🚀 Deploy with Bash Scripts
Full Deploy (First time)
chmod +x deploy.sh
./deploy.shThe script will:
- Check prerequisites (AWS CLI, Docker, kubectl)
- Create ECR repository if it doesn't exist
- Build and push image
- Apply Terraform configurations
- Check deployment status
Quick Update
For updates after code changes:
./quick-deploy.shCheck Status
./status.shRollback
If something goes wrong:
./rollback.sh🔧 Advanced Configuration
Environment Variables
You can configure script behavior:
export AWS_REGION="us-west-2"
export IMAGE_TAG="v1.2.3"
export KUBERNETES_NAMESPACE="my-namespace"
export ENVIRONMENT="production"
./deploy.shDockerfile Customization
If you need to customize the Dockerfile:
Generate base file:
devops-deploy generate --dockerEdit the generated
Dockerfileas neededUse deployment scripts normally
Custom Terraform Configuration
Most important Terraform variables:
# terraform.tfvars
aws_region = "us-east-1"
environment = "production"
replicas = 3
cpu_limit = "1000m"
memory_limit = "1Gi"
auth_client_id = "your-client-id"
auth_client_secret = "your-client-secret"🛡️ Security and Best Practices
The tool follows security best practices:
- Dockerfile: Non-root user, multi-stage build
- Kubernetes: Resource limits, health checks, secrets for credentials
- AWS: Restricted IAM policies, ECR image scanning
- Variables: Secrets separated from configs
🔍 Troubleshooting
Problem: "No solution file found"
Solution: Specify path manually:
devops-deploy generate --solution ./path/to/your.sln --allProblem: "launchSettings.json not found"
Solution: Check if file exists in Properties/launchSettings.json or specify:
devops-deploy generate --settings ./Properties/launchSettings.json --allProblem: Deploy fails with AWS authentication error
Solution: Configure AWS CLI:
aws configure
# or use environment variables
export AWS_ACCESS_KEY_ID="..."
export AWS_SECRET_ACCESS_KEY="..."Problem: kubectl cannot connect
Solution: Configure kubeconfig:
aws eks update-kubeconfig --region us-east-1 --name my-cluster📋 Complete Example
Let's say you have a project called "FlowchartService":
# 1. In project directory
cd FlowchartService
# 2. Generate deployment files
devops-deploy generate --all
# 3. Review generated files
ls deploy-output/
# 4. Configure Terraform
cp deploy-output/terraform.tfvars.example deploy-output/terraform.tfvars
# Edit terraform.tfvars with your credentials
# 5. Deploy
cd deploy-output
chmod +x *.sh
./deploy.sh
# 6. Check if it's working
./status.sh🤝 Contributing
To improve the tool:
- Clone the repository
- Install dependencies:
npm install - Make your changes
- Test:
npm test - Open a Pull Request
📄 License
MIT License - see LICENSE file for details.
Tip: Add the deploy-output/ directory to your .gitignore if you don't want to version the generated files, or version only the Dockerfile if needed.
