rumination 0.12.15 → 0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/rumination/deploy/base.rb +1 -93
- data/lib/rumination/deploy/class_methods.rb +37 -16
- data/lib/rumination/deploy.rb +1 -0
- data/lib/rumination/tasks/deploy.rake +83 -29
- data/lib/rumination/tasks/with_hash_puts.rake +14 -0
- data/lib/rumination/version.rb +1 -1
- data/lib/rumination.rb +3 -3
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f37ff443ac4ef4093c22b5fcf6d541433c0e6fc6
|
4
|
+
data.tar.gz: 884ba6986f9a85d092a58825e5916db578979e9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c59350b7d85331d45617617635047d5ab4ffc300e01566c070eceaa1b9a863a4efb9fbe41f44544cd81be8afca00fbbdf4dbb5dba45d24770ceb85733dbbabf
|
7
|
+
data.tar.gz: 7d9a018ce6310d3c12d03aa3f54ade2c765fad9622e41a7bd961f919306bd454d77105b30ea6c6bb8b984293a3eb993074295cbb970b987bf57708f89105237e
|
data/.gitignore
CHANGED
@@ -3,89 +3,12 @@ require "dotenv/parser"
|
|
3
3
|
require "active_support/core_ext/module/delegation"
|
4
4
|
require "active_support/core_ext/object/blank"
|
5
5
|
require_relative "../docker_compose"
|
6
|
-
require_relative "../generate"
|
7
6
|
|
8
7
|
module Rumination
|
9
8
|
module Deploy
|
10
|
-
Base
|
9
|
+
class Base
|
11
10
|
delegate :config, to: Deploy
|
12
11
|
|
13
|
-
def initialize *args
|
14
|
-
super
|
15
|
-
load_application_config_if_exists
|
16
|
-
load_target_config
|
17
|
-
end
|
18
|
-
|
19
|
-
def call
|
20
|
-
setup_outside_env
|
21
|
-
DockerCompose.build.down("--remove-orphans").up
|
22
|
-
app_container.run("bundle install") if cached_gems?
|
23
|
-
yield self if block_given?
|
24
|
-
app_container.run("rake deploy:inside:unload[#{target}]")
|
25
|
-
raise DeployError unless $? == 0
|
26
|
-
app_container.run("rake deploy:inside:finish[#{target}]")
|
27
|
-
raise DeployError unless $? == 0
|
28
|
-
end
|
29
|
-
|
30
|
-
def bootstrap
|
31
|
-
raise BootstrappedAlready if bootstrapped?
|
32
|
-
copy_dump_if_requested
|
33
|
-
app_container.run("rake deploy:inside:write_env_file[#{target}]")
|
34
|
-
app_container.run("rake deploy:inside:bootstrap[#{target}]")
|
35
|
-
raise BootstrapError unless $? == 0
|
36
|
-
end
|
37
|
-
|
38
|
-
def bootstrap_undo
|
39
|
-
setup_outside_env
|
40
|
-
DockerCompose.down("--remove-orphans", "-v")
|
41
|
-
raise BootstrapError unless $? == 0
|
42
|
-
end
|
43
|
-
|
44
|
-
def load_target_config
|
45
|
-
load target_config_path
|
46
|
-
rescue LoadError => e
|
47
|
-
raise UnknownTarget, e.message
|
48
|
-
end
|
49
|
-
|
50
|
-
def setup_outside_env
|
51
|
-
ENV.update env
|
52
|
-
end
|
53
|
-
|
54
|
-
def env
|
55
|
-
env = docker_machine_env
|
56
|
-
env["VIRTUAL_HOST"] = config.virtual_host
|
57
|
-
if config.letsencrypt_email.present?
|
58
|
-
env["LETSENCRYPT_HOST"] = config.virtual_host
|
59
|
-
env["LETSENCRYPT_EMAIL"] = config.letsencrypt_email
|
60
|
-
end
|
61
|
-
env["COMPOSE_FILE"] = config.compose_file if config.compose_file
|
62
|
-
env
|
63
|
-
end
|
64
|
-
|
65
|
-
def write_env_file
|
66
|
-
File.open(env_file_path, "w") do |io|
|
67
|
-
persistent_env.merge(generated_passwords).each do |var, val|
|
68
|
-
io.puts %Q[export #{var}="#{val}"]
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def rm_env_file
|
74
|
-
FileUtils.rm(env_file_path)
|
75
|
-
end
|
76
|
-
|
77
|
-
def persistent_env
|
78
|
-
config.persistent_env || {}
|
79
|
-
end
|
80
|
-
|
81
|
-
def generated_passwords
|
82
|
-
password_vars.map{|var| [var, generate_password]}.to_h
|
83
|
-
end
|
84
|
-
|
85
|
-
def generate_password
|
86
|
-
Generate.password
|
87
|
-
end
|
88
|
-
|
89
12
|
private
|
90
13
|
|
91
14
|
def copy_dump_if_requested
|
@@ -96,21 +19,10 @@ module Rumination
|
|
96
19
|
app_container.cp_to_container source, target
|
97
20
|
end
|
98
21
|
|
99
|
-
def load_application_config_if_exists
|
100
|
-
load application_config_path if File.exists?(application_config_path)
|
101
|
-
end
|
102
|
-
|
103
|
-
def application_config_path
|
104
|
-
"./config/deploy/application.rb"
|
105
|
-
end
|
106
|
-
|
107
22
|
def target_config_path
|
108
23
|
(config.target_config_path || "./config/deploy/targets/%s.rb") % target
|
109
24
|
end
|
110
25
|
|
111
|
-
def password_vars
|
112
|
-
config.generate_passwords || Array(config.generate_password)
|
113
|
-
end
|
114
26
|
|
115
27
|
def docker_machine_env
|
116
28
|
dm_env_str = if config.docker_machine
|
@@ -125,10 +37,6 @@ module Rumination
|
|
125
37
|
app_container.has_file?(env_file_path)
|
126
38
|
end
|
127
39
|
|
128
|
-
def env_file_path
|
129
|
-
"/opt/app/env"
|
130
|
-
end
|
131
|
-
|
132
40
|
def container(name)
|
133
41
|
DockerCompose::Container.new(name)
|
134
42
|
end
|
@@ -1,8 +1,17 @@
|
|
1
|
-
|
1
|
+
require "ostruct"
|
2
|
+
require_relative "../generate"
|
2
3
|
|
3
4
|
module Rumination
|
4
5
|
module Deploy
|
5
6
|
module ClassMethods
|
7
|
+
def factory_reset!
|
8
|
+
config.clear
|
9
|
+
configure do |config|
|
10
|
+
config.bootstrap = OpenStruct.new
|
11
|
+
end
|
12
|
+
self.target = nil
|
13
|
+
end
|
14
|
+
|
6
15
|
def docker_env
|
7
16
|
env = {}
|
8
17
|
if config.docker_machine
|
@@ -25,34 +34,46 @@ module Rumination
|
|
25
34
|
raise UnknownTarget, e.message
|
26
35
|
end
|
27
36
|
|
28
|
-
def
|
29
|
-
|
30
|
-
|
37
|
+
def write_env_file path
|
38
|
+
File.open(path, "w") do |io|
|
39
|
+
persistent_env.merge(generated_passwords).each do |var, val|
|
40
|
+
io.puts %Q[export #{var}="#{val}"]
|
41
|
+
end
|
31
42
|
end
|
32
43
|
end
|
33
44
|
|
34
|
-
def
|
35
|
-
|
45
|
+
def files_to_copy_on_bootstrap
|
46
|
+
(config.bootstrap && config.bootstrap.copy_files) || []
|
47
|
+
end
|
48
|
+
|
49
|
+
def files_to_copy_on_deploy
|
50
|
+
config.copy_files || []
|
51
|
+
end
|
52
|
+
|
53
|
+
def app_container_name
|
54
|
+
config.app_container || :app
|
36
55
|
end
|
37
56
|
|
38
|
-
def
|
39
|
-
|
57
|
+
def app_container_full_name
|
58
|
+
"#{compose_project_name}_#{app_container_name}_1"
|
40
59
|
end
|
41
60
|
|
42
|
-
def
|
43
|
-
|
61
|
+
def compose_project_name
|
62
|
+
(ENV["COMPOSE_PROJECT_NAME"] || File.basename(Dir.pwd)).gsub("_","")
|
44
63
|
end
|
45
64
|
|
46
|
-
|
47
|
-
|
65
|
+
private
|
66
|
+
|
67
|
+
def persistent_env
|
68
|
+
config.persistent_env || {}
|
48
69
|
end
|
49
70
|
|
50
|
-
def
|
51
|
-
|
71
|
+
def generated_passwords
|
72
|
+
password_vars.map{|var| [var, Generate.password]}.to_h
|
52
73
|
end
|
53
74
|
|
54
|
-
def
|
55
|
-
config.
|
75
|
+
def password_vars
|
76
|
+
config.generate_passwords || Array(config.generate_password)
|
56
77
|
end
|
57
78
|
end
|
58
79
|
end
|
data/lib/rumination/deploy.rb
CHANGED
@@ -1,43 +1,73 @@
|
|
1
|
+
require "dotenv"
|
2
|
+
require "active_support/core_ext/string/strip"
|
3
|
+
|
1
4
|
task :deploy, [:target] => "deploy:default"
|
2
5
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
end
|
6
|
+
namespace :deploy do
|
7
|
+
task :default, [:target] => %w[
|
8
|
+
start
|
9
|
+
finish
|
10
|
+
]
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
task :bootstrap, [:target] => %w[
|
13
|
+
start
|
14
|
+
bootstrap:env_file
|
15
|
+
bootstrap:copy_files
|
16
|
+
bootstrap:db
|
17
|
+
on:bootstrapped
|
18
|
+
finish
|
19
|
+
]
|
17
20
|
|
18
|
-
namespace :deploy do
|
19
21
|
task :env, [:target] => :load_target_config_filterd do |t, args|
|
20
22
|
puts
|
21
23
|
Rumination::Deploy.docker_env.each do |var, val|
|
22
24
|
puts %Q[export #{var}="#{val}"]
|
23
25
|
end
|
24
|
-
puts <<-__
|
25
|
-
|
26
|
-
#
|
27
|
-
#
|
28
|
-
# eval $(rake deploy:env[#{Rumination::Deploy.target}])
|
29
|
-
|
26
|
+
puts <<-__.strip_heredoc
|
27
|
+
# to load this into a bash environment run:
|
28
|
+
#
|
29
|
+
# eval $(rake deploy:env[#{Rumination::Deploy.target}])
|
30
30
|
__
|
31
31
|
end
|
32
32
|
|
33
|
-
|
33
|
+
namespace :on do
|
34
|
+
task :deployed
|
35
|
+
task :bootstrapped
|
34
36
|
end
|
35
37
|
|
36
|
-
|
38
|
+
namespace :bootstrap do
|
39
|
+
task :env_file do
|
40
|
+
env_file_path = "/opt/app/env"
|
41
|
+
temp_file_path = "tmp/#{Rumination::Deploy.target}.env"
|
42
|
+
mkdir_p File.dirname(temp_file_path)
|
43
|
+
Rumination::Deploy.write_env_file(temp_file_path)
|
44
|
+
container = Rumination::Deploy.app_container_full_name
|
45
|
+
sh "docker cp #{temp_file_path} #{container}:#{env_file_path}"
|
46
|
+
end
|
47
|
+
|
48
|
+
task :copy_files do
|
49
|
+
container = Rumination::Deploy.app_container_full_name
|
50
|
+
Rumination::Deploy.files_to_copy_on_bootstrap.each do |source, target|
|
51
|
+
sh "docker cp #{source} #{container}:#{target}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
task :db
|
56
|
+
|
57
|
+
task :undo, [:target] => %w[confirm_undo] do |t, args|
|
58
|
+
sh "docker-compose down --remove-orphans -v"
|
59
|
+
end
|
60
|
+
|
61
|
+
task :confirm_undo do |t, args|
|
62
|
+
require "highline/import"
|
63
|
+
question = "Do you really want to undo the bootstrap (database will be dropped)?"
|
64
|
+
abort("Bootstrap undo canceled, you didn't mean it") unless agree(question)
|
65
|
+
end
|
37
66
|
end
|
38
67
|
|
39
68
|
task :setup_docker_env, [:target] => :load_target_config do |t, args|
|
40
69
|
puts "Setting up '#{Rumination::Deploy.target}' target docker environment"
|
70
|
+
Dotenv.load
|
41
71
|
ENV.update Rumination::Deploy.docker_env
|
42
72
|
end
|
43
73
|
|
@@ -53,14 +83,38 @@ namespace :deploy do
|
|
53
83
|
end
|
54
84
|
end
|
55
85
|
|
56
|
-
|
57
|
-
|
58
|
-
|
86
|
+
task :start, [:target] => %w[
|
87
|
+
setup_docker_env
|
88
|
+
switch_containers
|
89
|
+
]
|
59
90
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
91
|
+
task :finish => %w[
|
92
|
+
copy_files
|
93
|
+
on:deployed
|
94
|
+
]
|
95
|
+
|
96
|
+
task :switch_containers => %w[
|
97
|
+
build_containers
|
98
|
+
shut_down_services
|
99
|
+
start_services
|
100
|
+
]
|
101
|
+
|
102
|
+
task :build_containers do
|
103
|
+
sh "docker-compose build"
|
104
|
+
end
|
105
|
+
|
106
|
+
task :shut_down_services do
|
107
|
+
sh "docker-compose down --remove-orphans"
|
108
|
+
end
|
109
|
+
|
110
|
+
task :start_services do
|
111
|
+
sh "docker-compose up -d"
|
112
|
+
end
|
113
|
+
|
114
|
+
task :copy_files do
|
115
|
+
container = Rumination::Deploy.app_container_full_name
|
116
|
+
Rumination::Deploy.files_to_copy_on_deploy.each do |source, target|
|
117
|
+
sh "docker cp #{source} #{container}:#{target}"
|
64
118
|
end
|
65
119
|
end
|
66
120
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Kernel
|
2
|
+
alias_method :orig_puts, :puts
|
3
|
+
def hash_puts *args
|
4
|
+
print "# "
|
5
|
+
orig_puts *args
|
6
|
+
end
|
7
|
+
|
8
|
+
def with_hash_puts
|
9
|
+
Kernel.send :alias_method, :puts, :hash_puts
|
10
|
+
yield
|
11
|
+
ensure
|
12
|
+
Kernel.send :alias_method, :puts, :orig_puts
|
13
|
+
end
|
14
|
+
end
|
data/lib/rumination/version.rb
CHANGED
data/lib/rumination.rb
CHANGED
@@ -10,15 +10,15 @@ require_relative "rumination/dev_user"
|
|
10
10
|
require_relative "rumination/pg"
|
11
11
|
|
12
12
|
module Rumination
|
13
|
-
def self.factory_reset
|
13
|
+
def self.factory_reset!
|
14
14
|
config.clear
|
15
15
|
if defined? Rumination::Deploy
|
16
|
-
Rumination::Deploy.
|
16
|
+
Rumination::Deploy.factory_reset!
|
17
17
|
end
|
18
18
|
configure do |config|
|
19
19
|
config.pg = Rumination::Pg.config
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
factory_reset
|
23
|
+
factory_reset!
|
24
24
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rumination
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.13'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Artem Baguinski
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -158,6 +158,7 @@ files:
|
|
158
158
|
- lib/rumination/tasks/db/setup.rake
|
159
159
|
- lib/rumination/tasks/deploy.rake
|
160
160
|
- lib/rumination/tasks/deploy/inside.rake
|
161
|
+
- lib/rumination/tasks/with_hash_puts.rake
|
161
162
|
- lib/rumination/version.rb
|
162
163
|
- rumination.gemspec
|
163
164
|
homepage: https://github.com/artm/rumination
|