Free 40-page Claude guide — setup, 120 prompt codes, MCP servers, AI agents. Download free →
CLSkills
DevOps & CI/CDintermediate

Deploy Script

Share

Create deployment scripts for various platforms

Works with OpenClaude

You are a DevOps automation engineer. The user wants to create reusable deployment scripts for multiple platforms (AWS, Docker, Kubernetes, traditional servers).

What to check first

  • Verify target platform credentials are configured (aws configure, kubectl config view, Docker daemon running)
  • Check if deployment target environment variables exist (.env file or system exports for API keys, registry URLs, image names)
  • Confirm deployment artifact exists (built Docker image, compiled binary, or packaged application)

Steps

  1. Define deployment configuration using environment variables and a .env.example file for reference
  2. Create platform-specific deployment functions (AWS, Docker, Kubernetes, SSH-based)
  3. Implement pre-deployment health checks (connectivity, permissions, service availability)
  4. Add rollback logic that captures previous state before applying changes
  5. Implement logging and error handling with timestamps and exit codes
  6. Create idempotent operations so re-running the script is safe
  7. Add deployment verification steps (health checks, endpoint tests, log inspection)
  8. Package the script with a Makefile or wrapper for easy invocation

Code

#!/bin/bash
set -euo pipefail

# Configuration
DEPLOYMENT_ENV="${DEPLOYMENT_ENV:-staging}"
DEPLOYMENT_LOG="/var/log/deployment-$(date +%Y%m%d-%H%M%S).log"
BACKUP_DIR="/opt/backups"
ROLLBACK_SNAPSHOT=""

# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'

log() {
  echo -e "${GREEN}[$(date +'%Y-%m-%d %H:%M:%S')]${NC} $*" | tee -a "$DEPLOYMENT_LOG"
}

error() {
  echo -e "${RED}[ERROR]${NC} $*" | tee -a "$DEPLOYMENT_LOG"
  exit 1
}

warn() {
  echo -e "${YELLOW}[WARN]${NC} $*" | tee -a "$DEPLOYMENT_LOG"
}

# Pre-deployment checks
pre_deployment_checks() {
  log "Running pre-deployment checks..."
  
  if [[ -z "${DOCKER_IMAGE:-}" ]]; then
    error "DOCKER_IMAGE environment variable not set"
  fi
  
  if ! command -v docker &> /dev/null; then
    error "Docker is not installed or not in PATH"
  fi
  
  if ! docker ps &> /dev/null; then
    error "Cannot connect to Docker daemon"
  fi
  
  log "Pre-deployment checks passed"
}

# Deploy to Kubernetes
deploy_kubernetes() {
  local app_name="$1"
  local image="$2"
  local replicas="${3:-3}"
  
  log "Deploying $app_name to Kubernetes cluster..."

Note: this example was truncated in the source. See the GitHub repo for the latest full version.

Common Pitfalls

  • Treating this skill as a one-shot solution — most workflows need iteration and verification
  • Skipping the verification steps — you don't know it worked until you measure
  • Applying this skill without understanding the underlying problem — read the related docs first

When NOT to Use This Skill

  • When a simpler manual approach would take less than 10 minutes
  • On critical production systems without testing in staging first
  • When you don't have permission or authorization to make these changes

How to Verify It Worked

  • Run the verification steps documented above
  • Compare the output against your expected baseline
  • Check logs for any warnings or errors — silent failures are the worst kind

Production Considerations

  • Test in staging before deploying to production
  • Have a rollback plan — every change should be reversible
  • Monitor the affected systems for at least 24 hours after the change

Quick Info

Difficultyintermediate
Version1.0.0
AuthorClaude Skills Hub
devopsdeploymentautomation

Install command:

curl -o ~/.claude/skills/deploy-script.md https://claude-skills-hub.vercel.app/skills/devops/deploy-script.md

Related DevOps & CI/CD Skills

Other Claude Code skills in the same category — free to download.

Want a DevOps & CI/CD skill personalized to YOUR project?

This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.