smartmachine 0.8.0 → 1.0.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 +75 -57
- data/lib/smart_machine/grids/scheduler/Dockerfile +1 -1
- 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 +15 -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,137 +1,178 @@
|
|
1
|
-
|
1
|
+
require 'yaml'
|
2
|
+
require "base64"
|
3
|
+
require 'bcrypt'
|
4
|
+
|
2
5
|
module SmartMachine
|
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
|
-
|
6
|
+
class Grids
|
7
|
+
class Nginx < SmartMachine::Base
|
8
|
+
def initialize
|
9
|
+
@home_dir = File.expand_path('~')
|
10
|
+
end
|
11
|
+
|
12
|
+
def uper
|
13
|
+
# Creating volumes
|
14
|
+
puts "-----> Creating volume nginx-confd ... "
|
15
|
+
if system("docker volume create nginx-confd", out: File::NULL)
|
16
|
+
puts "done"
|
17
|
+
end
|
18
|
+
|
19
|
+
puts "-----> Creating volume nginx-vhost ... "
|
20
|
+
if system("docker volume create nginx-vhost", out: File::NULL)
|
21
|
+
puts "done"
|
22
|
+
end
|
23
|
+
|
24
|
+
puts "-----> Creating volume nginx-shtml ... "
|
25
|
+
if system("docker volume create nginx-shtml", out: File::NULL)
|
26
|
+
puts "done"
|
27
|
+
end
|
28
|
+
|
29
|
+
# Creating networks
|
30
|
+
unless system("docker network inspect nginx-network", [:out, :err] => File::NULL)
|
31
|
+
puts "-----> Creating network nginx-network ... "
|
32
|
+
if system("docker network create nginx-network", out: File::NULL)
|
33
|
+
puts "done"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Creating & Starting containers
|
38
|
+
puts "-----> Creating container nginx ... "
|
39
|
+
command = [
|
40
|
+
"docker create",
|
41
|
+
"--name='nginx'",
|
42
|
+
"--publish='80:80' --publish='443:443'",
|
43
|
+
"--volume='nginx-confd:/etc/nginx/conf.d/'",
|
44
|
+
"--volume='nginx-vhost:/etc/nginx/vhost.d/'",
|
45
|
+
"--volume='nginx-shtml:/usr/share/nginx/html'",
|
46
|
+
"--volume='#{@home_dir}/smartmachine/grids/nginx/certificates:/etc/nginx/certs'",
|
47
|
+
"--volume='#{@home_dir}/smartmachine/grids/nginx/fastcgi.conf:/etc/nginx/fastcgi.conf:ro'",
|
48
|
+
"--volume='#{@home_dir}/smartmachine/grids/nginx/htpasswd:/etc/nginx/htpasswd:ro'",
|
49
|
+
"--restart='always'",
|
50
|
+
"--network='nginx-network'",
|
51
|
+
"nginx:alpine"
|
52
|
+
]
|
53
|
+
if system(command.compact.join(" "), out: File::NULL)
|
54
|
+
puts "done"
|
55
|
+
puts "-----> Starting container nginx ... "
|
56
|
+
if system("docker start nginx", out: File::NULL)
|
57
|
+
puts "done"
|
58
|
+
else
|
59
|
+
raise "Error: Could not start the created nginx container."
|
60
|
+
end
|
61
|
+
else
|
62
|
+
raise "Error: Could not create nginx container."
|
63
|
+
end
|
64
|
+
|
65
|
+
puts "-----> Creating container nginx-gen ... "
|
66
|
+
command = [
|
67
|
+
"docker create",
|
68
|
+
"--name='nginx-gen'",
|
69
|
+
"--volumes-from nginx",
|
70
|
+
"--volume='#{@home_dir}/smartmachine/grids/nginx/nginx.tmpl:/etc/docker-gen/templates/nginx.tmpl:ro'",
|
71
|
+
"--volume='/var/run/docker.sock:/tmp/docker.sock:ro'",
|
72
|
+
"--restart='always'",
|
73
|
+
"--network='nginx-network'",
|
74
|
+
"jwilder/docker-gen",
|
75
|
+
"-notify-sighup nginx -watch /etc/docker-gen/templates/nginx.tmpl /etc/nginx/conf.d/default.conf"
|
76
|
+
]
|
77
|
+
if system(command.compact.join(" "), out: File::NULL)
|
78
|
+
puts "done"
|
79
|
+
puts "-----> Starting container nginx-gen ... "
|
80
|
+
if system("docker start nginx-gen", out: File::NULL)
|
81
|
+
puts "done"
|
82
|
+
else
|
83
|
+
raise "Error: Could not start the created nginx-gen container."
|
84
|
+
end
|
85
|
+
else
|
86
|
+
raise "Error: Could not create nginx-gen container."
|
87
|
+
end
|
88
|
+
|
89
|
+
puts "-----> Creating container nginx-letsencrypt ... "
|
90
|
+
command = [
|
91
|
+
"docker create",
|
92
|
+
"--name='nginx-letsencrypt'",
|
93
|
+
"--env NGINX_PROXY_CONTAINER=nginx",
|
94
|
+
"--env NGINX_DOCKER_GEN_CONTAINER=nginx-gen",
|
95
|
+
"--env DEFAULT_EMAIL=#{SmartMachine.config.sysadmin_email}",
|
96
|
+
"--volumes-from nginx",
|
97
|
+
"--volume='/var/run/docker.sock:/var/run/docker.sock:ro'",
|
98
|
+
"--restart='always'",
|
99
|
+
"--network='nginx-network'",
|
100
|
+
"jrcs/letsencrypt-nginx-proxy-companion"
|
101
|
+
]
|
102
|
+
if system(command.compact.join(" "), out: File::NULL)
|
103
|
+
puts "done"
|
104
|
+
puts "-----> Starting container nginx-letsencrypt ... "
|
105
|
+
if system("docker start nginx-letsencrypt", out: File::NULL)
|
106
|
+
puts "done"
|
107
|
+
else
|
108
|
+
raise "Error: Could not start the created nginx-letsencrypt container."
|
109
|
+
end
|
110
|
+
else
|
111
|
+
raise "Error: Could not create nginx-letsencrypt container."
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
# Stopping & Removing containers - in reverse order
|
116
|
+
def downer
|
117
|
+
puts "-----> Stopping container nginx-letsencrypt ... "
|
118
|
+
if system("docker stop 'nginx-letsencrypt'", out: File::NULL)
|
119
|
+
puts "done"
|
120
|
+
puts "-----> Removing container nginx-letsencrypt ... "
|
121
|
+
if system("docker rm 'nginx-letsencrypt'", out: File::NULL)
|
122
|
+
puts "done"
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
puts "-----> Stopping container nginx-gen ... "
|
127
|
+
if system("docker stop 'nginx-gen'", out: File::NULL)
|
128
|
+
puts "done"
|
129
|
+
puts "-----> Removing container nginx-gen ... "
|
130
|
+
if system("docker rm 'nginx-gen'", out: File::NULL)
|
131
|
+
puts "done"
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
puts "-----> Stopping container nginx ... "
|
136
|
+
if system("docker stop 'nginx'", out: File::NULL)
|
137
|
+
puts "done"
|
138
|
+
puts "-----> Removing container nginx ... "
|
139
|
+
if system("docker rm 'nginx'", out: File::NULL)
|
140
|
+
puts "done"
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
# Removing networks
|
145
|
+
puts "-----> Removing network nginx-network ... "
|
146
|
+
if system("docker network rm nginx-network", out: File::NULL)
|
147
|
+
puts "done"
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def create_htpasswd_files
|
152
|
+
htpasswd_dir = "#{Dir.pwd}/grids/nginx/htpasswd"
|
153
|
+
|
154
|
+
# Remove existing htpasswd_dir and recreate it.
|
155
|
+
FileUtils.rm_r htpasswd_dir if Dir.exist?(htpasswd_dir)
|
156
|
+
FileUtils.mkdir htpasswd_dir
|
157
|
+
FileUtils.touch "#{htpasswd_dir}/.keep"
|
158
|
+
|
159
|
+
# Add hostfiles to htpasswd_dir
|
160
|
+
get_users_from_file.each do |domain_name, users|
|
161
|
+
next unless users
|
162
|
+
|
163
|
+
file_data = ""
|
164
|
+
users.each do |user, password|
|
165
|
+
file_data += "#{user}:#{BCrypt::Password.create(password)}\n"
|
166
|
+
end
|
167
|
+
File.open("#{Dir.pwd}/grids/nginx/htpasswd/#{domain_name}", "w") { |file| file.write(file_data) }
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
private
|
172
|
+
|
173
|
+
def get_users_from_file
|
174
|
+
YAML.load_file("#{Dir.pwd}/config/users.yml") || Hash.new
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
137
178
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
ARG SMARTMACHINE_VERSION
|
2
2
|
|
3
|
-
FROM smartmachine:$SMARTMACHINE_VERSION
|
4
|
-
LABEL maintainer="
|
3
|
+
FROM smartmachine/smartengine:$SMARTMACHINE_VERSION
|
4
|
+
LABEL maintainer="plainsource <plainsource@humanmind.me>"
|
5
5
|
|
6
6
|
# FCGI Essentials
|
7
7
|
# --- IMPORTANT NOTE: This is custom built fcgiwrap package for alpine linux to account for NO_BUFFERING option.
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
|
3
|
+
# oldrev, newrev, refname are a feature of the way in which Git executes the pre-receive hook.
|
4
|
+
# See https://www.kernel.org/pub/software/scm/git/docs/githooks.html
|
5
|
+
while read oldrev newrev refname; do
|
6
|
+
if [ $(git rev-parse --is-bare-repository) = true ]; then
|
7
|
+
REPOSITORY_BASENAME=$(basename "$PWD")
|
8
|
+
REPOSITORY_BASENAME=${REPOSITORY_BASENAME%.git}
|
9
|
+
else
|
10
|
+
REPOSITORY_BASENAME=$(basename $(readlink -nf "$PWD"/..))
|
11
|
+
fi
|
12
|
+
script --quiet --return --flush --command "smartmachine grid prereceiver prereceive $REPOSITORY_BASENAME $REMOTE_USER $oldrev $newrev $refname" /home/$(whoami)/machine/apps/containers/$REPOSITORY_BASENAME/typescript
|
13
|
+
if [ "$?" -eq 10 ]; then
|
14
|
+
exit 0
|
15
|
+
fi
|
16
|
+
exit 1
|
17
|
+
done
|