smartmachine 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +661 -0
  3. data/README.md +147 -0
  4. data/bin/console +14 -0
  5. data/bin/setup +8 -0
  6. data/exe/smartmachine +3 -0
  7. data/lib/smart_machine/apps/app.rb +165 -181
  8. data/lib/smart_machine/apps/container.rb +120 -0
  9. data/lib/smart_machine/apps/manager.rb +182 -0
  10. data/lib/smart_machine/base.rb +24 -6
  11. data/lib/smart_machine/buildpackers/buildpacker.rb +95 -0
  12. data/lib/smart_machine/{engine/buildpacks → buildpackers}/rails/Dockerfile +3 -3
  13. data/lib/smart_machine/buildpackers/rails.rb +221 -0
  14. data/lib/smart_machine/commands/app.rb +112 -0
  15. data/lib/smart_machine/commands/buildpacker.rb +53 -0
  16. data/lib/smart_machine/commands/credentials.rb +17 -0
  17. data/lib/smart_machine/commands/docker.rb +23 -0
  18. data/lib/smart_machine/commands/engine.rb +27 -0
  19. data/lib/smart_machine/commands/grid.rb +33 -0
  20. data/lib/smart_machine/commands/grid_commands/elasticsearch.rb +68 -0
  21. data/lib/smart_machine/commands/grid_commands/minio.rb +65 -0
  22. data/lib/smart_machine/commands/grid_commands/mysql.rb +71 -0
  23. data/lib/smart_machine/commands/grid_commands/nginx.rb +53 -0
  24. data/lib/smart_machine/commands/grid_commands/prereceiver.rb +96 -0
  25. data/lib/smart_machine/commands/grid_commands/redis.rb +65 -0
  26. data/lib/smart_machine/commands/grid_commands/scheduler.rb +15 -0
  27. data/lib/smart_machine/commands/grid_commands/sub_thor.rb +15 -0
  28. data/lib/smart_machine/commands/machine.rb +24 -0
  29. data/lib/smart_machine/commands/syncer.rb +23 -0
  30. data/lib/smart_machine/commands/utilities.rb +37 -0
  31. data/lib/smart_machine/commands.rb +66 -0
  32. data/lib/smart_machine/configuration.rb +79 -0
  33. data/lib/smart_machine/credentials.rb +93 -95
  34. data/lib/smart_machine/docker.rb +144 -143
  35. data/lib/smart_machine/engine/Dockerfile +7 -5
  36. data/lib/smart_machine/engine.rb +104 -79
  37. data/lib/smart_machine/grids/elasticsearch.rb +70 -89
  38. data/lib/smart_machine/grids/minio.rb +79 -68
  39. data/lib/smart_machine/grids/mysql.rb +207 -202
  40. data/lib/smart_machine/grids/nginx.rb +176 -135
  41. data/lib/smart_machine/grids/prereceiver/Dockerfile +2 -2
  42. data/lib/smart_machine/grids/prereceiver/pre-receive +17 -0
  43. data/lib/smart_machine/grids/prereceiver.rb +169 -169
  44. data/lib/smart_machine/grids/redis.rb +73 -57
  45. data/lib/smart_machine/logger.rb +26 -26
  46. data/lib/smart_machine/machine.rb +128 -194
  47. data/lib/smart_machine/scp.rb +15 -0
  48. data/lib/smart_machine/ssh.rb +69 -40
  49. data/lib/smart_machine/syncer.rb +133 -0
  50. data/lib/smart_machine/templates/dotsmartmachine/Gemfile +7 -0
  51. data/lib/smart_machine/templates/dotsmartmachine/config/elasticsearch.yml +5 -0
  52. data/lib/smart_machine/templates/dotsmartmachine/config/environment.rb +0 -9
  53. data/lib/smart_machine/templates/dotsmartmachine/config/minio.yml +13 -0
  54. data/lib/smart_machine/templates/dotsmartmachine/config/mysql/schedule.rb +3 -3
  55. data/lib/smart_machine/templates/dotsmartmachine/config/mysql.yml +13 -0
  56. data/lib/smart_machine/templates/dotsmartmachine/config/prereceiver.yml +7 -0
  57. data/lib/smart_machine/templates/dotsmartmachine/config/redis.yml +13 -0
  58. data/lib/smart_machine/templates/dotsmartmachine/config/users.yml +1 -1
  59. data/lib/smart_machine/templates/dotsmartmachine/gitignore-template +47 -0
  60. data/lib/smart_machine/templates/dotsmartmachine/{grids/elasticsearch/data → vendor}/.keep +0 -0
  61. data/lib/smart_machine/version.rb +30 -6
  62. data/lib/smart_machine.rb +42 -16
  63. metadata +97 -47
  64. data/CHANGELOG.rdoc +0 -0
  65. data/MIT-LICENSE +0 -21
  66. data/README.rdoc +0 -87
  67. data/bin/buildpacker +0 -8
  68. data/bin/prereceiver +0 -8
  69. data/bin/scheduler +0 -18
  70. data/bin/smartmachine +0 -81
  71. data/bin/smartrunner +0 -33
  72. data/lib/smart_machine/apps/rails.rb +0 -250
  73. data/lib/smart_machine/apps.rb +0 -14
  74. data/lib/smart_machine/boot.rb +0 -32
  75. data/lib/smart_machine/buildpacker.rb +0 -106
  76. data/lib/smart_machine/gem_version.rb +0 -17
  77. data/lib/smart_machine/grids.rb +0 -18
  78. data/lib/smart_machine/sync.rb +0 -120
  79. data/lib/smart_machine/templates/dotsmartmachine/grids/elasticsearch/logs/.keep +0 -0
  80. data/lib/smart_machine/templates/dotsmartmachine/grids/minio/data/.keep +0 -0
  81. data/lib/smart_machine/templates/dotsmartmachine/grids/mysql/backups/.keep +0 -0
  82. data/lib/smart_machine/templates/dotsmartmachine/grids/mysql/data/.keep +0 -0
  83. data/lib/smart_machine/templates/dotsmartmachine/grids/prereceiver/pre-receive +0 -17
  84. data/lib/smart_machine/templates/dotsmartmachine/grids/redis/data/.keep +0 -0
  85. data/lib/smart_machine/user.rb +0 -38
