smartcloud 0.1.0.beta5 → 0.2.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/smartcloud +26 -65
- data/lib/smartcloud.rb +13 -0
- data/lib/smartcloud/boot.rb +1 -76
- data/lib/smartcloud/docker.rb +40 -25
- data/lib/smartcloud/engine.rb +25 -28
- data/lib/smartcloud/engine/Dockerfile +13 -17
- data/lib/smartcloud/grids/buildpacker.rb +40 -14
- data/lib/smartcloud/grids/grid-runner/Dockerfile +1 -1
- data/lib/smartcloud/grids/grid-runner/buildpacks/rails/Dockerfile +1 -1
- data/lib/smartcloud/grids/mysql.rb +4 -1
- data/lib/smartcloud/grids/nginx.rb +4 -1
- data/lib/smartcloud/grids/runner.rb +11 -4
- data/lib/smartcloud/grids/solr.rb +12 -3
- data/lib/smartcloud/machine.rb +123 -20
- data/lib/smartcloud/ssh.rb +43 -0
- data/lib/smartcloud/templates/dotsmartcloud/bin/smartcloud.sh +9 -0
- data/lib/smartcloud/templates/dotsmartcloud/config/credentials.yml +6 -0
- data/lib/smartcloud/templates/dotsmartcloud/config/environment.rb +4 -2
- data/lib/smartcloud/templates/dotsmartcloud/config/users.yml +4 -0
- data/lib/smartcloud/templates/dotsmartcloud/tmp/.keep +0 -0
- data/lib/smartcloud/user.rb +11 -45
- metadata +7 -4
- data/lib/smartcloud/templates/dotsmartcloud/grids/grid-nginx/users.yml +0 -1
- data/lib/smartcloud/templates/machine/config/machine.yml +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9958c8ebc6f3cdf8111a9034bf70d052c5e1fcec70a23306deb953a3e81a9675
|
4
|
+
data.tar.gz: 335d928f1b65200db471517a4c8c38d32868ec24a2e188e87f6d7ef2b61338e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6951d53b56b47962fbab916f5943d20974974ba3d70e25c16e505a4ff6bda03ad30f8ef69f99ac24ebb686ea87bc4de7b39f20799ebd07dbbd4a7b522664742a
|
7
|
+
data.tar.gz: 796c0b9e7f77ef91161a4d29a46edf637782aee55014f183ef67a24fdbcfda8ee79eb832f74bac53cf8c9443e7aa08991117d0527efeeb3767a773ccf1155174
|
data/bin/smartcloud
CHANGED
@@ -2,73 +2,34 @@
|
|
2
2
|
|
3
3
|
require 'smartcloud'
|
4
4
|
|
5
|
-
|
6
|
-
Smartcloud::Boot.init
|
7
|
-
elsif !Smartcloud::Boot.initialized?
|
8
|
-
puts "Smartcloud has not been initialized. Please run command 'smartcloud init'."
|
9
|
-
exit
|
10
|
-
end
|
11
|
-
|
12
|
-
# if ARGV[0] == 'new'
|
13
|
-
# machine = Smartcloud::Machine.new
|
14
|
-
# raise "Please specify machine name" unless ARGV[1]
|
15
|
-
# machine.create(ARGV[1])
|
16
|
-
# elsif ARGV[0] == 'install'
|
17
|
-
# machine = Smartcloud::Machine.new
|
18
|
-
# machine.install_docker
|
19
|
-
# machine.install_engine
|
20
|
-
# elsif ARGV[0] == 'uninstall'
|
21
|
-
# machine = Smartcloud::Machine.new
|
22
|
-
# machine.uninstall_engine
|
23
|
-
# machine.uninstall_docker
|
24
|
-
# elsif ARGV[0] == 'run'
|
25
|
-
# machine = Smartcloud::Machine.new
|
26
|
-
# ARGV.shift
|
27
|
-
# raise "Please specify command to run" unless ARGV[0]
|
28
|
-
# machine.run(ARGV)
|
5
|
+
command = ARGV.shift
|
29
6
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
elsif ARGV[1] == 'uninstall'
|
34
|
-
Smartcloud::Docker.uninstall
|
35
|
-
end
|
36
|
-
elsif ARGV[0] == 'grids'
|
37
|
-
if ARGV[1] == 'runner'
|
38
|
-
if ARGV[2] == 'up'
|
39
|
-
Smartcloud::Grids::Runner.up
|
40
|
-
elsif ARGV[2] == 'down'
|
41
|
-
Smartcloud::Grids::Runner.down
|
42
|
-
end
|
43
|
-
elsif ARGV[1] == 'mysql'
|
44
|
-
if ARGV[2] == 'up'
|
45
|
-
Smartcloud::Grids::Mysql.up(ARGV[3])
|
46
|
-
elsif ARGV[2] == 'down'
|
47
|
-
Smartcloud::Grids::Mysql.down
|
48
|
-
end
|
49
|
-
elsif ARGV[1] == 'nginx'
|
50
|
-
if ARGV[2] == 'up'
|
51
|
-
Smartcloud::Grids::Nginx.up(ARGV[3])
|
52
|
-
elsif ARGV[2] == 'down'
|
53
|
-
Smartcloud::Grids::Nginx.down
|
54
|
-
end
|
55
|
-
elsif ARGV[1] == 'solr'
|
56
|
-
if ARGV[2] == 'up'
|
57
|
-
Smartcloud::Grids::Solr.up(ARGV[3])
|
58
|
-
elsif ARGV[2] == 'down'
|
59
|
-
Smartcloud::Grids::Solr.down
|
60
|
-
elsif ARGV[2] == 'create_core'
|
61
|
-
Smartcloud::Grids::Solr.create_core(ARGV[3])
|
62
|
-
elsif ARGV[2] == 'destroy_core'
|
63
|
-
Smartcloud::Grids::Solr.destroy_core(ARGV[3])
|
64
|
-
end
|
7
|
+
unless command == 'new'
|
8
|
+
unless Smartcloud::Machine.smartcloud_dir?
|
9
|
+
raise "This is not a smartcloud directory. Are you in the correct directory?"
|
65
10
|
end
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
11
|
+
end
|
12
|
+
|
13
|
+
if command == 'new'
|
14
|
+
raise "This is already a smartcloud directory. Are you in the correct directory?" if Smartcloud::Machine.smartcloud_dir?
|
15
|
+
raise "Please specify a machine name" if ARGV.empty?
|
16
|
+
machine = Smartcloud::Machine.new
|
17
|
+
machine.create ARGV
|
18
|
+
elsif command == 'start'
|
19
|
+
machine = Smartcloud::Machine.new
|
20
|
+
machine.start
|
21
|
+
elsif command == 'stop'
|
22
|
+
machine = Smartcloud::Machine.new
|
23
|
+
machine.stop
|
24
|
+
elsif command == 'grid'
|
25
|
+
machine = Smartcloud::Machine.new
|
26
|
+
machine.grid ARGV
|
27
|
+
elsif command == 'ssh'
|
28
|
+
machine = Smartcloud::Machine.new
|
29
|
+
machine.ssh
|
30
|
+
elsif command == 'sync'
|
31
|
+
machine = Smartcloud::Machine.new
|
32
|
+
machine.sync
|
72
33
|
else
|
73
34
|
puts "Specify a command to execute."
|
74
35
|
end
|
data/lib/smartcloud.rb
CHANGED
@@ -1,10 +1,23 @@
|
|
1
1
|
require "ostruct"
|
2
|
+
require "yaml"
|
2
3
|
|
3
4
|
# The main Smartcloud driver
|
4
5
|
module Smartcloud
|
5
6
|
def self.config
|
6
7
|
@@config ||= OpenStruct.new
|
7
8
|
end
|
9
|
+
|
10
|
+
def self.credentials
|
11
|
+
@@credentials ||= OpenStruct.new(Smartcloud.transform_keys_to_symbols(YAML.load_file("#{Dir.pwd}/config/credentials.yml")))
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def self.transform_keys_to_symbols(value)
|
17
|
+
return value if not value.is_a?(Hash)
|
18
|
+
hash = value.inject({}){|memo,(k,v)| memo[k.to_sym] = self.transform_keys_to_symbols(v); memo}
|
19
|
+
return hash
|
20
|
+
end
|
8
21
|
end
|
9
22
|
|
10
23
|
Smartcloud.config.root_path = File.expand_path('../..', __FILE__)
|
data/lib/smartcloud/boot.rb
CHANGED
@@ -1,87 +1,12 @@
|
|
1
|
-
require 'securerandom'
|
2
|
-
require "tempfile"
|
3
|
-
|
4
1
|
# The main Smartcloud Boot driver
|
5
2
|
module Smartcloud
|
6
3
|
class Boot < Smartcloud::Base
|
7
4
|
def initialize
|
8
5
|
end
|
9
|
-
|
10
|
-
def self.init
|
11
|
-
# Copy Template for dotsmartcloud
|
12
|
-
unless self.initialized?
|
13
|
-
puts "Initializing Smartcloud ...\n\n"
|
14
|
-
|
15
|
-
begin
|
16
|
-
print "Enter top-level apps domain to be used for subdomains of your apps. [Recommended: yourdomain.com]: "
|
17
|
-
config_apps_domain = STDIN.gets.chomp
|
18
|
-
raise if config_apps_domain.empty?
|
19
|
-
rescue
|
20
|
-
retry
|
21
|
-
end
|
22
|
-
|
23
|
-
begin
|
24
|
-
print "Enter sysadmin email id. [Recommended: admin@#{config_apps_domain}]: "
|
25
|
-
config_sysadmin_email = STDIN.gets.chomp
|
26
|
-
raise if config_sysadmin_email.empty?
|
27
|
-
rescue
|
28
|
-
retry
|
29
|
-
end
|
30
|
-
|
31
|
-
begin
|
32
|
-
print "Enter username for your git grid user. [Recommended: git@#{config_apps_domain}]: "
|
33
|
-
username = STDIN.gets.chomp
|
34
|
-
raise if username.empty?
|
35
|
-
rescue
|
36
|
-
retry
|
37
|
-
end
|
38
|
-
|
39
|
-
print "Enter password for your git grid user. (leave blank to generate automatically) [Recommended: Minimum 8 characters with numbers and symbols]: "
|
40
|
-
password = STDIN.gets.chomp
|
41
|
-
if password.empty?
|
42
|
-
password = SecureRandom.base64(8)
|
43
|
-
end
|
44
|
-
|
45
|
-
# Copy dotsmartcloud template to user home directory
|
46
|
-
FileUtils.cp_r("#{Smartcloud.config.root_path}/lib/smartcloud/templates/dotsmartcloud", "#{Smartcloud.config.user_home_path}/.smartcloud")
|
47
|
-
|
48
|
-
# modifying environment.rb file
|
49
|
-
tempFile = Tempfile.new("#{Smartcloud.config.user_home_path}/.smartcloud/config/environmentTemp.rb")
|
50
|
-
File.open("#{Smartcloud.config.user_home_path}/.smartcloud/config/environment.rb", "r").each_line do |line|
|
51
|
-
if line =~ /Smartcloud.config.apps_domain/
|
52
|
-
tempFile.puts "Smartcloud.config.apps_domain = \"#{config_apps_domain}\""
|
53
|
-
elsif line =~ /Smartcloud.config.git_domain/
|
54
|
-
tempFile.puts "Smartcloud.config.git_domain = \"git.#{config_apps_domain}\""
|
55
|
-
elsif line =~ /Smartcloud.config.sysadmin_email/
|
56
|
-
tempFile.puts "Smartcloud.config.sysadmin_email = \"#{config_sysadmin_email}\""
|
57
|
-
else
|
58
|
-
tempFile.puts line
|
59
|
-
end
|
60
|
-
end
|
61
|
-
tempFile.close
|
62
|
-
FileUtils.mv(tempFile.path, "#{Smartcloud.config.user_home_path}/.smartcloud/config/environment.rb")
|
63
|
-
|
64
|
-
# Reload the updated environment.rb file as it is required by methods below
|
65
|
-
require "#{Smartcloud.config.user_home_path}/.smartcloud/config/environment.rb"
|
66
|
-
|
67
|
-
# creating user for git grid at config.git_domain
|
68
|
-
Smartcloud::User.create(Smartcloud.config.git_domain, username, password)
|
69
|
-
|
70
|
-
puts "\nIMPORTANT NOTE: Please ensure that the required top-level apps domain '#{Smartcloud.config.apps_domain}' and git domain '#{Smartcloud.config.git_domain}' is pointing to this server using DNS Records before proceeding."
|
71
|
-
puts "IMPORTANT NOTE: Your git grid password is #{password} for username #{username}"
|
72
|
-
|
73
|
-
puts "\nInitializing Smartcloud ... done"
|
74
|
-
else
|
75
|
-
puts "Already Initialized. Please go to #{Smartcloud.config.user_home_path}/.smartcloud/config to make configuration changes."
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
def self.initialized?
|
80
|
-
Dir.exist? "#{Smartcloud.config.user_home_path}/.smartcloud"
|
81
|
-
end
|
82
6
|
end
|
83
7
|
end
|
84
8
|
|
9
|
+
require 'smartcloud/ssh'
|
85
10
|
require 'smartcloud/machine'
|
86
11
|
|
87
12
|
require 'smartcloud/engine'
|
data/lib/smartcloud/docker.rb
CHANGED
@@ -13,22 +13,30 @@ module Smartcloud
|
|
13
13
|
# Arguments:
|
14
14
|
# none
|
15
15
|
def self.install
|
16
|
+
ssh = Smartcloud::SSH.new
|
17
|
+
|
16
18
|
puts "-----> Installing Docker"
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
19
|
+
commands = [
|
20
|
+
"sudo apt-get update",
|
21
|
+
"sudo apt-get install apt-transport-https ca-certificates curl software-properties-common",
|
22
|
+
"curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -",
|
23
|
+
"sudo apt-key fingerprint 0EBFCD88",
|
24
|
+
"sudo add-apt-repository \"deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable\"",
|
25
|
+
"sudo apt-get update",
|
26
|
+
"sudo apt-get install docker-ce",
|
27
|
+
"sudo usermod -aG docker $USER",
|
28
|
+
"docker run --rm hello-world"
|
29
|
+
]
|
30
|
+
ssh.run commands
|
26
31
|
|
27
32
|
puts "-----> Installing Docker Compose"
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
33
|
+
commands = [
|
34
|
+
"sudo curl -L --fail https://github.com/docker/compose/releases/download/1.24.0/run.sh -o /usr/local/bin/docker-compose",
|
35
|
+
"sudo chmod +x /usr/local/bin/docker-compose",
|
36
|
+
"docker-compose --version",
|
37
|
+
"sudo curl -L https://raw.githubusercontent.com/docker/compose/1.24.0/contrib/completion/bash/docker-compose -o /etc/bash_completion.d/docker-compose"
|
38
|
+
]
|
39
|
+
ssh.run commands
|
32
40
|
|
33
41
|
self.add_ufw_rules
|
34
42
|
|
@@ -44,12 +52,17 @@ module Smartcloud
|
|
44
52
|
# Arguments:
|
45
53
|
# none
|
46
54
|
def self.uninstall
|
55
|
+
ssh = Smartcloud::SSH.new
|
56
|
+
|
47
57
|
puts "-----> Uninstalling Docker Compose"
|
48
|
-
|
58
|
+
ssh.run "sudo rm /usr/local/bin/docker-compose"
|
49
59
|
|
50
60
|
puts "-----> Uninstalling Docker"
|
51
|
-
|
52
|
-
|
61
|
+
commands = [
|
62
|
+
"sudo apt-get purge docker-ce",
|
63
|
+
"sudo rm -rf /var/lib/docker"
|
64
|
+
]
|
65
|
+
ssh.run commands
|
53
66
|
|
54
67
|
self.remove_ufw_rules
|
55
68
|
|
@@ -57,15 +70,6 @@ module Smartcloud
|
|
57
70
|
puts "-----> You must delete any edited configuration files manually."
|
58
71
|
end
|
59
72
|
|
60
|
-
def self.running?
|
61
|
-
if system("docker info", [:out, :err] => File::NULL)
|
62
|
-
true
|
63
|
-
else
|
64
|
-
puts "Error: Docker daemon is not running. Have you installed docker? Please ensure docker daemon is running and try again."
|
65
|
-
false
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
73
|
def self.add_ufw_rules
|
70
74
|
puts '-----> Add the following rules to the end of the file /etc/ufw/after.rules and reload ufw using - sudo ufw reload'
|
71
75
|
puts '# BEGIN UFW AND DOCKER
|
@@ -116,5 +120,16 @@ module Smartcloud
|
|
116
120
|
# system("sed '/^# BEGIN UFW AND DOCKER/,/^# END UFW AND DOCKER/d' '/etc/ufw/after.rules'")
|
117
121
|
# system("sudo ufw reload")
|
118
122
|
end
|
123
|
+
|
124
|
+
# Below methods are non ssh methods and should be executed on the server only.
|
125
|
+
|
126
|
+
def self.running?
|
127
|
+
if system("docker info", [:out, :err] => File::NULL)
|
128
|
+
true
|
129
|
+
else
|
130
|
+
puts "Error: Docker daemon is not running. Have you installed docker? Please ensure docker daemon is running and try again."
|
131
|
+
false
|
132
|
+
end
|
133
|
+
end
|
119
134
|
end
|
120
135
|
end
|
data/lib/smartcloud/engine.rb
CHANGED
@@ -4,35 +4,32 @@ module Smartcloud
|
|
4
4
|
def initialize
|
5
5
|
end
|
6
6
|
|
7
|
-
def
|
8
|
-
|
9
|
-
|
10
|
-
# if system("docker image build -t smartcloud \
|
11
|
-
# --build-arg DOCKER_GID=`getent group docker | cut -d: -f3` \
|
12
|
-
# --build-arg USER_UID=`id -u` \
|
13
|
-
# --build-arg USER_NAME=`id -un` \
|
14
|
-
# #{Smartcloud.config.root_path}/lib/smartcloud/engine")
|
15
|
-
# puts "done"
|
16
|
-
# end
|
17
|
-
# end
|
7
|
+
def self.install
|
8
|
+
ssh = Smartcloud::SSH.new
|
9
|
+
machine = Smartcloud::Machine.new
|
18
10
|
|
19
|
-
|
20
|
-
#
|
21
|
-
# --build-arg USER_GID=`id -g` \
|
22
|
-
# --build-arg USER_NAME=`id -un` \
|
23
|
-
# .
|
11
|
+
system("mkdir -p ./tmp/engine")
|
12
|
+
system("cp #{Smartcloud.config.root_path}/lib/smartcloud/engine/Dockerfile ./tmp/engine/Dockerfile")
|
24
13
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
14
|
+
machine.sync first_sync: true
|
15
|
+
|
16
|
+
puts "-----> Creating image smartcloud ... "
|
17
|
+
ssh.run "docker image build -t smartcloud \
|
18
|
+
--build-arg DOCKER_GID=`getent group docker | cut -d: -f3` \
|
19
|
+
--build-arg USER_UID=`id -u` \
|
20
|
+
--build-arg USER_NAME=`id -un` \
|
21
|
+
~/.smartcloud/tmp/engine"
|
22
|
+
|
23
|
+
puts "-----> Adding smartcloud to PATH ... "
|
24
|
+
ssh.run "chmod +x ~/.smartcloud/bin/smartcloud.sh && sudo ln -sf ~/.smartcloud/bin/smartcloud.sh /usr/local/bin/smartcloud"
|
25
|
+
system("rm ./tmp/engine/Dockerfile")
|
26
|
+
|
27
|
+
machine.sync
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.uninstall
|
31
|
+
ssh.run "sudo rm /usr/local/bin/smartcloud"
|
32
|
+
ssh.run "docker rmi smartcloud"
|
36
33
|
end
|
37
34
|
end
|
38
|
-
end
|
35
|
+
end
|
@@ -1,27 +1,23 @@
|
|
1
1
|
FROM ruby:2.6.4-alpine3.10
|
2
|
-
|
2
|
+
LABEL maintainer="Timeboard <hello@timeboard.me>"
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
# Setting up group and user
|
8
|
-
# - envs
|
4
|
+
# User
|
5
|
+
# --- Fix to change gid of 999 to 99 so that addgroup is free to create a group with 999 as gid
|
9
6
|
ARG USER_NAME
|
10
7
|
ARG USER_UID
|
11
8
|
ARG DOCKER_GID
|
12
|
-
# - fix to change gid of 999 to 99 so that addgroup is free to create a group with 999 as gid
|
13
|
-
# - Create group & user. Then add user to group
|
14
9
|
RUN sed -i "s/999/99/" /etc/group && \
|
15
|
-
adduser --disabled-password --gecos "" --uid $USER_UID $USER_NAME && \
|
16
|
-
addgroup --gid $DOCKER_GID "docker" && adduser $USER_NAME docker
|
10
|
+
adduser --disabled-password --gecos "" --uid "$USER_UID" "$USER_NAME" && \
|
11
|
+
addgroup --gid "$DOCKER_GID" "docker" && adduser "$USER_NAME" "docker"
|
12
|
+
|
13
|
+
# Docker
|
14
|
+
RUN apk add --update docker && \
|
15
|
+
rm -rf /var/cache/apk/*
|
17
16
|
|
17
|
+
# Privileges
|
18
18
|
USER "$USER_NAME"
|
19
|
-
WORKDIR "/home/$USER_NAME/.smartcloud"
|
20
19
|
|
21
|
-
#
|
22
|
-
RUN
|
23
|
-
gem install --no-document smartcloud\n\
|
24
|
-
exec smartcloud "$@"' >> "/home/$(whoami)/entrypoint"; chmod +x "/home/$(whoami)/entrypoint"
|
20
|
+
# Gems
|
21
|
+
RUN gem install --no-document smartcloud -v 0.1.0
|
25
22
|
|
26
|
-
|
27
|
-
ENTRYPOINT "/home/$(whoami)/entrypoint"
|
23
|
+
ENTRYPOINT ["smartcloud"]
|
@@ -17,11 +17,20 @@ module Smartcloud
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def pack_rails
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
if File.exist? "tmp/smartcloud/packed"
|
21
|
+
begin
|
22
|
+
pid = File.read('tmp/smartcloud/packed').to_i
|
23
|
+
Process.kill('QUIT', pid)
|
24
|
+
rescue Errno::ESRCH # No such process
|
25
|
+
end
|
26
|
+
exec "bundle", "exec", "puma", "--config", "config/puma.rb"
|
27
|
+
else
|
28
|
+
return unless bundle_install?
|
29
|
+
return unless precompile_assets?
|
30
|
+
return unless test_web_server?
|
23
31
|
|
24
|
-
|
32
|
+
exit 0
|
33
|
+
end
|
25
34
|
end
|
26
35
|
|
27
36
|
# Perform bundle install
|
@@ -64,17 +73,34 @@ module Smartcloud
|
|
64
73
|
end
|
65
74
|
end
|
66
75
|
|
67
|
-
# Perform
|
68
|
-
def
|
69
|
-
logger.
|
70
|
-
|
71
|
-
#
|
72
|
-
FileUtils.
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
+
# Perform testing of web server
|
77
|
+
def test_web_server?
|
78
|
+
logger.info "Setting up Web Server ..."
|
79
|
+
|
80
|
+
# tmp folder
|
81
|
+
FileUtils.mkdir_p("tmp/smartcloud")
|
82
|
+
FileUtils.rm_f("tmp/smartcloud/packed")
|
83
|
+
|
84
|
+
# Spawn Process
|
85
|
+
pid = Process.spawn("bundle", "exec", "puma", "--config", "config/puma.rb", out: File::NULL)
|
86
|
+
Process.detach(pid)
|
87
|
+
|
88
|
+
# Sleep
|
89
|
+
sleep 5
|
90
|
+
|
91
|
+
# Check PID running
|
92
|
+
status = nil
|
93
|
+
begin
|
94
|
+
Process.kill(0, pid)
|
95
|
+
system("echo '#{pid}' > tmp/smartcloud/packed")
|
96
|
+
status = true
|
97
|
+
rescue Errno::ESRCH # No such process
|
98
|
+
logger.info "Web Server could not start"
|
99
|
+
status = false
|
76
100
|
end
|
77
|
-
|
101
|
+
|
102
|
+
# Return status
|
103
|
+
return status
|
78
104
|
end
|
79
105
|
|
80
106
|
def set_logger_formatter_arrow
|
@@ -5,7 +5,10 @@ module Smartcloud
|
|
5
5
|
def initialize
|
6
6
|
end
|
7
7
|
|
8
|
-
def self.up(
|
8
|
+
def self.up(*args)
|
9
|
+
args.flatten!
|
10
|
+
exposed = args.empty? ? '' : args.shift
|
11
|
+
|
9
12
|
if Smartcloud::Docker.running?
|
10
13
|
# Creating networks
|
11
14
|
unless system("docker network inspect mysql-network", [:out, :err] => File::NULL)
|
@@ -293,6 +293,7 @@ module Smartcloud
|
|
293
293
|
# Setup rails env
|
294
294
|
env_path = "#{container_path}/env"
|
295
295
|
system("grep -q '^## Rails' #{env_path} || echo '## Rails' >> #{env_path}")
|
296
|
+
system("grep -q '^MALLOC_ARENA_MAX=' #{env_path} || echo '# MALLOC_ARENA_MAX=2' >> #{env_path}")
|
296
297
|
system("grep -q '^RAILS_ENV=' #{env_path} || echo 'RAILS_ENV=production' >> #{env_path}")
|
297
298
|
system("grep -q '^RACK_ENV=' #{env_path} || echo 'RACK_ENV=production' >> #{env_path}")
|
298
299
|
system("grep -q '^RAILS_LOG_TO_STDOUT=' #{env_path} || echo 'RAILS_LOG_TO_STDOUT=enabled' >> #{env_path}")
|
@@ -323,6 +324,7 @@ module Smartcloud
|
|
323
324
|
--volume='#{container_path}/app/public:/app/public' \
|
324
325
|
--volume='#{container_path}/app/node_modules:/app/node_modules' \
|
325
326
|
--restart='always' \
|
327
|
+
--init \
|
326
328
|
--network='nginx-network' \
|
327
329
|
smartcloud/buildpacks/rails", out: File::NULL)
|
328
330
|
|
@@ -330,10 +332,15 @@ module Smartcloud
|
|
330
332
|
system("docker network connect mysql-network #{new_container}")
|
331
333
|
|
332
334
|
if system("docker start --attach #{new_container}")
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
335
|
+
logger.debug "Starting Web Server ..."
|
336
|
+
if system("docker start #{new_container}", out: File::NULL)
|
337
|
+
sleep 5
|
338
|
+
logger.info "Web Server started successfully."
|
339
|
+
self.stop_app(old_container)
|
340
|
+
self.clean_up(container_path)
|
341
|
+
logger.info "Launched Application ... Success."
|
342
|
+
exit 10
|
343
|
+
end
|
337
344
|
else
|
338
345
|
self.stop_app("#{new_container}")
|
339
346
|
end
|
@@ -5,7 +5,10 @@ module Smartcloud
|
|
5
5
|
def initialize
|
6
6
|
end
|
7
7
|
|
8
|
-
def self.up(
|
8
|
+
def self.up(*args)
|
9
|
+
args.flatten!
|
10
|
+
exposed = args.empty? ? '' : args.shift
|
11
|
+
|
9
12
|
if Smartcloud::Docker.running?
|
10
13
|
# Creating networks
|
11
14
|
unless system("docker network inspect solr-network", [:out, :err] => File::NULL)
|
@@ -59,7 +62,10 @@ module Smartcloud
|
|
59
62
|
end
|
60
63
|
end
|
61
64
|
|
62
|
-
def self.create_core(
|
65
|
+
def self.create_core(*args)
|
66
|
+
args.flatten!
|
67
|
+
corename = args.empty? ? '' : args.shift
|
68
|
+
|
63
69
|
if Smartcloud::Docker.running?
|
64
70
|
puts "-----> Creating core #{corename} ... "
|
65
71
|
if system("docker exec -it --user=solr solr solr create_core -c #{corename}")
|
@@ -77,7 +83,10 @@ module Smartcloud
|
|
77
83
|
end
|
78
84
|
end
|
79
85
|
|
80
|
-
def self.destroy_core(
|
86
|
+
def self.destroy_core(*args)
|
87
|
+
args.flatten!
|
88
|
+
corename = args.empty? ? '' : args.shift
|
89
|
+
|
81
90
|
if Smartcloud::Docker.running?
|
82
91
|
puts "-----> Removing core #{corename} ... "
|
83
92
|
if system("docker exec -it --user=solr solr solr delete -c #{corename}")
|
data/lib/smartcloud/machine.rb
CHANGED
@@ -6,6 +6,69 @@ module Smartcloud
|
|
6
6
|
def initialize
|
7
7
|
end
|
8
8
|
|
9
|
+
def create(*args)
|
10
|
+
args.flatten!
|
11
|
+
|
12
|
+
name = args.shift
|
13
|
+
FileUtils.mkdir name
|
14
|
+
FileUtils.cp_r "#{Smartcloud.config.root_path}/lib/smartcloud/templates/dotsmartcloud/.", "#{name}"
|
15
|
+
puts "New machine #{name} has been created."
|
16
|
+
end
|
17
|
+
|
18
|
+
def start
|
19
|
+
Smartcloud::User.create_htpasswd_files
|
20
|
+
Smartcloud::Docker.install
|
21
|
+
Smartcloud::Engine.install
|
22
|
+
end
|
23
|
+
|
24
|
+
def stop
|
25
|
+
Smartcloud::Engine.uninstall
|
26
|
+
Smartcloud::Docker.uninstall
|
27
|
+
end
|
28
|
+
|
29
|
+
def grid(*args)
|
30
|
+
args.flatten!
|
31
|
+
name = "Smartcloud::Grids::#{args.shift.capitalize}"
|
32
|
+
action = args.shift.to_sym
|
33
|
+
|
34
|
+
args.empty? ? Object.const_get(name).public_send(action) : Object.const_get(name).public_send(action, args)
|
35
|
+
|
36
|
+
# if ARGV[1] == 'runner'
|
37
|
+
# if ARGV[2] == 'up'
|
38
|
+
# Smartcloud::Grids::Runner.up
|
39
|
+
# elsif ARGV[2] == 'down'
|
40
|
+
# Smartcloud::Grids::Runner.down
|
41
|
+
# end
|
42
|
+
# elsif ARGV[1] == 'mysql'
|
43
|
+
# if ARGV[2] == 'up'
|
44
|
+
# Smartcloud::Grids::Mysql.up(ARGV[3])
|
45
|
+
# elsif ARGV[2] == 'down'
|
46
|
+
# Smartcloud::Grids::Mysql.down
|
47
|
+
# end
|
48
|
+
# elsif ARGV[1] == 'nginx'
|
49
|
+
# if ARGV[2] == 'up'
|
50
|
+
# Smartcloud::Grids::Nginx.up(ARGV[3])
|
51
|
+
# elsif ARGV[2] == 'down'
|
52
|
+
# Smartcloud::Grids::Nginx.down
|
53
|
+
# end
|
54
|
+
# elsif ARGV[1] == 'solr'
|
55
|
+
# if ARGV[2] == 'up'
|
56
|
+
# Smartcloud::Grids::Solr.up(ARGV[3])
|
57
|
+
# elsif ARGV[2] == 'down'
|
58
|
+
# Smartcloud::Grids::Solr.down
|
59
|
+
# elsif ARGV[2] == 'create_core'
|
60
|
+
# Smartcloud::Grids::Solr.create_core(ARGV[3])
|
61
|
+
# elsif ARGV[2] == 'destroy_core'
|
62
|
+
# Smartcloud::Grids::Solr.destroy_core(ARGV[3])
|
63
|
+
# end
|
64
|
+
# end
|
65
|
+
end
|
66
|
+
|
67
|
+
def ssh
|
68
|
+
ssh = Smartcloud::SSH.new
|
69
|
+
ssh.login
|
70
|
+
end
|
71
|
+
|
9
72
|
def getting_started
|
10
73
|
# puts 'You may be prompted to make a menu selection when the Grub package is updated on Ubuntu. If prompted, select keep the local version currently installed.'
|
11
74
|
|
@@ -62,25 +125,65 @@ module Smartcloud
|
|
62
125
|
# sudo fail2ban-client status
|
63
126
|
end
|
64
127
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
128
|
+
def self.smartcloud_dir?
|
129
|
+
File.file?("./bin/smartcloud.sh")
|
130
|
+
end
|
131
|
+
|
132
|
+
def sync(first_sync = false)
|
133
|
+
puts "-----> Syncing smartcloud ... "
|
134
|
+
return sync_push if first_sync
|
135
|
+
|
136
|
+
unless block_given?
|
137
|
+
sync_pull && sync_push
|
138
|
+
else
|
139
|
+
sync_pull
|
140
|
+
yield
|
141
|
+
sync_push
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
private
|
146
|
+
|
147
|
+
def sync_pull
|
148
|
+
system("rsync -azumv --delete --include=*/ --include={#{sync_pull_files_list}} --exclude=* -e ssh #{Smartcloud.credentials.machine[:username]}@#{Smartcloud.credentials.machine[:host]}:~/.smartcloud/ .")
|
149
|
+
end
|
150
|
+
|
151
|
+
def sync_push
|
152
|
+
system("rsync -azumv --delete --include=*/ --include={#{sync_push_files_list}} --exclude={#{excluded_sync_files_list}} --exclude={#{sync_pull_files_list}} -e ssh ./ #{Smartcloud.credentials.machine[:username]}@#{Smartcloud.credentials.machine[:host]}:~/.smartcloud")
|
153
|
+
end
|
154
|
+
|
155
|
+
def excluded_sync_files_list
|
156
|
+
files = [
|
157
|
+
'config/credentials.yml',
|
158
|
+
'config/users.yml'
|
159
|
+
]
|
160
|
+
files.join(',')
|
161
|
+
end
|
162
|
+
|
163
|
+
def sync_pull_files_list
|
164
|
+
files = [
|
165
|
+
'grids/grid-mysql/data/***',
|
166
|
+
'grids/grid-nginx/certificates/***',
|
167
|
+
'grids/grid-runner/apps/***',
|
168
|
+
'grids/grid-solr/data/***',
|
169
|
+
]
|
170
|
+
files.join(',')
|
171
|
+
end
|
172
|
+
|
173
|
+
def sync_push_files_list
|
174
|
+
files = [
|
175
|
+
'grids/grid-mysql/data/.keep',
|
176
|
+
'grids/grid-nginx/certificates/.keep',
|
177
|
+
'grids/grid-runner/apps/containers/.keep',
|
178
|
+
'grids/grid-runner/apps/repositories/.keep',
|
179
|
+
'grids/grid-solr/data/.keep',
|
180
|
+
'grids/grid-solr/data/README.txt',
|
181
|
+
'grids/grid-solr/data/solr.xml',
|
182
|
+
'grids/grid-solr/data/zoo.cfg',
|
183
|
+
'grids/grid-solr/data/configsets/***',
|
184
|
+
'grids/grid-solr/data/lib/***',
|
185
|
+
]
|
186
|
+
files.join(',')
|
187
|
+
end
|
85
188
|
end
|
86
189
|
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "net/ssh"
|
2
|
+
|
3
|
+
# The main Smartcloud SSH driver
|
4
|
+
module Smartcloud
|
5
|
+
class SSH < Smartcloud::Base
|
6
|
+
def initialize
|
7
|
+
end
|
8
|
+
|
9
|
+
def run(*commands)
|
10
|
+
commands.flatten!
|
11
|
+
Net::SSH.start(Smartcloud.credentials.machine[:host], Smartcloud.credentials.machine[:username], { port: Smartcloud.credentials.machine[:port], password: Smartcloud.credentials.machine[:password] }) do |ssh|
|
12
|
+
channel = ssh.open_channel do |channel, success|
|
13
|
+
channel.request_pty do |channel, success|
|
14
|
+
channel.exec commands.join(';') do |channel, success|
|
15
|
+
raise "Could not execute command" unless success
|
16
|
+
|
17
|
+
channel.on_data do |channel, data|
|
18
|
+
$stdout.print data
|
19
|
+
|
20
|
+
if data =~ /^\[sudo\] password for /
|
21
|
+
channel.send_data "#{Smartcloud.credentials.machine[:password]}\n"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
channel.on_extended_data do |channel, type, data|
|
26
|
+
$stderr.print data
|
27
|
+
end
|
28
|
+
|
29
|
+
channel.on_close do |channel|
|
30
|
+
# puts "done!"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
channel.wait
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def login
|
40
|
+
exec "ssh #{Smartcloud.credentials.machine[:username]}@#{Smartcloud.credentials.machine[:host]}"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -1,12 +1,14 @@
|
|
1
1
|
# Be sure to restart your server when you modify this file.
|
2
2
|
|
3
|
-
#
|
3
|
+
# => NOTE: Ensure that the specified top-level domains are pointing to this server ip address using DNS records.
|
4
|
+
|
5
|
+
# Top-level naked domain to be used for subdomains of apps.
|
4
6
|
Smartcloud.config.apps_domain = "yourdomain.com"
|
5
7
|
|
6
8
|
# domain to be used for git runner
|
7
9
|
Smartcloud.config.git_domain = "git.yourdomain.com"
|
8
10
|
|
9
|
-
#
|
11
|
+
# Sysadmin email id.
|
10
12
|
Smartcloud.config.sysadmin_email = "admin@yourdomain.com"
|
11
13
|
|
12
14
|
# letsencrypt test boolean to be used
|
File without changes
|
data/lib/smartcloud/user.rb
CHANGED
@@ -7,50 +7,9 @@ module Smartcloud
|
|
7
7
|
def initialize
|
8
8
|
end
|
9
9
|
|
10
|
-
def self.create(hostname, username, password)
|
11
|
-
if hostname.nil? || hostname.empty? || username.nil? || username.empty? || password.nil? || password.empty?
|
12
|
-
puts "One of hostname, username, password missing."
|
13
|
-
else
|
14
|
-
puts "-----> Creating User ... "
|
15
|
-
|
16
|
-
salt = Base64.encode64((("a".."z").to_a + ("A".."Z").to_a + (0..9).to_a).shuffle[0..7].join)
|
17
|
-
new_user = { "#{hostname}" => { "#{username}" => "#{password.crypt(salt)}" } }
|
18
|
-
users = self.get_users_from_file
|
19
|
-
users.merge!(new_user) { |hostname, curr_user_vals, new_user_val| (curr_user_vals && new_user_val) ? curr_user_vals.merge(new_user_val) : new_user_val }
|
20
|
-
self.set_users_to_file(users)
|
21
|
-
|
22
|
-
puts "-----> Creating User ... done"
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
# def self.destroy(hostname, username)
|
27
|
-
# if hostname.nil? || hostname.empty? || username.nil? || username.empty?
|
28
|
-
# puts "One of hostname, username missing."
|
29
|
-
# else
|
30
|
-
# puts "-----> Removing User ... "
|
31
|
-
#
|
32
|
-
# users = self.get_users_from_file
|
33
|
-
# # users.merge!(new_user)
|
34
|
-
# self.set_users_to_file(users)
|
35
|
-
#
|
36
|
-
# puts "-----> Removing User ... done"
|
37
|
-
# end
|
38
|
-
# end
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
|
-
def self.get_users_from_file
|
43
|
-
YAML.load_file("#{Smartcloud.config.user_home_path}/.smartcloud/grids/grid-nginx/users.yml") || Hash.new
|
44
|
-
end
|
45
|
-
|
46
|
-
def self.set_users_to_file(users)
|
47
|
-
File.open("#{Smartcloud.config.user_home_path}/.smartcloud/grids/grid-nginx/users.yml", "w") { |file| file.write(users.to_yaml) }
|
48
|
-
self.create_htpasswd_files
|
49
|
-
end
|
50
|
-
|
51
10
|
def self.create_htpasswd_files
|
52
|
-
htpasswd_dirpath = "#{
|
53
|
-
|
11
|
+
htpasswd_dirpath = "#{Dir.pwd}/grids/grid-nginx/htpasswd"
|
12
|
+
|
54
13
|
# Remove existing htpasswd_dirpath
|
55
14
|
FileUtils.rm_r htpasswd_dirpath if Dir.exist?(htpasswd_dirpath)
|
56
15
|
|
@@ -63,10 +22,17 @@ module Smartcloud
|
|
63
22
|
|
64
23
|
file_data = ""
|
65
24
|
users.each do |user, password|
|
66
|
-
|
25
|
+
salt = Base64.encode64((("a".."z").to_a + ("A".."Z").to_a + (0..9).to_a).shuffle[0..7].join)
|
26
|
+
file_data += "#{user}:#{password.crypt(salt)}\n"
|
67
27
|
end
|
68
|
-
File.open("#{
|
28
|
+
File.open("#{Dir.pwd}/grids/grid-nginx/htpasswd/#{hostname}", "w") { |file| file.write(file_data) }
|
69
29
|
end
|
70
30
|
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def self.get_users_from_file
|
35
|
+
YAML.load_file("#{Dir.pwd}/config/users.yml") || Hash.new
|
36
|
+
end
|
71
37
|
end
|
72
38
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smartcloud
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0.beta1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Timeboard
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: net-ssh
|
@@ -70,12 +70,15 @@ files:
|
|
70
70
|
- lib/smartcloud/grids/solr.rb
|
71
71
|
- lib/smartcloud/logger.rb
|
72
72
|
- lib/smartcloud/machine.rb
|
73
|
+
- lib/smartcloud/ssh.rb
|
74
|
+
- lib/smartcloud/templates/dotsmartcloud/bin/smartcloud.sh
|
75
|
+
- lib/smartcloud/templates/dotsmartcloud/config/credentials.yml
|
73
76
|
- lib/smartcloud/templates/dotsmartcloud/config/environment.rb
|
77
|
+
- lib/smartcloud/templates/dotsmartcloud/config/users.yml
|
74
78
|
- lib/smartcloud/templates/dotsmartcloud/grids/grid-buildpacker/.keep
|
75
79
|
- lib/smartcloud/templates/dotsmartcloud/grids/grid-mysql/data/.keep
|
76
80
|
- lib/smartcloud/templates/dotsmartcloud/grids/grid-nginx/certificates/.keep
|
77
81
|
- lib/smartcloud/templates/dotsmartcloud/grids/grid-nginx/htpasswd/.keep
|
78
|
-
- lib/smartcloud/templates/dotsmartcloud/grids/grid-nginx/users.yml
|
79
82
|
- lib/smartcloud/templates/dotsmartcloud/grids/grid-runner/apps/containers/.keep
|
80
83
|
- lib/smartcloud/templates/dotsmartcloud/grids/grid-runner/apps/repositories/.keep
|
81
84
|
- lib/smartcloud/templates/dotsmartcloud/grids/grid-runner/pre-receive
|
@@ -239,7 +242,7 @@ files:
|
|
239
242
|
- lib/smartcloud/templates/dotsmartcloud/grids/grid-solr/data/lib/.keep
|
240
243
|
- lib/smartcloud/templates/dotsmartcloud/grids/grid-solr/data/solr.xml
|
241
244
|
- lib/smartcloud/templates/dotsmartcloud/grids/grid-solr/data/zoo.cfg
|
242
|
-
- lib/smartcloud/templates/
|
245
|
+
- lib/smartcloud/templates/dotsmartcloud/tmp/.keep
|
243
246
|
- lib/smartcloud/user.rb
|
244
247
|
homepage: https://github.com/timeboardme/smartcloud
|
245
248
|
licenses:
|
@@ -1 +0,0 @@
|
|
1
|
-
---
|