-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
90 lines (77 loc) · 2.11 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
require 'sshkit'
require 'sshkit/dsl'
include SSHKit::DSL
DEPLOYED_NODES = ["159.203.206.61", "159.203.206.63", "159.203.206.49"].map do |ip|
SSHKit::Host.new("root@#{ip}")
end
def stop_container
execute "docker ps -ql | xargs docker stop"
end
def pull_image
execute "docker pull worace/clarke-coin:latest"
end
def start_container
execute "docker run -d -v /var/lib/clarke-coin:/var/lib/clarke-coin -p 3000-3000:3000-3000 worace/clarke-coin:latest"
end
def docker_cleanup
execute "docker rm -v $(docker ps --filter status=exited -q 2>/dev/null) 2>/dev/null"
execute "docker rmi $(docker images --filter dangling=true -q 2>/dev/null) 2>/dev/null"
end
def docker_command
if RUBY_PLATFORM.include?("darwin")
"docker"
else
"sudo docker"
end
end
desc "Shutdown docker containers on miner nodes"
task :stop do
on DEPLOYED_NODES do |host|
puts "Stopping miner on node #{host}"
stop_container
end
end
desc "Start docker containers on miner nodes"
task :start do
on DEPLOYED_NODES do |host|
puts "Starting miner on node #{host}"
start_container
end
end
desc "Delete unused docker images and containers on miner nodes"
task :docker_cleanup do
on DEPLOYED_NODES do |host|
puts "Removing old docker images on host #{host}"
docker_cleanup
end
end
desc "Wipe wallets on miner nodes"
task :wipe_wallets do
on DEPLOYED_NODES do |host|
puts "Stopping miner on node #{host}"
execute "rm -rf /var/lib/clarke-coin/wallets"
end
end
desc "Delete DBs on miner nodes"
task :wipe_dbs do
on DEPLOYED_NODES do |host|
puts "Wiping DB on node #{host}"
execute "rm -rf /var/lib/clarke-coin/db"
end
end
desc "Rebuild the docker image and push it to dockerhub"
task :docker_push do
puts "Building and pushing docker image..."
sh "#{docker_command} build -t worace/clarke-coin ."
sh "#{docker_command} push worace/clarke-coin:latest"
end
desc "Pull the latest docker image to each server and run it"
task :deploy => [:docker_push] do
on DEPLOYED_NODES do |host|
puts "Deploying to node #{host}"
pull_image
stop_container
docker_cleanup
start_container
end
end