smartmachine 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +661 -0
- data/README.md +147 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/smartmachine +3 -0
- data/lib/smart_machine/apps/app.rb +165 -181
- data/lib/smart_machine/apps/container.rb +120 -0
- data/lib/smart_machine/apps/manager.rb +182 -0
- data/lib/smart_machine/base.rb +24 -6
- data/lib/smart_machine/buildpackers/buildpacker.rb +95 -0
- data/lib/smart_machine/{engine/buildpacks → buildpackers}/rails/Dockerfile +3 -3
- data/lib/smart_machine/buildpackers/rails.rb +221 -0
- data/lib/smart_machine/commands/app.rb +112 -0
- data/lib/smart_machine/commands/buildpacker.rb +53 -0
- data/lib/smart_machine/commands/credentials.rb +17 -0
- data/lib/smart_machine/commands/docker.rb +23 -0
- data/lib/smart_machine/commands/engine.rb +27 -0
- data/lib/smart_machine/commands/grid.rb +33 -0
- data/lib/smart_machine/commands/grid_commands/elasticsearch.rb +68 -0
- data/lib/smart_machine/commands/grid_commands/minio.rb +65 -0
- data/lib/smart_machine/commands/grid_commands/mysql.rb +71 -0
- data/lib/smart_machine/commands/grid_commands/nginx.rb +53 -0
- data/lib/smart_machine/commands/grid_commands/prereceiver.rb +96 -0
- data/lib/smart_machine/commands/grid_commands/redis.rb +65 -0
- data/lib/smart_machine/commands/grid_commands/scheduler.rb +15 -0
- data/lib/smart_machine/commands/grid_commands/sub_thor.rb +15 -0
- data/lib/smart_machine/commands/machine.rb +24 -0
- data/lib/smart_machine/commands/syncer.rb +23 -0
- data/lib/smart_machine/commands/utilities.rb +37 -0
- data/lib/smart_machine/commands.rb +66 -0
- data/lib/smart_machine/configuration.rb +79 -0
- data/lib/smart_machine/credentials.rb +93 -95
- data/lib/smart_machine/docker.rb +144 -143
- data/lib/smart_machine/engine/Dockerfile +7 -5
- data/lib/smart_machine/engine.rb +104 -79
- data/lib/smart_machine/grids/elasticsearch.rb +70 -89
- data/lib/smart_machine/grids/minio.rb +79 -68
- data/lib/smart_machine/grids/mysql.rb +207 -202
- data/lib/smart_machine/grids/nginx.rb +176 -135
- data/lib/smart_machine/grids/prereceiver/Dockerfile +2 -2
- data/lib/smart_machine/grids/prereceiver/pre-receive +17 -0
- data/lib/smart_machine/grids/prereceiver.rb +169 -169
- data/lib/smart_machine/grids/redis.rb +73 -57
- data/lib/smart_machine/logger.rb +26 -26
- data/lib/smart_machine/machine.rb +128 -194
- data/lib/smart_machine/scp.rb +15 -0
- data/lib/smart_machine/ssh.rb +69 -40
- data/lib/smart_machine/syncer.rb +133 -0
- data/lib/smart_machine/templates/dotsmartmachine/Gemfile +7 -0
- data/lib/smart_machine/templates/dotsmartmachine/config/elasticsearch.yml +5 -0
- data/lib/smart_machine/templates/dotsmartmachine/config/environment.rb +0 -9
- data/lib/smart_machine/templates/dotsmartmachine/config/minio.yml +13 -0
- data/lib/smart_machine/templates/dotsmartmachine/config/mysql/schedule.rb +3 -3
- data/lib/smart_machine/templates/dotsmartmachine/config/mysql.yml +13 -0
- data/lib/smart_machine/templates/dotsmartmachine/config/prereceiver.yml +7 -0
- data/lib/smart_machine/templates/dotsmartmachine/config/redis.yml +13 -0
- data/lib/smart_machine/templates/dotsmartmachine/config/users.yml +1 -1
- data/lib/smart_machine/templates/dotsmartmachine/gitignore-template +47 -0
- data/lib/smart_machine/templates/dotsmartmachine/{grids/elasticsearch/data → vendor}/.keep +0 -0
- data/lib/smart_machine/version.rb +30 -6
- data/lib/smart_machine.rb +42 -16
- metadata +97 -47
- data/CHANGELOG.rdoc +0 -0
- data/MIT-LICENSE +0 -21
- data/README.rdoc +0 -87
- data/bin/buildpacker +0 -8
- data/bin/prereceiver +0 -8
- data/bin/scheduler +0 -18
- data/bin/smartmachine +0 -81
- data/bin/smartrunner +0 -33
- data/lib/smart_machine/apps/rails.rb +0 -250
- data/lib/smart_machine/apps.rb +0 -14
- data/lib/smart_machine/boot.rb +0 -32
- data/lib/smart_machine/buildpacker.rb +0 -106
- data/lib/smart_machine/gem_version.rb +0 -17
- data/lib/smart_machine/grids.rb +0 -18
- data/lib/smart_machine/sync.rb +0 -120
- data/lib/smart_machine/templates/dotsmartmachine/grids/elasticsearch/logs/.keep +0 -0
- data/lib/smart_machine/templates/dotsmartmachine/grids/minio/data/.keep +0 -0
- data/lib/smart_machine/templates/dotsmartmachine/grids/mysql/backups/.keep +0 -0
- data/lib/smart_machine/templates/dotsmartmachine/grids/mysql/data/.keep +0 -0
- data/lib/smart_machine/templates/dotsmartmachine/grids/prereceiver/pre-receive +0 -17
- data/lib/smart_machine/templates/dotsmartmachine/grids/redis/data/.keep +0 -0
- data/lib/smart_machine/user.rb +0 -38
@@ -1,97 +1,78 @@
|
|
1
|
-
# The main SmartMachine Grids Elasticsearch driver
|
2
1
|
module SmartMachine
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
class Grids
|
3
|
+
class Elasticsearch < SmartMachine::Base
|
4
|
+
def initialize(name:)
|
5
|
+
config = SmartMachine.config.grids.elasticsearch.dig(name.to_sym)
|
6
|
+
raise "elasticsearch config for #{name} not found." unless config
|
7
7
|
|
8
|
-
|
9
|
-
puts "-----> Installing Elasticsearch"
|
8
|
+
@port = config.dig(:port)
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
puts "done"
|
10
|
+
@name = name.to_s
|
11
|
+
@home_dir = File.expand_path('~')
|
12
|
+
end
|
15
13
|
|
16
|
-
|
17
|
-
|
14
|
+
def uper
|
15
|
+
# Creating networks
|
16
|
+
unless system("docker network inspect #{@name}-network", [:out, :err] => File::NULL)
|
17
|
+
print "-----> Creating network #{@name}-network ... "
|
18
|
+
if system("docker network create #{@name}-network", out: File::NULL)
|
19
|
+
puts "done"
|
20
|
+
end
|
21
|
+
end
|
18
22
|
|
19
|
-
|
20
|
-
|
23
|
+
FileUtils.mkdir_p("#{@home_dir}/machine/grids/elasticsearch/#{@name}/data")
|
24
|
+
FileUtils.mkdir_p("#{@home_dir}/machine/grids/elasticsearch/#{@name}/logs")
|
21
25
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
26
|
+
# Creating & Starting containers
|
27
|
+
print "-----> Creating container #{@name} ... "
|
28
|
+
command = [
|
29
|
+
"docker create",
|
30
|
+
"--name='#{@name}'",
|
31
|
+
"--label='smartmachine.elasticsearch.name=#{@name}'",
|
32
|
+
"--env discovery.type=single-node",
|
33
|
+
"--env cluster.name=#{@name}-cluster",
|
34
|
+
"--env 'ES_JAVA_OPTS=-Xms512m -Xmx512m -Des.enforce.bootstrap.checks=true'",
|
35
|
+
"--env bootstrap.memory_lock=true",
|
36
|
+
"--ulimit memlock=-1:-1",
|
37
|
+
"--ulimit nofile=65535:65535",
|
38
|
+
"--user `id -u`:`id -g`",
|
39
|
+
"--publish='#{@port}:#{@port}'",
|
40
|
+
"--volume='#{@home_dir}/smartmachine/grids/elasticsearch/#{@name}/data:/usr/share/elasticsearch/data'",
|
41
|
+
"--volume='#{@home_dir}/smartmachine/grids/elasticsearch/#{@name}/logs:/usr/share/elasticsearch/logs'",
|
42
|
+
"--restart='always'",
|
43
|
+
"--network='#{@name}-network'",
|
44
|
+
"elasticsearch:7.4.1"
|
45
|
+
]
|
46
|
+
if system(command.compact.join(" "), out: File::NULL)
|
47
|
+
puts "done"
|
48
|
+
puts "-----> Starting container #{@name} ... "
|
49
|
+
if system("docker start #{@name}", out: File::NULL)
|
50
|
+
puts "done"
|
51
|
+
else
|
52
|
+
raise "Error: Could not start the created #{@name} container"
|
53
|
+
end
|
54
|
+
else
|
55
|
+
raise "Error: Could not create #{@name} container"
|
56
|
+
end
|
57
|
+
end
|
27
58
|
|
28
|
-
|
29
|
-
|
59
|
+
def downer
|
60
|
+
# Stopping & Removing containers - in reverse order
|
61
|
+
print "-----> Stopping container #{@name} ... "
|
62
|
+
if system("docker stop '#{@name}'", out: File::NULL)
|
63
|
+
puts "done"
|
64
|
+
print "-----> Removing container #{@name} ... "
|
65
|
+
if system("docker rm '#{@name}'", out: File::NULL)
|
66
|
+
puts "done"
|
67
|
+
end
|
68
|
+
end
|
30
69
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
if SmartMachine::Docker.running?
|
41
|
-
# Creating networks
|
42
|
-
unless system("docker network inspect elasticsearch-network", [:out, :err] => File::NULL)
|
43
|
-
print "-----> Creating network elasticsearch-network ... "
|
44
|
-
if system("docker network create elasticsearch-network", out: File::NULL)
|
45
|
-
puts "done"
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
# Creating & Starting containers
|
50
|
-
print "-----> Creating container elasticsearch ... "
|
51
|
-
if system("docker create \
|
52
|
-
--name='elasticsearch' \
|
53
|
-
--env discovery.type=single-node \
|
54
|
-
--env cluster.name=elasticsearch-cluster \
|
55
|
-
--env 'ES_JAVA_OPTS=-Xms512m -Xmx512m -Des.enforce.bootstrap.checks=true' \
|
56
|
-
--env bootstrap.memory_lock=true \
|
57
|
-
--ulimit memlock=-1:-1 \
|
58
|
-
--ulimit nofile=65535:65535 \
|
59
|
-
--user `id -u`:`id -g` \
|
60
|
-
#{"--publish='#{SmartMachine.credentials.elasticsearch[:port]}:#{SmartMachine.credentials.elasticsearch[:port]}'" if exposed == '--exposed'} \
|
61
|
-
--volume='#{SmartMachine.config.user_home_path}/.smartmachine/grids/elasticsearch/data:/usr/share/elasticsearch/data' \
|
62
|
-
--volume='#{SmartMachine.config.user_home_path}/.smartmachine/grids/elasticsearch/logs:/usr/share/elasticsearch/logs' \
|
63
|
-
--restart='always' \
|
64
|
-
--network='elasticsearch-network' \
|
65
|
-
elasticsearch:7.4.1", out: File::NULL)
|
66
|
-
|
67
|
-
puts "done"
|
68
|
-
print "-----> Starting container elasticsearch ... "
|
69
|
-
if system("docker start elasticsearch", out: File::NULL)
|
70
|
-
puts "done"
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
def down
|
77
|
-
if SmartMachine::Docker.running?
|
78
|
-
# Stopping & Removing containers - in reverse order
|
79
|
-
print "-----> Stopping container elasticsearch ... "
|
80
|
-
if system("docker stop 'elasticsearch'", out: File::NULL)
|
81
|
-
puts "done"
|
82
|
-
print "-----> Removing container elasticsearch ... "
|
83
|
-
if system("docker rm 'elasticsearch'", out: File::NULL)
|
84
|
-
puts "done"
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
# Removing networks
|
89
|
-
print "-----> Removing network elasticsearch-network ... "
|
90
|
-
if system("docker network rm elasticsearch-network", out: File::NULL)
|
91
|
-
puts "done"
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
70
|
+
# Removing networks
|
71
|
+
print "-----> Removing network #{@name}-network ... "
|
72
|
+
if system("docker network rm #{@name}-network", out: File::NULL)
|
73
|
+
puts "done"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -1,77 +1,88 @@
|
|
1
|
-
# The main SmartMachine Grids Minio driver
|
2
1
|
module SmartMachine
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
class Grids
|
3
|
+
class Minio < SmartMachine::Base
|
4
|
+
def initialize(name:)
|
5
|
+
config = SmartMachine.config.grids.minio.dig(name.to_sym)
|
6
|
+
raise "minio config for #{name} not found." unless config
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
@host = config.dig(:host)
|
9
|
+
@access_key = config.dig(:access_key)
|
10
|
+
@secret_key = config.dig(:secret_key)
|
11
|
+
@browser = config.dig(:browser)
|
12
|
+
@worm = config.dig(:worm)
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
print "-----> Creating network minio-network ... "
|
16
|
-
if system("docker network create minio-network", out: File::NULL)
|
17
|
-
puts "done"
|
18
|
-
end
|
19
|
-
end
|
14
|
+
@name = name.to_s
|
15
|
+
@home_dir = File.expand_path('~')
|
16
|
+
end
|
20
17
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
--env MINIO_ACCESS_KEY=#{SmartMachine.credentials.minio[:access_key]} \
|
30
|
-
--env MINIO_SECRET_KEY=#{SmartMachine.credentials.minio[:secret_key]} \
|
31
|
-
--env MINIO_BROWSER=#{SmartMachine.credentials.minio[:browser]} \
|
32
|
-
--env MINIO_WORM=#{SmartMachine.credentials.minio[:worm]} \
|
33
|
-
--user `id -u`:`id -g` \
|
34
|
-
--volume='#{SmartMachine.config.user_home_path}/.smartmachine/grids/minio/data:/data' \
|
35
|
-
--restart='always' \
|
36
|
-
--network='minio-network' \
|
37
|
-
minio/minio:RELEASE.2020-02-27T00-23-05Z server /data", out: File::NULL)
|
18
|
+
def uper
|
19
|
+
# Creating networks
|
20
|
+
unless system("docker network inspect #{@name}-network", [:out, :err] => File::NULL)
|
21
|
+
print "-----> Creating network #{@name}-network ... "
|
22
|
+
if system("docker network create #{@name}-network", out: File::NULL)
|
23
|
+
puts "done"
|
24
|
+
end
|
25
|
+
end
|
38
26
|
|
39
|
-
|
40
|
-
system("docker network connect --alias #{SmartMachine.credentials.minio[:name]}.#{SmartMachine.config.apps_domain} minio-network nginx")
|
41
|
-
system("docker network connect nginx-network minio")
|
27
|
+
FileUtils.mkdir_p("#{@home_dir}/machine/grids/minio/#{@name}/data")
|
42
28
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
29
|
+
# Creating & Starting containers
|
30
|
+
print "-----> Creating container #{@name} ... "
|
31
|
+
command = [
|
32
|
+
"docker create",
|
33
|
+
"--name='#{@name}'",
|
34
|
+
"--env VIRTUAL_HOST=#{@host}",
|
35
|
+
"--env LETSENCRYPT_HOST=#{@host}",
|
36
|
+
"--env LETSENCRYPT_EMAIL=#{SmartMachine.config.sysadmin_email}",
|
37
|
+
"--env LETSENCRYPT_TEST=false",
|
38
|
+
"--env MINIO_ACCESS_KEY=#{@access_key}",
|
39
|
+
"--env MINIO_SECRET_KEY=#{@secret_key}",
|
40
|
+
"--env MINIO_BROWSER=#{@browser}",
|
41
|
+
"--env MINIO_WORM=#{@worm}",
|
42
|
+
"--user `id -u`:`id -g`",
|
43
|
+
"--volume='#{@home_dir}/smartmachine/grids/minio/#{@name}/data:/data'",
|
44
|
+
"--restart='always'",
|
45
|
+
"--network='#{@name}-network'",
|
46
|
+
"minio/minio:RELEASE.2020-02-27T00-23-05Z server /data"
|
47
|
+
]
|
48
|
+
if system(command.compact.join(" "), out: File::NULL)
|
49
|
+
# The alias is necessary to support internal network requests directed to minio container using public url
|
50
|
+
system("docker network connect --alias #{@host} #{@name}-network nginx")
|
51
|
+
system("docker network connect nginx-network #{@name}")
|
51
52
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
53
|
+
puts "done"
|
54
|
+
puts "-----> Starting container #{@name} ... "
|
55
|
+
if system("docker start #{@name}", out: File::NULL)
|
56
|
+
puts "done"
|
57
|
+
else
|
58
|
+
raise "Error: Could not start the created #{@name} container"
|
59
|
+
end
|
60
|
+
else
|
61
|
+
raise "Error: Could not create #{@name} container"
|
62
|
+
end
|
63
|
+
end
|
57
64
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
print "-----> Removing container minio ... "
|
63
|
-
if system("docker rm 'minio'", out: File::NULL)
|
64
|
-
puts "done"
|
65
|
-
end
|
66
|
-
end
|
65
|
+
def downer
|
66
|
+
# Disconnecting networks
|
67
|
+
system("docker network disconnect nginx-network #{@name}")
|
68
|
+
system("docker network disconnect #{@name}-network nginx")
|
67
69
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
70
|
+
# Stopping & Removing containers - in reverse order
|
71
|
+
print "-----> Stopping container #{@name} ... "
|
72
|
+
if system("docker stop '#{@name}'", out: File::NULL)
|
73
|
+
puts "done"
|
74
|
+
print "-----> Removing container #{@name} ... "
|
75
|
+
if system("docker rm '#{@name}'", out: File::NULL)
|
76
|
+
puts "done"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# Removing networks
|
81
|
+
print "-----> Removing network #{@name}-network ... "
|
82
|
+
if system("docker network rm #{@name}-network", out: File::NULL)
|
83
|
+
puts "done"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|