File contents 4. Bash Scripts
4. Bash Scripts
#!/bin/bash
# scripts/devops/deploy_service.sh
# Deploy a service with health checks and rollback capability.
# Windmill automatically provides these as environment variables
# SERVICE_NAME, VERSION, ENVIRONMENT, DRY_RUN
set -euo pipefail
# Get secrets from Windmill resources
DEPLOY_KEY=$(curl -s -H "Authorization: Bearer $WM_TOKEN" \
"$BASE_INTERNAL_URL/api/w/$WM_WORKSPACE/resources/get/u/admin/deploy_key" | jq -r '.value.key')
AWS_REGION=$(curl -s -H "Authorization: Bearer $WM_TOKEN" \
"$BASE_INTERNAL_URL/api/w/$WM_WORKSPACE/resources/get/u/admin/aws_config" | jq -r '.value.region')
log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1"
}
deploy_service() {
local service=$1
local version=$2
local env=$3
log "Deploying $service version $version to $env"
# Update ECS service
if [[ "$DRY_RUN" == "true" ]]; then
log "[DRY RUN] Would update ECS service $service to $version"
return 0
fi
aws ecs update-service \
--cluster "${env}-cluster" \
--service "$service" \
--force-new-deployment \
--region "$AWS_REGION"
log "Deployment initiated"
}
wait_for_healthy() {
local service=$1
local env=$2
local max_wait=300
local interval=10
local elapsed=0
log "Waiting for $service to become healthy..."
while [[ $elapsed -lt $max_wait ]]; do
local running_count=$(aws ecs describe-services \
--cluster "${env}-cluster" \
--services "$service" \
--region "$AWS_REGION" \
--query 'services[0].runningCount' \
--output text)
local desired_count=$(aws ecs describe-services \
--cluster "${env}-cluster" \
--services "$service" \
--region "$AWS_REGION" \
--query 'services[0].desiredCount' \
--output text)
if [[ "$running_count" == "$desired_count" ]]; then
log "Service healthy: $running_count/$desired_count tasks running"
return 0
fi
log "Waiting... ($running_count/$desired_count tasks running)"
sleep $interval
elapsed=$((elapsed + interval))
done
log "ERROR: Service did not become healthy within ${max_wait}s"
return 1
}
rollback() {
local service=$1
local env=$2
log "Rolling back $service in $env"
# Get previous task definition
local prev_task_def=$(aws ecs describe-services \
--cluster "${env}-cluster" \
--services "$service" \
--region "$AWS_REGION" \
--query 'services[0].deployments[1].taskDefinition' \
--output text)
if [[ -z "$prev_task_def" || "$prev_task_def" == "None" ]]; then
log "ERROR: No previous task definition found for rollback"
return 1
fi
aws ecs update-service \
--cluster "${env}-cluster" \
--service "$service" \
--task-definition "$prev_task_def" \
--region "$AWS_REGION"
log "Rollback initiated to $prev_task_def"
}
# Main execution
main() {
log "=== Deployment Started ==="
log "Service: $SERVICE_NAME"
log "Version: $VERSION"
log "Environment: $ENVIRONMENT"
log "Dry Run: $DRY_RUN"
# Deploy
if ! deploy_service "$SERVICE_NAME" "$VERSION" "$ENVIRONMENT"; then
log "ERROR: Deployment failed"
exit 1
fi
# Wait for health (skip in dry run)
if [[ "$DRY_RUN" != "true" ]]; then
if ! wait_for_healthy "$SERVICE_NAME" "$ENVIRONMENT"; then
log "Deployment failed health check, initiating rollback"
rollback "$SERVICE_NAME" "$ENVIRONMENT"
exit 1
fi
fi
log "=== Deployment Completed Successfully ==="
# Output result as JSON for Windmill
cat <<EOF
{
"status": "success",
"service": "$SERVICE_NAME",
"version": "$VERSION",
"environment": "$ENVIRONMENT",
"timestamp": "$(date -u +%Y-%m-%dT%H:%M:%SZ)"
}
EOF
}
main
1 --- 2 name: windmill-4-bash-scripts 3 description: Sub-skill of windmill: 4. Bash Scripts. 4 --- 5 6 # 4. Bash Scripts 7 8 ## 4. Bash Scripts 9 10 11 ```bash 12 #!/bin/bash 13 # scripts/devops/deploy_service.sh 14 # Deploy a service with health checks and rollback capability. 15 16 # Windmill automatically provides these as environment variables 17 # SERVICE_NAME, VERSION, ENVIRONMENT, DRY_RUN 18 19 set -euo pipefail 20 21 # Get secrets from Windmill resources 22 DEPLOY_KEY=$(curl -s -H "Authorization: Bearer $WM_TOKEN" \ 23 "$BASE_INTERNAL_URL/api/w/$WM_WORKSPACE/resources/get/u/admin/deploy_key" | jq -r '.value.key') 24 25 AWS_REGION=$(curl -s -H "Authorization: Bearer $WM_TOKEN" \ 26 "$BASE_INTERNAL_URL/api/w/$WM_WORKSPACE/resources/get/u/admin/aws_config" | jq -r '.value.region') 27 28 log() { 29 echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" 30 } 31 32 deploy_service() { 33 local service=$1 34 local version=$2 35 local env=$3 36 37 log "Deploying $service version $version to $env" 38 39 # Update ECS service 40 if [[ "$DRY_RUN" == "true" ]]; then 41 log "[DRY RUN] Would update ECS service $service to $version" 42 return 0 43 fi 44 45 aws ecs update-service \ 46 --cluster "${env}-cluster" \ 47 --service "$service" \ 48 --force-new-deployment \ 49 --region "$AWS_REGION" 50 51 log "Deployment initiated" 52 } 53 54 wait_for_healthy() { 55 local service=$1 56 local env=$2 57 local max_wait=300 58 local interval=10 59 local elapsed=0 60 61 log "Waiting for $service to become healthy..." 62 63 while [[ $elapsed -lt $max_wait ]]; do 64 local running_count=$(aws ecs describe-services \ 65 --cluster "${env}-cluster" \ 66 --services "$service" \ 67 --region "$AWS_REGION" \ 68 --query 'services[0].runningCount' \ 69 --output text) 70 71 local desired_count=$(aws ecs describe-services \ 72 --cluster "${env}-cluster" \ 73 --services "$service" \ 74 --region "$AWS_REGION" \ 75 --query 'services[0].desiredCount' \ 76 --output text) 77 78 if [[ "$running_count" == "$desired_count" ]]; then 79 log "Service healthy: $running_count/$desired_count tasks running" 80 return 0 81 fi 82 83 log "Waiting... ($running_count/$desired_count tasks running)" 84 sleep $interval 85 elapsed=$((elapsed + interval)) 86 done 87 88 log "ERROR: Service did not become healthy within ${max_wait}s" 89 return 1 90 } 91 92 rollback() { 93 local service=$1 94 local env=$2 95 96 log "Rolling back $service in $env" 97 98 # Get previous task definition 99 local prev_task_def=$(aws ecs describe-services \ 100 --cluster "${env}-cluster" \ 101 --services "$service" \ 102 --region "$AWS_REGION" \ 103 --query 'services[0].deployments[1].taskDefinition' \ 104 --output text) 105 106 if [[ -z "$prev_task_def" || "$prev_task_def" == "None" ]]; then 107 log "ERROR: No previous task definition found for rollback" 108 return 1 109 fi 110 111 aws ecs update-service \ 112 --cluster "${env}-cluster" \ 113 --service "$service" \ 114 --task-definition "$prev_task_def" \ 115 --region "$AWS_REGION" 116 117 log "Rollback initiated to $prev_task_def" 118 } 119 120 # Main execution 121 main() { 122 log "=== Deployment Started ===" 123 log "Service: $SERVICE_NAME" 124 log "Version: $VERSION" 125 log "Environment: $ENVIRONMENT" 126 log "Dry Run: $DRY_RUN" 127 128 # Deploy 129 if ! deploy_service "$SERVICE_NAME" "$VERSION" "$ENVIRONMENT"; then 130 log "ERROR: Deployment failed" 131 exit 1 132 fi 133 134 # Wait for health (skip in dry run) 135 if [[ "$DRY_RUN" != "true" ]]; then 136 if ! wait_for_healthy "$SERVICE_NAME" "$ENVIRONMENT"; then 137 log "Deployment failed health check, initiating rollback" 138 rollback "$SERVICE_NAME" "$ENVIRONMENT" 139 exit 1 140 fi 141 fi 142 143 log "=== Deployment Completed Successfully ===" 144 145 # Output result as JSON for Windmill 146 cat <<EOF 147 { 148 "status": "success", 149 "service": "$SERVICE_NAME", 150 "version": "$VERSION", 151 "environment": "$ENVIRONMENT", 152 "timestamp": "$(date -u +%Y-%m-%dT%H:%M:%SZ)" 153 } 154 EOF 155 } 156 157 main 158 ```
vamseeachanta/workspace-hub/tree/main/.agents/skills/_archive/operations/automation/windmill/4-bash-scripts commit 61994d7619
Frequently asked questions How do I install the Windmill 4 Bash Scripts skill? Run npx skillmds@latest add vamseeachanta/windmill-4-bash-scripts in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
What does the Windmill 4 Bash Scripts skill do? Sub-skill of windmill: 4. Bash Scripts. It is listed under Coding & Dev Tools on SkillMD.
Is Windmill 4 Bash Scripts safe to use? This skill has not completed SkillMD's automated safety review yet. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
Which AI agents work with Windmill 4 Bash Scripts? This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Is Windmill 4 Bash Scripts free to use? Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
Who published Windmill 4 Bash Scripts? vamseeachanta (@vamseeachanta) published this skill. Their other Agent Skills are listed on their SkillMD profile.