-
Notifications
You must be signed in to change notification settings - Fork 18
/
Rakefile
94 lines (74 loc) · 2.14 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
91
92
93
94
task default: %w[deploy]
desc "Deploys IoT Event Streaming Architecture and launches all services and daemons needed to properly work"
task :deploy => [
:cleaning_environment_task,
:start,
:status] do
puts "Deploying services..."
end
desc "UnDeploy IoT Event Streaming Architecture"
task :undeploy => [:status] do
puts "Undeploy Services"
puts `docker-compose down -v 2>&1`
end
desc "Start Containers"
task :start => [ :check_docker_task, :login, :check_deployment_file_task ] do
puts "Start Containers"
puts `docker-compose up -d`
end
desc "Stop Containers"
task :stop => [ :check_docker_task ] do
puts "Stop Containers"
puts `docker-compose stop 2>&1`
puts `docker-compose rm -f 2>&1`
end
desc "Status Containers"
task :status do
puts "Show Containers Status"
puts `docker-compose ps 2>&1`
end
desc "Cleaning Evironment Task"
task :cleaning_environment_task do
puts "Cleaning Environment"
puts `docker image prune -af`
puts `docker volume prune -f 2>&1`
end
desc "Check Docker and Docker Compose Task"
task :check_docker_task do
puts "Check Docker and Docker Compose ..."
if which('docker') && which('docker-compose')
show_docker_version
show_docker_compose_version
else
raise "Please check that Docker and Docker Compose are visible and accessible in the PATH"
end
end
desc "Authenticating with existing credentials"
task :login do
puts `docker login 2>&1`
end
desc "Check Deployment File"
task :check_deployment_file_task do
puts "Check Deployment File ..."
raise "Deployment file not found, please check availability" unless File.file?("docker-compose.yml")
puts "Deployment File OK"
end
## Utils Functions
def show_docker_version
puts `docker version 2>&1`
end
def show_docker_compose_version
puts `docker-compose version 2>&1`
end
# Cross-platform way of finding an executable in the $PATH.
# which('ruby') #=> /usr/bin/ruby
def which(cmd)
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
exts.each { |ext|
exe = File.join(path, "#{cmd}#{ext}")
return exe if File.executable?(exe) && !File.directory?(exe)
}
end
return nil
end