Guides
Automation Guide
Automate DevEx in CI/CD pipelines, deployment scripts, and infrastructure automation
Automation Guide
DevEx excels in automated environments, making it perfect for CI/CD pipelines, infrastructure automation, and deployment workflows. This guide covers integration patterns, automation strategies, and best practices.
Security in Automation: When automating DevEx installations, always review our Security Best Practices guide. Pin versions, verify checksums, and use secure installation methods in production environments.
CI/CD Integration
For team-specific automation setups, see Team Setup Guide. For troubleshooting CI/CD issues, check our Troubleshooting Guide.
GitHub Actions
# .github/workflows/devex-setup.yml
name: Development Environment Setup
on:
push:
branches: [main, develop]
pull_request:
branches: [main]
jobs:
setup-environment:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install DevEx
run: |
# Install DevEx with version pinning for CI reproducibility
set -euo pipefail # Enable strict error handling
curl -fsSL https://devex.sh/install | bash
echo "$HOME/.local/share/devex/bin" >> $GITHUB_PATH
- name: Configure DevEx
run: |
set -euo pipefail
devex config init
devex config apply --file .devex/ci.yaml
- name: Install development tools
run: |
set -euo pipefail
devex install --category development --non-interactive
- name: Verify installation
run: |
set -euo pipefail
devex status
devex config validate
# Fail if any required tools are missing
devex install --dry-run --category developmentGitLab CI/CD
# .gitlab-ci.yml
stages:
- setup
- test
- deploy
variables:
DEVEX_VERSION: "latest"
DEVEX_CONFIG: ".devex/gitlab-ci.yaml"
.devex_setup: &devex_setup
before_script:
# Install DevEx with GitLab CI considerations
- curl -fsSL https://devex.sh/install | bash
- export PATH="$PATH:$HOME/.local/share/devex/bin"
- devex config apply --file $DEVEX_CONFIG
setup_environment:
stage: setup
<<: *devex_setup
script:
- devex install --category development --non-interactive
- devex status
artifacts:
reports:
junit: devex-report.xml
paths:
- ~/.local/share/devex/
expire_in: 1 hour
test_frontend:
stage: test
dependencies:
- setup_environment
<<: *devex_setup
script:
- devex config apply --file .devex/frontend.yaml
- npm ci
- npm test
only:
changes:
- frontend/**/*
test_backend:
stage: test
dependencies:
- setup_environment
<<: *devex_setup
script:
- devex config apply --file .devex/backend.yaml
- go mod download
- go test ./...
only:
changes:
- backend/**/*Jenkins Pipeline
// Jenkinsfile
pipeline {
agent any
environment {
DEVEX_HOME = "${env.HOME}/.local/share/devex"
PATH = "${env.PATH}:${DEVEX_HOME}/bin"
}
stages {
stage('Setup DevEx') {
steps {
script {
// Install DevEx if not present
sh '''
if [ ! -f ${DEVEX_HOME}/bin/devex ]; then
# Install DevEx for Jenkins pipeline
curl -fsSL https://devex.sh/install | bash
fi
'''
}
}
}
stage('Configure Environment') {
parallel {
stage('Development Tools') {
steps {
sh 'devex install --category development --non-interactive'
}
}
stage('Database Setup') {
steps {
sh 'devex install --category databases --non-interactive'
}
}
}
}
stage('Validate Setup') {
steps {
sh '''
devex status
devex config validate
devex security audit --format json > security-audit.json
'''
archiveArtifacts artifacts: 'security-audit.json'
}
}
stage('Run Tests') {
steps {
sh '''
# Tests now run in consistent environment
npm test
go test ./...
python -m pytest
'''
}
}
}
post {
always {
// Clean up resources
sh 'devex clean --cache --logs'
}
failure {
// Send notification with DevEx status
sh '''
devex report generate --format slack > devex-status.json
curl -X POST -H 'Content-type: application/json' \
--data @devex-status.json \
$SLACK_WEBHOOK_URL
'''
}
}
}Container Integration
Dockerfile Integration
# Dockerfile.dev
FROM ubuntu:22.04
# Install basic dependencies
RUN apt-get update && apt-get install -y \
curl \
wget \
sudo \
git \
&& rm -rf /var/lib/apt/lists/*
# Create development user
RUN useradd -m -s /bin/bash -G sudo developer
USER developer
WORKDIR /home/developer
# Install DevEx with security considerations
RUN curl -fsSL https://devex.sh/install | bash
ENV PATH="/home/developer/.local/share/devex/bin:${PATH}"
# Copy team configuration
COPY --chown=developer:developer .devex/ /home/developer/.devex/
# Install development environment
RUN devex install --non-interactive --category development
# Set up shell
RUN echo 'source ~/.local/share/devex/shell/setup.sh' >> ~/.bashrc
# Expose common ports
EXPOSE 3000 8000 8080 5000
CMD ["/bin/bash"]Docker Compose for Development
# docker-compose.dev.yml
version: '3.8'
services:
devex-environment:
build:
context: .
dockerfile: Dockerfile.dev
volumes:
- .:/workspace
- devex-cache:/home/developer/.devex/cache
- node-modules:/workspace/node_modules
ports:
- "3000:3000"
- "8000:8000"
environment:
- DEVEX_WORKSPACE=/workspace
- NODE_ENV=development
command: >
bash -c "
cd /workspace &&
devex config apply --file .devex/development.yaml &&
devex install --update &&
npm run dev
"
database:
image: postgres:14
environment:
POSTGRES_DB: devapp
POSTGRES_USER: developer
POSTGRES_PASSWORD: devpass
volumes:
- postgres-data:/var/lib/postgresql/data
ports:
- "5432:5432"
redis:
image: redis:7-alpine
ports:
- "6379:6379"
volumes:
devex-cache:
node-modules:
postgres-data:Infrastructure as Code
Terraform Integration
# terraform/devex-setup.tf
terraform {
required_providers {
devex = {
source = "jameswlane/devex"
version = "~> 1.0"
}
}
}
# Configure development workstations
resource "devex_configuration" "team_frontend" {
name = "frontend-team"
applications = [
{
name = "node"
version = "18.17.0"
install_method = "mise"
default = true
},
{
name = "vscode"
default = true
extensions = [
"ms-vscode.vscode-typescript-next",
"esbenp.prettier-vscode"
]
}
]
environment = {
NODE_ENV = "development"
API_URL = var.api_url
}
themes = {
name = "company-theme"
vscode_theme = "GitHub Dark"
}
}
# Apply configuration to development VMs
resource "devex_deployment" "dev_workstations" {
configuration_id = devex_configuration.team_frontend.id
targets = [
for vm in var.dev_vms : {
host = vm.ip_address
user = "developer"
ssh_key = file("~/.ssh/id_ed25519")
}
]
deployment_strategy = "rolling"
max_parallel = 3
}
# Output deployment status
output "deployment_status" {
value = devex_deployment.dev_workstations.status
}Ansible Integration
# ansible/devex-playbook.yml
---
- name: Setup Development Environment with DevEx
hosts: developers
become: yes
become_user: "{{ developer_user }}"
vars:
devex_version: "latest"
devex_config_repo: "https://github.com/company/devex-config.git"
tasks:
- name: Check if DevEx is installed
command: which devex
register: devex_check
failed_when: false
changed_when: false
- name: Install DevEx
shell: |
# Install DevEx via Ansible with error handling
curl -fsSL https://devex.sh/install | bash
when: devex_check.rc != 0
- name: Add DevEx to PATH
lineinfile:
path: "{{ ansible_env.HOME }}/.bashrc"
line: 'export PATH="$PATH:$HOME/.local/share/devex/bin"'
create: yes
when: devex_check.rc != 0
- name: Clone team configuration
git:
repo: "{{ devex_config_repo }}"
dest: "{{ ansible_env.HOME }}/.devex"
version: main
force: yes
- name: Apply team configuration
shell: |
export PATH="$PATH:{{ ansible_env.HOME }}/.local/share/devex/bin"
devex config validate
devex install --config {{ ansible_env.HOME }}/.devex/team.yaml --non-interactive
args:
executable: /bin/bash
- name: Configure Git
git_config:
name: "{{ item.name }}"
value: "{{ item.value }}"
scope: global
loop:
- { name: "user.name", value: "{{ git_user_name }}" }
- { name: "user.email", value: "{{ git_user_email }}" }
- { name: "core.editor", value: "code --wait" }
- name: Generate SSH key if needed
openssh_keypair:
path: "{{ ansible_env.HOME }}/.ssh/id_ed25519"
type: ed25519
comment: "{{ git_user_email }}"
state: present
register: ssh_key
- name: Display SSH public key
debug:
msg: "Add this SSH key to GitHub: {{ ssh_key.public_key }}"
when: ssh_key.changedKubernetes Integration
# k8s/devex-init-job.yaml
apiVersion: batch/v1
kind: Job
metadata:
name: devex-environment-setup
namespace: development
spec:
template:
spec:
containers:
- name: devex-setup
image: ubuntu:22.04
command: ["/bin/bash"]
args:
- -c
- |
# Install DevEx with security considerations
apt-get update && apt-get install -y curl ca-certificates
curl -fsSL https://devex.sh/install | bash
export PATH="$PATH:/root/.local/share/devex/bin"
# Apply configuration from ConfigMap
devex config apply --file /config/development.yaml
devex install --non-interactive
# Export environment for other containers
devex env export --format k8s > /shared/environment.yaml
volumeMounts:
- name: config-volume
mountPath: /config
- name: shared-volume
mountPath: /shared
volumes:
- name: config-volume
configMap:
name: devex-config
- name: shared-volume
emptyDir: {}
restartPolicy: OnFailure
---
apiVersion: v1
kind: ConfigMap
metadata:
name: devex-config
namespace: development
data:
development.yaml: |
applications:
development:
- name: kubectl
default: true
- name: helm
default: true
- name: skaffold
default: trueAutomation Scripts
Deployment Automation
#!/bin/bash
# scripts/deploy-production.sh
set -euo pipefail
# Configuration
ENVIRONMENT="production"
CONFIG_REPO="https://github.com/company/devex-production-config.git"
BACKUP_DIR="/backup/devex-$(date +%Y%m%d-%H%M%S)"
echo "🚀 Starting production deployment with DevEx..."
# Pre-deployment checks
echo "🔍 Running pre-deployment checks..."
devex config validate --strict
devex security audit --fail-on-issues
devex system check --requirements production
# Backup current configuration
echo "💾 Creating backup..."
mkdir -p "$BACKUP_DIR"
cp -r ~/.devex "$BACKUP_DIR/"
cp -r ~/.local/share/devex "$BACKUP_DIR/"
# Update to production configuration
echo "⚙️ Applying production configuration..."
git clone "$CONFIG_REPO" /tmp/prod-config
cp -r /tmp/prod-config/* ~/.devex/
# Dry run first
echo "🧪 Testing configuration (dry run)..."
devex install --dry-run --environment "$ENVIRONMENT"
# Prompt for confirmation
read -p "Deploy to production? (yes/no): " confirm
if [[ $confirm != "yes" ]]; then
echo "❌ Deployment cancelled"
exit 1
fi
# Deploy with rollback capability
echo "📦 Deploying applications..."
if ! devex install --environment "$ENVIRONMENT" --timeout 30m; then
echo "❌ Deployment failed, rolling back..."
cp -r "$BACKUP_DIR/.devex" ~/
cp -r "$BACKUP_DIR/devex" ~/.local/share/
devex install --rollback
exit 1
fi
# Post-deployment verification
echo "✅ Verifying deployment..."
devex status --detailed
devex test --suite production
# Notify team
echo "📢 Notifying team..."
devex notify slack "Production environment updated successfully"
echo "🎉 Production deployment complete!"Monitoring and Alerting
Environment Monitoring
#!/bin/bash
# scripts/monitor-environments.sh
# Monitor development environments across the team
WEBHOOK_URL="${SLACK_WEBHOOK_URL}"
ALERT_THRESHOLD=80
echo "📊 Monitoring team development environments..."
# Collect environment data
devex report generate \
--team \
--format json \
--output /tmp/team-report.json
# Check for issues
ISSUES=$(devex report analyze \
--file /tmp/team-report.json \
--threshold "$ALERT_THRESHOLD" \
--format count)
if [[ "$ISSUES" -gt 0 ]]; then
echo "⚠️ Found $ISSUES environment issues"
# Generate detailed report
devex report analyze \
--file /tmp/team-report.json \
--format detailed \
--output /tmp/issues-report.txt
# Send alert
curl -X POST -H 'Content-type: application/json' \
--data "{
\"text\": \"🚨 DevEx Alert: $ISSUES environment issues detected\",
\"attachments\": [{
\"color\": \"warning\",
\"text\": \"$(cat /tmp/issues-report.txt)\"
}]
}" \
"$WEBHOOK_URL"
fi
# Generate daily metrics
devex metrics collect \
--team \
--period daily \
--output /var/log/devex/metrics-$(date +%Y%m%d).jsonPerformance Monitoring
# monitoring/devex-monitoring.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: devex-monitoring
data:
monitor.sh: |
#!/bin/bash
while true; do
# Collect metrics
devex metrics collect --json > /tmp/metrics.json
# Check resource usage
CPU=$(devex system cpu-usage)
MEMORY=$(devex system memory-usage)
DISK=$(devex system disk-usage)
# Send to monitoring system
curl -X POST http://prometheus:9090/metrics \
-H "Content-Type: application/json" \
-d @/tmp/metrics.json
sleep 300 # 5 minutes
done
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: devex-monitor
spec:
selector:
matchLabels:
app: devex-monitor
template:
metadata:
labels:
app: devex-monitor
spec:
containers:
- name: monitor
image: devex:latest
command: ["/bin/bash", "/config/monitor.sh"]
volumeMounts:
- name: config
mountPath: /config
volumes:
- name: config
configMap:
name: devex-monitoringBest Practices for Automation
DevEx Automation Best Practices:
- Idempotent Operations: Ensure scripts can run multiple times safely
- Error Handling: Implement comprehensive error handling and rollback
- Logging: Log all operations for debugging and auditing
- Validation: Always validate configurations before applying
- Testing: Test automation scripts in staging environments
- Monitoring: Monitor automated deployments and environments
- Security: Secure credentials and validate inputs
- Documentation: Document automation processes and procedures
Automation Testing
#!/bin/bash
# scripts/test-automation.sh
echo "🧪 Testing DevEx automation..."
# Test configuration validation
echo "Testing configuration validation..."
devex config validate --all --strict
# Test dry-run installations
echo "Testing dry-run installations..."
devex install --dry-run --all
# Test rollback capability
echo "Testing rollback capability..."
devex backup create test-backup
devex install test-application
devex rollback test-backup
devex backup delete test-backup
# Test error handling
echo "Testing error handling..."
devex install non-existent-application 2>/dev/null && {
echo "❌ Error handling test failed"
exit 1
} || echo "✅ Error handling test passed"
# Test parallel installations
echo "Testing parallel installations..."
time devex install --category test-tools --parallel
echo "✅ All automation tests passed!"