kdeploy 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +101 -936
- data/exe/kdeploy +6 -0
- data/k.md +149 -0
- data/lib/kdeploy/banner.rb +44 -14
- data/lib/kdeploy/cli.rb +138 -1389
- data/lib/kdeploy/dsl.rb +66 -530
- data/lib/kdeploy/executor.rb +73 -0
- data/lib/kdeploy/initializer.rb +229 -0
- data/lib/kdeploy/runner.rb +40 -180
- data/lib/kdeploy/template.rb +18 -161
- data/lib/kdeploy/version.rb +1 -2
- data/lib/kdeploy.rb +9 -100
- metadata +75 -52
- data/.editorconfig +0 -12
- data/.rspec +0 -3
- data/.rubocop.yml +0 -100
- data/LICENSE +0 -21
- data/Rakefile +0 -45
- data/bin/kdeploy +0 -7
- data/kdeploy.gemspec +0 -49
- data/lib/kdeploy/command.rb +0 -182
- data/lib/kdeploy/configuration.rb +0 -83
- data/lib/kdeploy/host.rb +0 -85
- data/lib/kdeploy/inventory.rb +0 -243
- data/lib/kdeploy/logger.rb +0 -100
- data/lib/kdeploy/pipeline.rb +0 -249
- data/lib/kdeploy/ssh_connection.rb +0 -187
- data/lib/kdeploy/statistics.rb +0 -439
- data/lib/kdeploy/task.rb +0 -240
- data/scripts/common_tasks.rb +0 -218
- data/scripts/deploy.rb +0 -50
data/scripts/common_tasks.rb
DELETED
@@ -1,218 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Common tasks for kdeploy projects
|
4
|
-
# This file demonstrates modular script organization
|
5
|
-
#
|
6
|
-
# To use this file, include it in your main deployment script:
|
7
|
-
# include 'scripts/common_tasks.rb' if File.exist?('scripts/common_tasks.rb')
|
8
|
-
|
9
|
-
# ===================================================================
|
10
|
-
# HOST DEFINITIONS (Required for remote tasks)
|
11
|
-
# ===================================================================
|
12
|
-
|
13
|
-
# Define default hosts - update these with your actual hosts
|
14
|
-
host 'localhost', user: ENV.fetch('USER', 'deploy'), port: 22, roles: %i[web app db all]
|
15
|
-
|
16
|
-
# Uncomment and update these for real deployments:
|
17
|
-
# host 'web1.example.com', user: 'deploy', port: 22, roles: [:web, :app]
|
18
|
-
# host 'web2.example.com', user: 'deploy', port: 22, roles: [:web, :app]
|
19
|
-
# host 'db1.example.com', user: 'deploy', port: 22, roles: [:db]
|
20
|
-
|
21
|
-
# ===================================================================
|
22
|
-
# COMMON UTILITY TASKS
|
23
|
-
# ===================================================================
|
24
|
-
|
25
|
-
# Shared pre-deployment checks (LOCAL + REMOTE)
|
26
|
-
task 'pre_deploy_checks', on: :all do
|
27
|
-
local 'echo "🔍 Running pre-deployment checks..."'
|
28
|
-
local 'echo "Current user: $(whoami)"'
|
29
|
-
local 'echo "Current directory: $(pwd)"'
|
30
|
-
local 'echo "Git status:" && git status --porcelain || echo "Not a git repository"'
|
31
|
-
local 'echo "✅ Pre-deployment checks completed"'
|
32
|
-
|
33
|
-
# Add a dummy remote command to satisfy validation
|
34
|
-
run 'echo "Pre-deployment check completed on {{hostname}}"'
|
35
|
-
end
|
36
|
-
|
37
|
-
# Common environment setup
|
38
|
-
task 'setup_environment', on: :all do
|
39
|
-
run 'echo "Setting up environment on {{hostname}}..."'
|
40
|
-
|
41
|
-
# Set timezone
|
42
|
-
run 'sudo timedatectl set-timezone UTC', ignore_errors: true
|
43
|
-
|
44
|
-
# Update system packages
|
45
|
-
run 'sudo apt-get update -qq', ignore_errors: true
|
46
|
-
|
47
|
-
# Install common utilities
|
48
|
-
run 'sudo apt-get install -y -qq htop curl wget vim git unzip', ignore_errors: true
|
49
|
-
|
50
|
-
run 'echo "✅ Environment setup completed on {{hostname}}"'
|
51
|
-
end
|
52
|
-
|
53
|
-
# Common log rotation setup
|
54
|
-
task 'setup_log_rotation', on: :all do
|
55
|
-
run 'echo "Setting up log rotation on {{hostname}}..."'
|
56
|
-
|
57
|
-
# Application log rotation
|
58
|
-
run <<~LOGROTATE
|
59
|
-
sudo tee /etc/logrotate.d/{{application}} > /dev/null << 'EOF'
|
60
|
-
{{deploy_to}}/shared/logs/*.log {
|
61
|
-
daily
|
62
|
-
missingok
|
63
|
-
rotate 52
|
64
|
-
compress
|
65
|
-
delaycompress
|
66
|
-
notifempty
|
67
|
-
create 644 {{user}} {{user}}
|
68
|
-
postrotate
|
69
|
-
sudo systemctl reload {{application}} || true
|
70
|
-
endscript
|
71
|
-
}
|
72
|
-
EOF
|
73
|
-
LOGROTATE
|
74
|
-
|
75
|
-
run 'echo "✅ Log rotation setup completed on {{hostname}}"'
|
76
|
-
end
|
77
|
-
|
78
|
-
# Common system monitoring setup
|
79
|
-
task 'setup_monitoring', on: :all do
|
80
|
-
run 'echo "Setting up basic monitoring on {{hostname}}..."'
|
81
|
-
|
82
|
-
# Install system monitoring tools
|
83
|
-
run 'sudo apt-get install -y htop iotop iftop nethogs', ignore_errors: true
|
84
|
-
|
85
|
-
# Setup basic disk space monitoring
|
86
|
-
run <<~MONITORING
|
87
|
-
sudo tee /usr/local/bin/disk-alert.sh > /dev/null << 'EOF'
|
88
|
-
#!/bin/bash
|
89
|
-
THRESHOLD=90
|
90
|
-
USAGE=$(df / | awk 'NR==2 {print $5}' | sed 's/%//')
|
91
|
-
if [ $USAGE -gt $THRESHOLD ]; then
|
92
|
-
echo "Warning: Disk usage is $USAGE% on $(hostname)"
|
93
|
-
logger "Disk usage alert: $USAGE% on $(hostname)"
|
94
|
-
fi
|
95
|
-
EOF
|
96
|
-
MONITORING
|
97
|
-
|
98
|
-
run 'sudo chmod +x /usr/local/bin/disk-alert.sh'
|
99
|
-
|
100
|
-
# Add to crontab
|
101
|
-
run 'echo "0 */6 * * * /usr/local/bin/disk-alert.sh" | sudo crontab -', ignore_errors: true
|
102
|
-
|
103
|
-
run 'echo "✅ Monitoring setup completed on {{hostname}}"'
|
104
|
-
end
|
105
|
-
|
106
|
-
# Common security hardening
|
107
|
-
task 'security_hardening', on: :all do
|
108
|
-
run 'echo "Applying security hardening on {{hostname}}..."'
|
109
|
-
|
110
|
-
# Disable root login
|
111
|
-
run 'sudo sed -i "s/PermitRootLogin yes/PermitRootLogin no/" /etc/ssh/sshd_config', ignore_errors: true
|
112
|
-
|
113
|
-
# Configure firewall basics
|
114
|
-
run 'sudo ufw --force reset', ignore_errors: true
|
115
|
-
run 'sudo ufw default deny incoming', ignore_errors: true
|
116
|
-
run 'sudo ufw default allow outgoing', ignore_errors: true
|
117
|
-
run 'sudo ufw allow ssh', ignore_errors: true
|
118
|
-
run 'sudo ufw allow 80', ignore_errors: true
|
119
|
-
run 'sudo ufw allow 443', ignore_errors: true
|
120
|
-
run 'sudo ufw --force enable', ignore_errors: true
|
121
|
-
|
122
|
-
# Install fail2ban
|
123
|
-
run 'sudo apt-get install -y fail2ban', ignore_errors: true
|
124
|
-
run 'sudo systemctl enable fail2ban', ignore_errors: true
|
125
|
-
run 'sudo systemctl start fail2ban', ignore_errors: true
|
126
|
-
|
127
|
-
run 'echo "✅ Security hardening completed on {{hostname}}"'
|
128
|
-
end
|
129
|
-
|
130
|
-
# Common performance tuning
|
131
|
-
task 'performance_tuning', on: :all do
|
132
|
-
run 'echo "Applying performance tuning on {{hostname}}..."'
|
133
|
-
|
134
|
-
# System limits
|
135
|
-
run <<~LIMITS
|
136
|
-
sudo tee -a /etc/security/limits.conf > /dev/null << 'EOF'
|
137
|
-
* soft nofile 65536
|
138
|
-
* hard nofile 65536
|
139
|
-
* soft nproc 32768
|
140
|
-
* hard nproc 32768
|
141
|
-
EOF
|
142
|
-
LIMITS
|
143
|
-
|
144
|
-
# Kernel parameters
|
145
|
-
run <<~SYSCTL
|
146
|
-
sudo tee -a /etc/sysctl.conf > /dev/null << 'EOF'
|
147
|
-
# Network performance
|
148
|
-
net.core.rmem_max = 16777216
|
149
|
-
net.core.wmem_max = 16777216
|
150
|
-
net.ipv4.tcp_rmem = 4096 65536 16777216
|
151
|
-
net.ipv4.tcp_wmem = 4096 65536 16777216
|
152
|
-
EOF
|
153
|
-
SYSCTL
|
154
|
-
|
155
|
-
run 'sudo sysctl -p', ignore_errors: true
|
156
|
-
|
157
|
-
run 'echo "✅ Performance tuning completed on {{hostname}}"'
|
158
|
-
end
|
159
|
-
|
160
|
-
# ===================================================================
|
161
|
-
# COMMON UTILITY FUNCTIONS
|
162
|
-
# ===================================================================
|
163
|
-
|
164
|
-
# Health check wrapper (LOCAL + REMOTE)
|
165
|
-
task 'health_check_all', on: :all do
|
166
|
-
local 'echo "🏥 Running comprehensive health checks..."'
|
167
|
-
|
168
|
-
# You can call other scripts from here
|
169
|
-
local 'echo "1. System health check"'
|
170
|
-
local 'echo "2. Application health check"'
|
171
|
-
local 'echo "3. Service status check"'
|
172
|
-
local 'echo "✅ Health checks completed"'
|
173
|
-
|
174
|
-
# Add a dummy remote command to satisfy validation
|
175
|
-
run 'echo "Health check completed on {{hostname}}"'
|
176
|
-
end
|
177
|
-
|
178
|
-
# ===================================================================
|
179
|
-
# EMERGENCY PROCEDURES
|
180
|
-
# ===================================================================
|
181
|
-
|
182
|
-
# Emergency stop all services
|
183
|
-
task 'emergency_stop', on: :all do
|
184
|
-
run 'echo "🚨 Emergency stop initiated on {{hostname}}"'
|
185
|
-
run 'sudo systemctl stop nginx || echo "nginx not found"', ignore_errors: true
|
186
|
-
run 'sudo systemctl stop apache2 || echo "apache2 not found"', ignore_errors: true
|
187
|
-
run 'echo "🛑 Services stopped on {{hostname}}"'
|
188
|
-
end
|
189
|
-
|
190
|
-
# Emergency start all services
|
191
|
-
task 'emergency_start', on: :all do
|
192
|
-
run 'echo "🚨 Emergency start initiated on {{hostname}}"'
|
193
|
-
run 'sudo systemctl start nginx || echo "nginx not found"', ignore_errors: true
|
194
|
-
run 'sudo systemctl start apache2 || echo "apache2 not found"', ignore_errors: true
|
195
|
-
run 'echo "🚀 Services started on {{hostname}}"'
|
196
|
-
end
|
197
|
-
|
198
|
-
# ===================================================================
|
199
|
-
# USAGE EXAMPLES
|
200
|
-
# ===================================================================
|
201
|
-
#
|
202
|
-
# This file can be included in your main deploy.rb script:
|
203
|
-
#
|
204
|
-
# include 'scripts/common_tasks.rb' if File.exist?('scripts/common_tasks.rb')
|
205
|
-
#
|
206
|
-
# Then you can call these tasks from your deployment workflow:
|
207
|
-
#
|
208
|
-
# task 'full_setup' do
|
209
|
-
# run_task 'pre_deploy_checks'
|
210
|
-
# run_task 'setup_environment'
|
211
|
-
# run_task 'security_hardening'
|
212
|
-
# run_task 'performance_tuning'
|
213
|
-
# end
|
214
|
-
#
|
215
|
-
# Or run individual tasks:
|
216
|
-
# kdeploy deploy scripts/common_tasks.rb --task setup_environment
|
217
|
-
# kdeploy deploy scripts/common_tasks.rb --task security_hardening
|
218
|
-
# kdeploy deploy scripts/common_tasks.rb --task emergency_stop
|
data/scripts/deploy.rb
DELETED
@@ -1,50 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# Simple kdeploy test deployment script - only using local commands
|
4
|
-
|
5
|
-
# Set global variables
|
6
|
-
set 'application', 'myapp'
|
7
|
-
set 'hostname', 'localhost'
|
8
|
-
set 'version', '1.0.0'
|
9
|
-
|
10
|
-
# All commands are executed locally, no SSH required
|
11
|
-
local 'echo "=== Starting kdeploy deployment process ==="'
|
12
|
-
local 'echo "Application: {{application}}"'
|
13
|
-
local 'echo "Version: {{version}}"'
|
14
|
-
local 'echo "Target: {{hostname}}"'
|
15
|
-
local 'echo "Current user: $(whoami)"'
|
16
|
-
local 'echo "Current date: $(date)"'
|
17
|
-
|
18
|
-
local 'echo "=== Preparation Phase ==="'
|
19
|
-
local 'echo "Preparing deployment environment..."'
|
20
|
-
local 'mkdir -p /tmp/kdeploy-test'
|
21
|
-
local 'echo "Environment prepared!"'
|
22
|
-
|
23
|
-
local 'echo "=== Build Phase ==="'
|
24
|
-
local 'echo "Building application..."'
|
25
|
-
local 'sleep 1'
|
26
|
-
local 'echo "Build completed successfully!"'
|
27
|
-
|
28
|
-
local 'echo "=== Testing Phase ==="'
|
29
|
-
local 'echo "Running tests..."'
|
30
|
-
local 'echo "Test 1: Basic functionality... PASSED"'
|
31
|
-
local 'echo "Test 2: Integration tests... PASSED"'
|
32
|
-
local 'echo "All tests passed!"'
|
33
|
-
|
34
|
-
local 'echo "=== Deployment Phase ==="'
|
35
|
-
local 'echo "Deploying to {{hostname}}..."'
|
36
|
-
local 'echo "{{application}} {{version}}" > /tmp/kdeploy-test/version.txt'
|
37
|
-
local 'echo "Application deployed to /tmp/kdeploy-test/"'
|
38
|
-
|
39
|
-
local 'echo "=== Verification Phase ==="'
|
40
|
-
local 'echo "Verifying deployment..."'
|
41
|
-
local 'cat /tmp/kdeploy-test/version.txt'
|
42
|
-
local 'echo "Deployment verification completed!"'
|
43
|
-
|
44
|
-
local 'echo "=== Cleanup Phase ==="'
|
45
|
-
local 'echo "Cleaning up temporary files..."'
|
46
|
-
local 'rm -rf /tmp/kdeploy-test'
|
47
|
-
local 'echo "Cleanup completed!"'
|
48
|
-
|
49
|
-
local 'echo "=== Deployment Complete ==="'
|
50
|
-
local 'echo "{{application}} {{version}} successfully deployed!"'
|