-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
182 lines (152 loc) · 6.53 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
task default: %w[tvnexa:deploy]
namespace :tvnexa do
desc "Authenticating with existing credentials"
task :login do
puts `docker login 2>&1`
end
desc "Cleaning Environment Task"
task :cleaning_environment_task do
puts "Cleaning Environment"
puts `docker image prune -af`
puts `docker volume prune -f 2>&1`
end
desc "Status Containers"
task :status => [
"redis:status",
"galera:status",
"platform:status"
] do
puts "Show Containers Status"
end
desc "Deploys Platform Containers and launches all services and daemons needed to properly work"
task :deploy => [
:cleaning_environment_task,
"redis:start",
"galera:start",
"platform:start",
:status] do
puts "Deploying services..."
end
desc "Undeploy Platform Containers"
task :undeploy => [ :status ] do
puts "Undeploy Services"
puts `docker-compose down -v 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
## Deploy MariaDB Galera Cluster with HAProxy
namespace :galera do
desc "Check Platform Deployment File"
task :check_deployment_file do
puts "Check Platform Deployment File ..."
raise "Deployment file not found, please check availability" unless File.file?("./mariadb_galera_cluster/docker-compose.yml")
puts "Platform Deployment File OK!"
end
desc "Start MariaDB Galera Cluster and HAProxy containers"
task :start => [ :check_docker_task, :login, :check_deployment_file ] do
puts "Start MariaDB Galera Cluster and HAProxy containers"
puts `docker-compose -f ./mariadb_galera_cluster/docker-compose.yml up -d`
end
desc "Stop MariaDB Galera Cluster and HAProxy containers"
task :stop => [ :check_docker_task, :login, :check_deployment_file ] do
puts "Stop Platform Containers"
puts `docker-compose -f ./mariadb_galera_cluster/docker-compose.yml stop 2>&1`
end
desc "Check Status of MariaDB Galera Cluster and HAProxy containers"
task :status => [ :check_docker_task, :login, :check_deployment_file ] do
puts "Check Status of MariaDB Galera Cluster and HAProxy containers"
puts `docker-compose -f ./mariadb_galera_cluster/docker-compose.yml ps`
end
end
# Redis Cluster
namespace :redis do
desc "Check Redis Cluster Deployment File"
task :check_deployment_file do
puts "Check Redis Cluster Deployment File ..."
raise "Deployment file not found, please check availability" unless File.file?("./redis_cluster/docker-compose.yml")
puts "Platform Deployment File OK!"
end
desc "Start and configure Cluster Containers"
task :start => [ :check_docker_task, :login, :check_deployment_file ] do
puts "Start Cluster Containers"
puts `docker-compose -f ./redis_cluster/docker-compose.yml up -d`
puts `docker run -it --rm --network=redis_cluster_redis_cluster_network redislabs/rejson:latest redis-cli --cluster create 192.168.0.30:6379 192.168.0.35:6380 192.168.0.40:6381 192.168.0.45:6382 192.168.0.50:6383 192.168.0.55:6384 192.168.0.60:6385 192.168.0.65:6386 --cluster-replicas 1 --cluster-yes`
end
desc "Stop Cluster Containers"
task :stop => [ :check_docker_task, :login, :check_deployment_file ] do
puts "Stop Cluster Containers"
puts `docker-compose -f ./redis_cluster/docker-compose.yml stop 2>&1`
end
desc "Check Status of Redis Cluster Containers"
task :status => [ :check_docker_task, :login, :check_deployment_file ] do
puts "Check Status of Redis Cluster Containers"
puts `docker-compose -f ./redis_cluster/docker-compose.yml ps`
end
end
## Deploy Platform
namespace :platform do
desc "Check Platform Deployment File"
task :check_deployment_file do
puts "Check Platform Deployment File ..."
raise "Deployment file not found, please check availability" unless File.file?("./platform/docker-compose.yml")
puts "Platform Deployment File OK!"
end
desc "Start Platform Hotspot JVM Containers"
task :start => [ :check_docker_task, :login, :check_deployment_file ] do
puts "Start Platform Containers"
puts `docker-compose -f ./platform/docker-compose.yml up -d`
end
desc "Stop Platform Hotspot JVM Containers"
task :stop => [ :check_docker_task, :login, :check_deployment_file ] do
puts "Stop Platform Containers"
puts `docker-compose -f ./platform/docker-compose.yml stop 2>&1`
end
desc "Build Docker Image based on Hotspot JVM"
task :build_image => [:check_docker_task, :login] do
microservicesFolder = "./platform/microservices"
apiServiceDockerImage = "ssanchez11/tv_nexa_api_service:0.0.1"
ingestionServiceDockerImage = "ssanchez11/tv_nexa_ingestion_service:0.0.1"
puts "Build Docker Image #{apiServiceDockerImage} based on Hotspot"
puts `docker build -t #{apiServiceDockerImage} -f #{microservicesFolder}/tv_nexa_api_service/Dockerfile #{microservicesFolder}`
puts "Docker image #{apiServiceDockerImage} has been created! trying to upload it!"
puts `docker push #{apiServiceDockerImage}`
puts "Build Docker Image #{ingestionServiceDockerImage} based on Hotspot"
puts `docker build -t #{ingestionServiceDockerImage} -f #{microservicesFolder}/tv_nexa_ingestion_service/Dockerfile #{microservicesFolder}`
puts "Docker image #{ingestionServiceDockerImage} has been created! trying to upload it!"
puts `docker push #{ingestionServiceDockerImage}`
puts `docker images`
end
desc "Check Status of Platform Containers"
task :status => [ :check_docker_task, :login, :check_deployment_file ] do
puts "Check Status of Platform Containers"
puts `docker-compose -f ./platform/docker-compose.yml ps`
end
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
end