@@ -1,170 +1,170 @@
1
- # The main SmartMachine Grids Git driver
2
1
  module SmartMachine
3
- class Grids
4
- class Prereceiver < SmartMachine::Base
5
-
6
- def initialize
7
- end
8
-
9
- def install
10
- puts "-----> Installing Prereceiver"
11
-
12
- ssh = SmartMachine::SSH.new
13
- commands = ["smartmachine runner prereceiver create"]
14
- ssh.run commands
15
-
16
- puts "-----> Prereceiver Installation Complete"
17
- end
18
-
19
- def uninstall
20
- puts "-----> Uninstalling Prereceiver"
21
-
22
- ssh = SmartMachine::SSH.new
23
- commands = ["smartmachine runner prereceiver destroy"]
24
- ssh.run commands
25
-
26
- puts "-----> Prereceiver Uninstallation Complete"
27
- end
28
-
29
- def update
30
- uninstall
31
- install
32
- end
33
-
34
- def create
35
- unless system("docker image inspect #{prereceiver_image_name}", [:out, :err] => File::NULL)
36
- print "-----> Creating image #{prereceiver_image_name} ... "
37
- if system("docker image build -t #{prereceiver_image_name} \
38
- --build-arg SMARTMACHINE_VERSION=#{SmartMachine.version} \
39
- #{SmartMachine.config.root_path}/lib/smart_machine/grids/prereceiver", out: File::NULL)
40
- puts "done"
41
-
42
- up
43
- end
44
- end
45
- end
46
-
47
- def destroy
48
- down
49
-
50
- if system("docker image inspect #{prereceiver_image_name}", [:out, :err] => File::NULL)
51
- print "-----> Removing image #{prereceiver_image_name} ... "
52
- if system("docker image rm #{prereceiver_image_name}", out: File::NULL)
53
- puts "done"
54
- end
55
- end
56
- end
57
-
58
- def up
59
- if SmartMachine::Docker.running?
60
- if system("docker image inspect #{prereceiver_image_name}", [:out, :err] => File::NULL) && system("docker image inspect #{buildpacker_image_name}", [:out, :err] => File::NULL)
61
- print "-----> Creating container prereceiver with image #{prereceiver_image_name} ... "
62
- if system("docker create \
63
- --name='prereceiver' \
64
- --env VIRTUAL_PROTO=fastcgi \
65
- --env VIRTUAL_HOST=#{SmartMachine.config.git_domain} \
66
- --env LETSENCRYPT_HOST=#{SmartMachine.config.git_domain} \
67
- --env LETSENCRYPT_EMAIL=#{SmartMachine.config.sysadmin_email} \
68
- --env LETSENCRYPT_TEST=#{SmartMachine.config.letsencrypt_test} \
69
- --env GIT_PROJECT_ROOT=#{SmartMachine.config.user_home_path}/.smartmachine/apps/repositories \
70
- --env GIT_HTTP_EXPORT_ALL="" \
71
- --user `id -u` \
72
- --workdir /home/`id -un`/.smartmachine/apps \
73
- --expose='9000' \
74
- --volume='#{SmartMachine.config.user_home_path}/.smartmachine/config:#{SmartMachine.config.user_home_path}/.smartmachine/config' \
75
- --volume='#{SmartMachine.config.user_home_path}/.smartmachine/apps:#{SmartMachine.config.user_home_path}/.smartmachine/apps' \
76
- --volume='#{SmartMachine.config.user_home_path}/.smartmachine/grids/prereceiver:#{SmartMachine.config.user_home_path}/.smartmachine/grids/prereceiver' \
77
- --volume='/var/run/docker.sock:/var/run/docker.sock:ro' \
78
- --restart='always' \
79
- --network='nginx-network' \
80
- #{prereceiver_image_name}", out: File::NULL)
81
- puts "done"
82
-
83
- print "-----> Starting container prereceiver with image #{prereceiver_image_name} ... "
84
- if system("docker start prereceiver", out: File::NULL)
85
- puts "done"
86
- end
87
- end
88
- end
89
- end
90
- end
91
-
92
- def down
93
- if SmartMachine::Docker.running?
94
- # Stopping & Removing containers - in reverse order
95
- if system("docker inspect -f '{{.State.Running}}' 'prereceiver'", [:out, :err] => File::NULL)
96
- print "-----> Stopping container prereceiver with image #{prereceiver_image_name} ... "
97
- if system("docker stop 'prereceiver'", out: File::NULL)
98
- puts "done"
99
-
100
- print "-----> Removing container prereceiver with image #{prereceiver_image_name} ... "
101
- if system("docker rm 'prereceiver'", out: File::NULL)
102
- puts "done"
103
- end
104
- end
105
- else
106
- puts "-----> Container 'prereceiver' is currently not running."
107
- end
108
- end
109
- end
110
-
111
- def self.prereceive(appname, username, oldrev, newrev, refname)
112
- logger.formatter = proc do |severity, datetime, progname, message|
113
- severity_text = { "DEBUG" => "\u{1f527} #{severity}:", "INFO" => " \u{276f}", "WARN" => "\u{2757} #{severity}:",
114
- "ERROR" => "\u{274c} #{severity}:", "FATAL" => "\u{2b55} #{severity}:", "UNKNOWN" => "\u{2753} #{severity}:"
115
- }
116
- "\t\t\t\t#{severity_text[severity]} #{message}\n"
117
- end
118
-
119
- # Load vars and environment
120
- container_path = "#{SmartMachine.config.user_home_path}/.smartmachine/apps/containers/#{appname}"
121
- env_vars = SmartMachine::Apps::App.get_env_vars(container_path)
122
- return unless env_vars
123
-
124
- # Verify the user and ensure the user is correct and has access to this repository
125
- unless env_vars['USERNAME'] == username
126
- logger.error "Unauthorized."
127
- return
128
- end
129
-
130
- # Only run this script for the master branch. You can remove this
131
- # if block if you wish to run it for others as well.
132
- if refname == "refs/heads/master"
133
- logger.info "Loading Application ..."
134
-
135
- # Note: There should be no space between + and " in version.
136
- # Note: date will be UTC date until timezone has been changed.
137
- version = `date +"%Y%m%d%H%M%S"`.chomp!
138
- container_path_with_version = "#{container_path}/releases/#{version}"
139
-
140
- unless Dir.exist? container_path_with_version
141
- FileUtils.mkdir_p(container_path_with_version)
142
- if system("git archive #{newrev} | tar -x -C #{container_path_with_version}")
143
- # Start App
144
- SmartMachine::Apps::App.start(appname)
145
- else
146
- logger.fatal "Could not extract new app version ... Failed."
147
- return
148
- end
149
- else
150
- logger.fatal "This version name already exists ... Failed."
151
- return
152
- end
153
- else
154
- # Allow the push to complete for all other branches normally.
155
- exit 10
156
- end
157
-
158
- logger.formatter = nil
159
- end
160
-
161
- def buildpacker_image_name
162
- Buildpacker.new.buildpacker_image_name
163
- end
164
-
165
- def prereceiver_image_name
166
- "smartmachine/prereceiver:#{SmartMachine.version}"
167
- end
168
- end
169
- end
170
- end
2
+ class Grids
3
+ class Prereceiver < SmartMachine::Base
4
+
5
+ def initialize(name:)
6
+ config = SmartMachine.config.grids.prereceiver.dig(name.to_sym)
7
+ raise "prereceiver config for #{name} not found." unless config
8
+
9
+ @git_domain = config.dig(:git_domain)
10
+ @letsencrypt_test = config.dig(:letsencrypt_test)
11
+ @letsencrypt_email = SmartMachine.config.sysadmin_email
12
+ @image_name = "smartmachine/prereceiver:#{SmartMachine.version}"
13
+
14
+ @name = name.to_s
15
+ @home_dir = File.expand_path('~')
16
+ end
17
+
18
+ def installer
19
+ unless system("docker image inspect #{@image_name}", [:out, :err] => File::NULL)
20
+ puts "-----> Creating image #{@image_name} ... "
21
+ command = [
22
+ "docker image build -t #{@image_name}",
23
+ "--build-arg SMARTMACHINE_VERSION=#{SmartMachine.version}",
24
+ "#{SmartMachine.config.gem_dir}/lib/smart_machine/grids/prereceiver"
25
+ ]
26
+ if system(command.join(" "), out: File::NULL)
27
+ puts "done"
28
+ else
29
+ raise "Error: Could not install Prereceiver."
30
+ end
31
+ else
32
+ raise "Error: Prereceiver already installed. Please uninstall using 'smartmachine grids prereceiver uninstall' and try installing again."
33
+ end
34
+ end
35
+
36
+ def uninstaller
37
+ unless system("docker inspect -f '{{.State.Running}}' '#{@name}'", [:out, :err] => File::NULL)
38
+ if system("docker image inspect #{@image_name}", [:out, :err] => File::NULL)
39
+ puts "-----> Removing image #{@image_name} ... "
40
+ if system("docker image rm #{@image_name}", out: File::NULL)
41
+ puts "done"
42
+ end
43
+ else
44
+ raise "Error: Prereceiver already uninstalled. Please install using 'smartmachine grids prereceiver install' and try uninstalling again."
45
+ end
46
+ else
47
+ raise "Error: Prereceiver is currently running. Please stop the prereceiver using 'smartmachine grids prereceiver down' and try uninstalling again."
48
+ end
49
+ end
50
+
51
+ def uper
52
+ if system("docker image inspect #{@image_name}", [:out, :err] => File::NULL)
53
+ FileUtils.mkdir_p("#{@home_dir}/machine/grids/prereceiver/#{@name}")
54
+ system("cp #{SmartMachine.config.gem_dir}/lib/smart_machine/grids/prereceiver/pre-receive #{@home_dir}/machine/grids/prereceiver/#{@name}/pre-receive")
55
+ system("chmod +x #{@home_dir}/machine/grids/prereceiver/#{@name}/pre-receive")
56
+
57
+ puts "-----> Creating container #{@name} with image #{@image_name} ... "
58
+ command = [
59
+ "docker create",
60
+ "--name='#{@name}'",
61
+ "--env VIRTUAL_PROTO=fastcgi",
62
+ "--env VIRTUAL_HOST=#{@git_domain}",
63
+ "--env LETSENCRYPT_HOST=#{@git_domain}",
64
+ "--env LETSENCRYPT_EMAIL=#{@letsencrypt_email}",
65
+ "--env LETSENCRYPT_TEST=#{@letsencrypt_test}",
66
+ "--env GIT_PROJECT_ROOT=#{@home_dir}/machine/apps/repositories",
67
+ "--env GIT_HTTP_EXPORT_ALL=''",
68
+ "--user `id -u`",
69
+ "--workdir #{@home_dir}/machine",
70
+ "--expose='9000'",
71
+ "--volume='#{@home_dir}/smartmachine/config:#{@home_dir}/machine/config'",
72
+ "--volume='#{@home_dir}/smartmachine/apps:#{@home_dir}/machine/apps'",
73
+ "--volume='#{@home_dir}/smartmachine/grids/prereceiver/#{@name}:#{@home_dir}/machine/grids/prereceiver/#{@name}'",
74
+ "--volume='/var/run/docker.sock:/var/run/docker.sock:ro'",
75
+ "--restart='always'",
76
+ "--network='nginx-network'",
77
+ "#{@image_name}"
78
+ ]
79
+ if system(command.join(" "), out: File::NULL)
80
+ puts "done"
81
+
82
+ puts "-----> Starting container #{@name} with image #{@image_name} ... "
83
+ if system("docker start #{@name}", out: File::NULL)
84
+ puts "done"
85
+ else
86
+ raise "Error: Could not start the created image to take UP the prereceiver."
87
+ end
88
+ else
89
+ raise "Error: Could not create image to take UP the prereceiver."
90
+ end
91
+ end
92
+ end
93
+
94
+ # Stopping & Removing containers - in reverse order
95
+ def downer
96
+ if system("docker inspect -f '{{.State.Running}}' '#{@name}'", [:out, :err] => File::NULL)
97
+ puts "-----> Stopping container #{@name} with image #{@image_name} ... "
98
+ if system("docker stop '#{@name}'", out: File::NULL)
99
+ puts "done"
100
+
101
+ puts "-----> Removing container #{@name} with image #{@image_name} ... "
102
+ if system("docker rm '#{@name}'", out: File::NULL)
103
+
104
+ system("rm -r #{@home_dir}/machine/grids/prereceiver/#{@name}")
105
+
106
+ puts "done"
107
+ end
108
+ end
109
+ else
110
+ puts "-----> Container '#{@name}' is currently not running."
111
+ end
112
+ end
113
+
114
+ def prereceive(appname:, username:, oldrev:, newrev:, refname:)
115
+ manager = SmartMachine::Apps::Manager.new(appname: appname)
116
+
117
+ # Loading SmartMachine Environment File
118
+ if File.exist?("#{@home_dir}/machine/config/environment.rb")
119
+ require "#{@home_dir}/machine/config/environment"
120
+ end
121
+
122
+ logger.formatter = proc do |severity, datetime, progname, message|
123
+ severity_text = { "DEBUG" => "\u{1f527} #{severity}:", "INFO" => " \u{276f}", "WARN" => "\u{2757} #{severity}:",
124
+ "ERROR" => "\u{274c} #{severity}:", "FATAL" => "\u{2b55} #{severity}:", "UNKNOWN" => "\u{2753} #{severity}:"
125
+ }
126
+ "\t\t\t\t#{severity_text[severity]} #{message}\n"
127
+ end
128
+
129
+ # Load vars and environment
130
+ container_path = "#{@home_dir}/machine/apps/containers/#{appname}"
131
+
132
+ # Verify the user and ensure the user is correct and has access to this repository
133
+ unless manager.env_vars.present? && manager.env_vars['USERNAME'] == username
134
+ logger.error "Unauthorized."
135
+ return
136
+ end
137
+
138
+ # Only run this script for the main branch. You can remove this
139
+ # if block if you wish to run it for others as well.
140
+ if refname == "refs/heads/main"
141
+ logger.info "Loading Application ..."
142
+
143
+ # Note: There should be no space between + and " in version.
144
+ # Note: date will be UTC date until timezone has been changed.
145
+ version = `date +"%Y%m%d%H%M%S"`.chomp!
146
+ container_path_with_version = "#{container_path}/releases/#{version}"
147
+
148
+ unless Dir.exist? container_path_with_version
149
+ FileUtils.mkdir_p(container_path_with_version)
150
+ if system("git archive #{newrev} | tar -x -C #{container_path_with_version}")
151
+ # Deploy app with the latest release
152
+ manager.deploy
153
+ else
154
+ logger.fatal "Could not extract new app version ... Failed."
155
+ return
156
+ end
157
+ else
158
+ logger.fatal "This version name already exists ... Failed."
159
+ return
160
+ end
161
+ else
162
+ # Allow the push to complete for all other branches normally.
163
+ exit 10
164
+ end
165
+
166
+ logger.formatter = nil
167
+ end
168
+ end
169
+ end
170
+ end
@@ -1,58 +1,74 @@
1
- # The main SmartMachine Grids Redis driver
2
1
  module SmartMachine
3
- class Grids
4
- class Redis < SmartMachine::Base
5
- def initialize
6
- end
7
-
8
- def up
9
- if SmartMachine::Docker.running?
10
- # Creating networks
11
- unless system("docker network inspect redis-network", [:out, :err] => File::NULL)
12
- print "-----> Creating network redis-network ... "
13
- if system("docker network create redis-network", out: File::NULL)
14
- puts "done"
15
- end
16
- end
17
-
18
- # Creating & Starting containers
19
- print "-----> Creating container redis ... "
20
- if system("docker create \
21
- --name='redis' \
22
- --user `id -u`:`id -g` \
23
- --volume='#{SmartMachine.config.user_home_path}/.smartmachine/grids/redis/data:/data' \
24
- --restart='always' \
25
- --network='redis-network' \
26
- redis:6.0-rc3-alpine3.11 redis-server --appendonly yes", out: File::NULL)
27
-
28
- puts "done"
29
- print "-----> Starting container redis ... "
30
- if system("docker start redis", out: File::NULL)
31
- puts "done"
32
- end
33
- end
34
- end
35
- end
36
-
37
- def down
38
- if SmartMachine::Docker.running?
39
- # Stopping & Removing containers - in reverse order
40
- print "-----> Stopping container redis ... "
41
- if system("docker stop 'redis'", out: File::NULL)
42
- puts "done"
43
- print "-----> Removing container redis ... "
44
- if system("docker rm 'redis'", out: File::NULL)
45
- puts "done"
46
- end
47
- end
48
-
49
- # Removing networks
50
- print "-----> Removing network redis-network ... "
51
- if system("docker network rm redis-network", out: File::NULL)
52
- puts "done"
53
- end
54
- end
55
- end
56
- end
57
- end
58
- end
2
+ class Grids
3
+ class Redis < SmartMachine::Base
4
+ def initialize(name:)
5
+ config = SmartMachine.config.grids.redis.dig(name.to_sym)
6
+ raise "redis config for #{name} not found." unless config
7
+
8
+ @port = config.dig(:port)
9
+ @password = config.dig(:password)
10
+ @appendonly = config.dig(:appendonly)
11
+ @maxmemory = config.dig(:maxmemory)
12
+ @maxmemory_policy = config.dig(:maxmemory_policy)
13
+
14
+ @name = name.to_s
15
+ @home_dir = File.expand_path('~')
16
+ end
17
+
18
+ def uper
19
+ # Creating networks
20
+ unless system("docker network inspect #{@name}-network", [:out, :err] => File::NULL)
21
+ puts "-----> Creating network #{@name}-network ... "
22
+ if system("docker network create #{@name}-network", out: File::NULL)
23
+ puts "done"
24
+ end
25
+ end
26
+
27
+ FileUtils.mkdir_p("#{@home_dir}/machine/grids/redis/#{@name}/data")
28
+
29
+ # Creating & Starting containers
30
+ puts "-----> Creating container #{@name} ... "
31
+
32
+ command = [
33
+ "docker create",
34
+ "--name='#{@name}'",
35
+ "--user `id -u`:`id -g`",
36
+ "--publish='#{@port}:#{@port}'",
37
+ "--volume='#{@home_dir}/smartmachine/grids/redis/#{@name}/data:/data'",
38
+ "--restart='always'",
39
+ "--network='#{@name}-network'",
40
+ "redis:6.2.6-alpine3.15 redis-server --port #{@port} --requirepass #{@password} --appendonly #{@appendonly} --maxmemory #{@maxmemory} --maxmemory-policy #{@maxmemory_policy}"
41
+ ]
42
+ if system(command.compact.join(" "), out: File::NULL)
43
+ puts "done"
44
+ puts "-----> Starting container #{@name} ... "
45
+ if system("docker start #{@name}", out: File::NULL)
46
+ puts "done"
47
+ else
48
+ raise "Error: Could not start the created #{@name} container"
49
+ end
50
+ else
51
+ raise "Error: Could not create #{@name} container"
52
+ end
53
+ end
54
+
55
+ # Stopping & Removing containers - in reverse order
56
+ def downer
57
+ puts "-----> Stopping container #{@name} ... "
58
+ if system("docker stop '#{@name}'", out: File::NULL)
59
+ puts "done"
60
+ puts "-----> Removing container #{@name} ... "
61
+ if system("docker rm '#{@name}'", out: File::NULL)
62
+ puts "done"
63
+ end
64
+ end
65
+
66
+ # Removing networks
67
+ puts "-----> Removing network #{@name}-network ... "
68
+ if system("docker network rm #{@name}-network", out: File::NULL)
69
+ puts "done"
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -3,33 +3,33 @@ require "logger"
3
3
  $stdout.sync = true
4
4
 
5
5
  module SmartMachine
6
- module Logger
7
- def logger
8
- @logger ||= SmartMachine::Logger.logger_for(self.class.name)
9
- end
6
+ module Logger
7
+ def logger
8
+ @logger ||= SmartMachine::Logger.logger_for(self.class.name)
9
+ end
10
10
 
11
- # Use a hash class-ivar to cache a unique Logger per class:
12
- @loggers = {}
11
+ # Use a hash class-ivar to cache a unique Logger per class:
12
+ @loggers = {}
13
13
 
14
- def self.included(base)
15
- class << base
16
- def logger
17
- @logger ||= SmartMachine::Logger.logger_for(self.name)
18
- end
19
- end
20
- end
14
+ def self.included(base)
15
+ class << base
16
+ def logger
17
+ @logger ||= SmartMachine::Logger.logger_for(self.name)
18
+ end
19
+ end
20
+ end
21
21
 
22
- class << self
23
- def logger_for(classname)
24
- @loggers[classname] ||= configure_logger_for(classname)
25
- end
22
+ class << self
23
+ def logger_for(classname)
24
+ @loggers[classname] ||= configure_logger_for(classname)
25
+ end
26
26
 
27
- def configure_logger_for(classname)
28
- logger = ::Logger.new($stdout)
29
- logger.level = ::Logger.const_get("#{SmartMachine.config.logger_level}".upcase)
30
- logger.progname = classname
31
- logger
32
- end
33
- end
34
- end
35
- end
27
+ def configure_logger_for(classname)
28
+ logger = ::Logger.new($stdout)
29
+ logger.level = ::Logger.const_get("#{SmartMachine.config.logger_level}".upcase)
30
+ logger.progname = classname
31
+ logger
32
+ end
33
+ end
34
+ end
35
+ end