devup 0.3.2.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.ruby-version +1 -1
- data/Gemfile.lock +28 -23
- data/README.md +50 -14
- data/devup.gemspec +2 -1
- data/docker-compose.devup.yml +11 -0
- data/exe/devup +2 -10
- data/lib/devup/boot.rb +4 -1
- data/lib/devup/cli.rb +22 -0
- data/lib/devup/cli/commands/command.rb +38 -0
- data/lib/devup/cli/commands/down.rb +17 -0
- data/lib/devup/cli/commands/up.rb +33 -0
- data/lib/devup/compose.rb +42 -16
- data/lib/devup/compose/ps.rb +30 -0
- data/lib/devup/dotenv.rb +15 -1
- data/lib/devup/dotenv_load_list.rb +35 -0
- data/lib/devup/environment.rb +26 -15
- data/lib/devup/logger.rb +7 -3
- data/lib/devup/port_checker.rb +16 -0
- data/lib/devup/service.rb +3 -3
- data/lib/devup/service_presenter.rb +2 -27
- data/lib/devup/shell.rb +28 -0
- data/lib/devup/version.rb +1 -1
- metadata +27 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 511e80ba2fee56f5436b039bed0a4971bd862d72b567212ce9d308c67ee8a1e2
|
4
|
+
data.tar.gz: d6ee87d4b3072ec10b9b5f4cba552e9c3227ff2541ac94ad8e2811a71b5d0f88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43b8fef236dda464cd9264096534f997dce81a1b71f266a3892161008f036d77053345324ad7f2f936ce34fc58708f5b24f499ad9d0b9f19c2bbe10642f4eaf5
|
7
|
+
data.tar.gz: 1c54bc229b93496280b47bd81d2e8a900db0d08fd9acc7c774f857e19ddbf05fb73a38aad292b65b78fdb8bd855666e2ef26f28d34f4083b83d1212c8b8eb658
|
data/.gitignore
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby-2.
|
1
|
+
ruby-2.5.8
|
data/Gemfile.lock
CHANGED
@@ -1,25 +1,28 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
devup (0.
|
4
|
+
devup (0.5.0)
|
5
5
|
dotenv
|
6
|
+
dry-cli
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: https://rubygems.org/
|
9
10
|
specs:
|
10
|
-
ast (2.4.
|
11
|
+
ast (2.4.1)
|
11
12
|
byebug (11.1.3)
|
12
|
-
|
13
|
+
concurrent-ruby (1.1.7)
|
14
|
+
diff-lcs (1.4.4)
|
13
15
|
docile (1.3.2)
|
14
|
-
dotenv (2.7.
|
15
|
-
|
16
|
-
|
17
|
-
parallel (1.19.
|
18
|
-
parser (2.7.1.
|
19
|
-
ast (~> 2.4.
|
16
|
+
dotenv (2.7.6)
|
17
|
+
dry-cli (0.6.0)
|
18
|
+
concurrent-ruby (~> 1.0)
|
19
|
+
parallel (1.19.2)
|
20
|
+
parser (2.7.1.4)
|
21
|
+
ast (~> 2.4.1)
|
20
22
|
rainbow (3.0.0)
|
21
23
|
rake (12.3.3)
|
22
|
-
|
24
|
+
regexp_parser (1.7.1)
|
25
|
+
rexml (3.2.4)
|
23
26
|
rspec (3.9.0)
|
24
27
|
rspec-core (~> 3.9.0)
|
25
28
|
rspec-expectations (~> 3.9.0)
|
@@ -33,26 +36,28 @@ GEM
|
|
33
36
|
diff-lcs (>= 1.2.0, < 2.0)
|
34
37
|
rspec-support (~> 3.9.0)
|
35
38
|
rspec-support (3.9.3)
|
36
|
-
rubocop (0.
|
37
|
-
jaro_winkler (~> 1.5.1)
|
39
|
+
rubocop (0.85.1)
|
38
40
|
parallel (~> 1.10)
|
39
41
|
parser (>= 2.7.0.1)
|
40
42
|
rainbow (>= 2.2.2, < 4.0)
|
43
|
+
regexp_parser (>= 1.7)
|
41
44
|
rexml
|
45
|
+
rubocop-ast (>= 0.0.3)
|
42
46
|
ruby-progressbar (~> 1.7)
|
43
|
-
unicode-display_width (>= 1.4.0, <
|
44
|
-
rubocop-
|
47
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
48
|
+
rubocop-ast (0.1.0)
|
49
|
+
parser (>= 2.7.0.1)
|
50
|
+
rubocop-performance (1.6.1)
|
45
51
|
rubocop (>= 0.71.0)
|
46
52
|
ruby-progressbar (1.10.1)
|
47
|
-
simplecov (0.
|
53
|
+
simplecov (0.18.5)
|
48
54
|
docile (~> 1.1)
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
rubocop (~>
|
54
|
-
|
55
|
-
unicode-display_width (1.6.1)
|
55
|
+
simplecov-html (~> 0.11)
|
56
|
+
simplecov-html (0.12.2)
|
57
|
+
standard (0.4.7)
|
58
|
+
rubocop (~> 0.85.0)
|
59
|
+
rubocop-performance (~> 1.6.0)
|
60
|
+
unicode-display_width (1.7.0)
|
56
61
|
|
57
62
|
PLATFORMS
|
58
63
|
ruby
|
@@ -66,4 +71,4 @@ DEPENDENCIES
|
|
66
71
|
standard
|
67
72
|
|
68
73
|
BUNDLED WITH
|
69
|
-
|
74
|
+
1.17.3
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# DevUp! [![Travis (.com) branch](https://img.shields.io/travis/com/sergio-fry/devup/master)](https://travis-ci.com/github/sergio-fry/devup) [![Gem](https://img.shields.io/gem/v/devup)](https://rubygems.org/gems/devup) [![Code Climate coverage](https://img.shields.io/codeclimate/coverage/sergio-fry/devup)](https://codeclimate.com/github/sergio-fry/devup) [![Code Climate maintainability](https://img.shields.io/codeclimate/maintainability/sergio-fry/devup)](https://codeclimate.com/github/sergio-fry/devup) [![Gem](https://img.shields.io/gem/dt/devup)](https://rubygems.org/gems/devup)
|
1
|
+
# DevUp! [![Travis (.com) branch](https://img.shields.io/travis/com/sergio-fry/devup/master)](https://travis-ci.com/github/sergio-fry/devup) [![Gem](https://img.shields.io/gem/v/devup)](https://rubygems.org/gems/devup) [![Code Climate coverage](https://img.shields.io/codeclimate/coverage/sergio-fry/devup)](https://codeclimate.com/github/sergio-fry/devup) [![Code Climate maintainability](https://img.shields.io/codeclimate/maintainability/sergio-fry/devup)](https://codeclimate.com/github/sergio-fry/devup) [![Gem](https://img.shields.io/gem/dt/devup)](https://rubygems.org/gems/devup) [![Hits-of-Code](https://hitsofcode.com/github/sergio-fry/devup)](https://hitsofcode.com/view/github/sergio-fry/devup)
|
2
2
|
|
3
3
|
Describe development dependencies with docker-compose. It is not required to remember any fancy command to start docker. Just start developing your app. Rails is a first-class citizen, but could be used without ruby.
|
4
4
|
|
@@ -32,28 +32,37 @@ gem "devup", group: [:development, :test]
|
|
32
32
|
|
33
33
|
and
|
34
34
|
|
35
|
-
bundle install
|
35
|
+
$ bundle install
|
36
36
|
|
37
37
|
|
38
38
|
Update your database.yml to use ENV:
|
39
39
|
|
40
40
|
```yaml
|
41
|
-
|
42
|
-
|
41
|
+
default: &default
|
42
|
+
adapter: postgresql
|
43
|
+
encoding: unicode
|
44
|
+
host: <%= ENV.fetch("POSTGRES_HOST") %>
|
45
|
+
port: <%= ENV.fetch("POSTGRES_PORT") %>
|
46
|
+
username: postgres
|
47
|
+
password:
|
43
48
|
|
44
49
|
development:
|
45
|
-
|
50
|
+
<<: *default
|
51
|
+
database: development
|
46
52
|
|
53
|
+
test:
|
54
|
+
<<: *default
|
55
|
+
database: test
|
47
56
|
```
|
48
57
|
|
49
58
|
|
50
59
|
You are ready to use rails with PostgreSQL configured
|
51
60
|
|
52
|
-
$ bundle exec rake db:create
|
53
|
-
|
54
|
-
|
61
|
+
$ RAILS_ENV=test bundle exec rake db:create
|
62
|
+
DevUp! INFO starting up...
|
63
|
+
DevUp! INFO up
|
55
64
|
|
56
|
-
$
|
65
|
+
$ Created database 'test'
|
57
66
|
|
58
67
|
|
59
68
|
## Without Rails
|
@@ -65,18 +74,21 @@ ENV vars from .env.services are loaded with dotenv automatically.
|
|
65
74
|
require "devup"
|
66
75
|
require "sequel"
|
67
76
|
|
68
|
-
DB = Sequel.connect(ENV.fetch("
|
77
|
+
DB = Sequel.connect(adapter: "postgres", host: ENV.fetch("POSTGRES_HOST"), port: ENV.fetch("POSTGRES_PORT"), database: "blog", user: 'postgres')
|
69
78
|
```
|
70
79
|
|
71
80
|
|
72
81
|
## Without Ruby (PHP, nodejs, Java, ...)
|
73
82
|
|
83
|
+
Install DevUp!
|
84
|
+
|
85
|
+
$ gem install devup
|
86
|
+
|
74
87
|
Start up services
|
75
88
|
|
76
|
-
$ devup
|
77
|
-
|
78
|
-
|
79
|
-
dummy_rails_memcached_1 is up-to-date
|
89
|
+
$ devup up
|
90
|
+
DevUp! INFO starting up...
|
91
|
+
DevUp! INFO up
|
80
92
|
|
81
93
|
$ cat .env.services
|
82
94
|
export POSTGRES_HOST=0.0.0.0
|
@@ -100,6 +112,30 @@ Now you can run app
|
|
100
112
|
|
101
113
|
If you don't want devup to setup your dev services, you can disable it by using `DEVUP_ENABLED=false`. Just add it to .env.local file.
|
102
114
|
|
115
|
+
### Override some service
|
116
|
+
|
117
|
+
If you want to switch some service from DevUp! to another, you can override ENV in a local dotenv configs:
|
118
|
+
|
119
|
+
* .env.local
|
120
|
+
* .env.development.local
|
121
|
+
* .env.test.local
|
122
|
+
|
123
|
+
Just put to your .env.local:
|
124
|
+
|
125
|
+
export POSTGRES_HOST=0.0.0.0
|
126
|
+
export POSTGRES_PORT=5432
|
127
|
+
|
128
|
+
### Get some DATABASE_URL working
|
129
|
+
|
130
|
+
|
131
|
+
Just put to your .env.test or .env.development something like:
|
132
|
+
|
133
|
+
DATABASE_URL=postgres://postgres@$POSTGRES_HOST:$POSTGRES_PORT/test_db
|
134
|
+
|
135
|
+
### Debug
|
136
|
+
|
137
|
+
$ export DEVUP_LOG_LEVEL=debug
|
138
|
+
$ devup up
|
103
139
|
|
104
140
|
## Development
|
105
141
|
|
data/devup.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.authors = ["Sergei O. Udalov"]
|
11
11
|
spec.email = ["sergei@udalovs.ru"]
|
12
12
|
|
13
|
-
spec.summary = "A tool to manage docker-compose for
|
13
|
+
spec.summary = "A tool to manage docker-compose for development"
|
14
14
|
# spec.description = %q{TODO: Write a longer description or delete this line.}
|
15
15
|
spec.homepage = "https://github.com/sergio-fry/devup"
|
16
16
|
spec.license = "MIT"
|
@@ -32,4 +32,5 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.require_paths = ["lib"]
|
33
33
|
|
34
34
|
spec.add_dependency "dotenv"
|
35
|
+
spec.add_dependency "dry-cli"
|
35
36
|
end
|
data/exe/devup
CHANGED
@@ -1,13 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require "devup/
|
3
|
+
require "devup/cli"
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
# TODO: use dry-cli here
|
8
|
-
case ARGV[0]
|
9
|
-
when "down"
|
10
|
-
devup.down
|
11
|
-
else
|
12
|
-
devup.up
|
13
|
-
end
|
5
|
+
Dry::CLI.new(Devup::CLI::Commands).call
|
data/lib/devup/boot.rb
CHANGED
data/lib/devup/cli.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require "dry/cli"
|
2
|
+
|
3
|
+
require "devup/cli/commands/up"
|
4
|
+
require "devup/cli/commands/down"
|
5
|
+
|
6
|
+
module Devup
|
7
|
+
module CLI
|
8
|
+
module Commands
|
9
|
+
extend Dry::CLI::Registry
|
10
|
+
|
11
|
+
class Version < Dry::CLI::Command
|
12
|
+
def call(*)
|
13
|
+
puts Devup::VERSION
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
Devup::CLI::Commands.register "version", Devup::CLI::Commands::Version, aliases: ["v", "-v", "--version"]
|
21
|
+
Devup::CLI::Commands.register "up", Devup::CLI::Commands::Up
|
22
|
+
Devup::CLI::Commands.register "down", Devup::CLI::Commands::Down
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require "devup/logger"
|
2
|
+
|
3
|
+
module Devup
|
4
|
+
module CLI
|
5
|
+
module Commands
|
6
|
+
class Command < Dry::CLI::Command
|
7
|
+
def call(**options)
|
8
|
+
@opts = options
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
|
13
|
+
attr_reader :opts
|
14
|
+
|
15
|
+
def logger
|
16
|
+
@logger ||= Devup::Logger.build(log_level)
|
17
|
+
end
|
18
|
+
|
19
|
+
def log_level
|
20
|
+
if opts.fetch(:verbose)
|
21
|
+
:debug
|
22
|
+
else
|
23
|
+
:info
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def devup
|
28
|
+
require "devup/environment"
|
29
|
+
|
30
|
+
@devup ||= Devup::Environment.new(
|
31
|
+
pwd: `pwd`,
|
32
|
+
logger: logger
|
33
|
+
)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Devup
|
2
|
+
module CLI
|
3
|
+
module Commands
|
4
|
+
class Down < Command
|
5
|
+
desc "Stop dev services"
|
6
|
+
|
7
|
+
option :verbose, type: :boolean, default: false, desc: "Verbose"
|
8
|
+
|
9
|
+
def call(**options)
|
10
|
+
super
|
11
|
+
|
12
|
+
devup.down
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "devup/cli/commands/command"
|
2
|
+
module Devup
|
3
|
+
module CLI
|
4
|
+
module Commands
|
5
|
+
class Up < Command
|
6
|
+
desc "Run dev services"
|
7
|
+
|
8
|
+
option :verbose, type: :boolean, default: false, desc: "Verbose"
|
9
|
+
|
10
|
+
def call(**options)
|
11
|
+
super
|
12
|
+
|
13
|
+
devup.up
|
14
|
+
print_info
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def print_info
|
20
|
+
puts <<~INFO
|
21
|
+
|
22
|
+
Now you are ready to use services. All variables are available
|
23
|
+
in a .env.services file. Just start you ruby application if
|
24
|
+
gem "devup" is used. Or load variable manually with
|
25
|
+
|
26
|
+
$ source .env.services
|
27
|
+
|
28
|
+
INFO
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/devup/compose.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
require "yaml"
|
2
|
-
|
2
|
+
|
3
|
+
require "devup/compose/ps"
|
3
4
|
|
4
5
|
module Devup
|
5
6
|
class Compose
|
6
|
-
attr_reader :path, :project, :logger
|
7
|
+
attr_reader :path, :project, :logger, :shell
|
7
8
|
|
8
9
|
class Error < StandardError; end
|
9
10
|
|
10
|
-
def initialize(path, project: "devup", logger:)
|
11
|
+
def initialize(path, project: "devup", logger:, shell:)
|
11
12
|
@path = path
|
12
13
|
@project = project
|
13
14
|
@logger = logger
|
15
|
+
@shell = shell
|
14
16
|
end
|
15
17
|
|
16
18
|
def check
|
17
|
-
|
18
|
-
|
19
|
-
status
|
19
|
+
true
|
20
20
|
end
|
21
21
|
|
22
22
|
def services
|
@@ -24,11 +24,19 @@ module Devup
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def service_ports(name)
|
27
|
-
config["services"][name]["ports"]
|
27
|
+
return [] if config["services"][name]["ports"].nil?
|
28
|
+
|
29
|
+
config["services"][name]["ports"].map { |el| el.to_s.split(":")[-1].to_i }
|
30
|
+
end
|
31
|
+
|
32
|
+
def port_mapping(port)
|
33
|
+
ComposeHelpers::Ps.new(exec_ps_cached).port_mapping(port)
|
28
34
|
end
|
29
35
|
|
30
36
|
def up
|
31
37
|
exec "up -d --remove-orphans"
|
38
|
+
|
39
|
+
wait_alive 3
|
32
40
|
end
|
33
41
|
|
34
42
|
def stop
|
@@ -39,22 +47,40 @@ module Devup
|
|
39
47
|
exec "rm -f"
|
40
48
|
end
|
41
49
|
|
42
|
-
|
43
|
-
output, status = safe_exec "docker-compose -p #{project} -f #{path} #{cmd}"
|
50
|
+
private
|
44
51
|
|
45
|
-
|
52
|
+
def wait_alive(timeout, retry_sleep: 0.3)
|
53
|
+
start = Time.now
|
46
54
|
|
47
|
-
|
55
|
+
loop {
|
56
|
+
break if alive?
|
57
|
+
|
58
|
+
if Time.now - start > timeout
|
59
|
+
logger.error "can't run services"
|
60
|
+
break
|
61
|
+
end
|
62
|
+
sleep retry_sleep
|
63
|
+
}
|
48
64
|
end
|
49
65
|
|
50
|
-
|
66
|
+
def alive?
|
67
|
+
ComposeHelpers::Ps.new(exec_ps).up?
|
68
|
+
end
|
69
|
+
|
70
|
+
def exec_ps
|
71
|
+
@exec_ps_output = exec("ps")
|
72
|
+
end
|
73
|
+
|
74
|
+
def exec_ps_cached
|
75
|
+
@exec_ps_output ||= exec("ps")
|
76
|
+
end
|
51
77
|
|
52
|
-
def
|
53
|
-
|
78
|
+
def exec(cmd)
|
79
|
+
resp = shell.exec "docker-compose -p #{project} -f #{path} #{cmd}"
|
54
80
|
|
55
|
-
|
81
|
+
raise(Error) unless resp.success?
|
56
82
|
|
57
|
-
|
83
|
+
resp.data
|
58
84
|
end
|
59
85
|
|
60
86
|
def config
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Devup
|
2
|
+
module ComposeHelpers
|
3
|
+
class Ps
|
4
|
+
attr_reader :output
|
5
|
+
def initialize(output)
|
6
|
+
@output = output
|
7
|
+
end
|
8
|
+
|
9
|
+
def up?
|
10
|
+
service_lines.map { |line|
|
11
|
+
line.match(/Up/) && !line.match(/Exit/)
|
12
|
+
}.all?
|
13
|
+
end
|
14
|
+
|
15
|
+
def port_mapping(port)
|
16
|
+
m = output.match(/\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}:(\d+)->#{port}\/tcp/)
|
17
|
+
|
18
|
+
return if m.nil?
|
19
|
+
|
20
|
+
m[1].to_i
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def service_lines
|
26
|
+
output.split("\n")[2..-1]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/devup/dotenv.rb
CHANGED
@@ -1,2 +1,16 @@
|
|
1
1
|
require "dotenv"
|
2
|
-
|
2
|
+
require "devup/dotenv_load_list"
|
3
|
+
|
4
|
+
begin
|
5
|
+
Dotenv.instrumenter = ActiveSupport::Notifications
|
6
|
+
ActiveSupport::Notifications.subscribe(/^dotenv/) do |*args|
|
7
|
+
event = ActiveSupport::Notifications::Event.new(*args)
|
8
|
+
Spring.watch event.payload[:env].filename # if Rails.application
|
9
|
+
end
|
10
|
+
rescue LoadError, ArgumentError
|
11
|
+
# Spring is not available
|
12
|
+
end
|
13
|
+
|
14
|
+
env = (ENV["RAILS_ENV"] || "development").to_sym
|
15
|
+
list = Devup::DotenvLoadList.new(env: env)
|
16
|
+
Dotenv.load(*list.to_a)
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Devup
|
2
|
+
class DotenvLoadList
|
3
|
+
def initialize(env: nil)
|
4
|
+
@env = env.to_sym unless env.nil?
|
5
|
+
end
|
6
|
+
|
7
|
+
def to_a
|
8
|
+
list = []
|
9
|
+
|
10
|
+
list << ".env.#{@env}.local" if env_defined?
|
11
|
+
list << ".env.local" unless test?
|
12
|
+
list << ".env.services"
|
13
|
+
list << ".env.#{@env}" if env_defined?
|
14
|
+
list << ".env"
|
15
|
+
|
16
|
+
list
|
17
|
+
end
|
18
|
+
|
19
|
+
def include?(val)
|
20
|
+
to_a.include? val
|
21
|
+
end
|
22
|
+
|
23
|
+
def index(val)
|
24
|
+
to_a.index val
|
25
|
+
end
|
26
|
+
|
27
|
+
def test?
|
28
|
+
@env == :test
|
29
|
+
end
|
30
|
+
|
31
|
+
def env_defined?
|
32
|
+
!@env.nil?
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/devup/environment.rb
CHANGED
@@ -4,15 +4,17 @@ require "devup/logger"
|
|
4
4
|
require "devup/compose"
|
5
5
|
require "devup/service"
|
6
6
|
require "devup/service_presenter"
|
7
|
+
require "devup/shell"
|
7
8
|
|
8
9
|
module Devup
|
9
10
|
class Environment
|
10
|
-
attr_reader :pwd, :
|
11
|
+
attr_reader :pwd, :logger, :shell
|
11
12
|
|
12
|
-
def initialize(pwd:, compose: nil, logger: Logger.
|
13
|
+
def initialize(pwd:, compose: nil, logger: Logger.build, shell: Shell.new(pwd: pwd, logger: logger))
|
13
14
|
@pwd = pwd.to_s.strip
|
14
|
-
@compose = compose
|
15
|
+
@compose = compose
|
15
16
|
@logger = logger
|
17
|
+
@shell = shell
|
16
18
|
end
|
17
19
|
|
18
20
|
def project
|
@@ -24,24 +26,27 @@ module Devup
|
|
24
26
|
end
|
25
27
|
|
26
28
|
def up
|
27
|
-
logger.info "
|
29
|
+
logger.info "starting up..."
|
28
30
|
check
|
29
31
|
compose.up
|
30
32
|
write_dotenv
|
31
|
-
logger.info "
|
32
|
-
rescue
|
33
|
+
logger.info "up"
|
34
|
+
rescue => ex
|
33
35
|
clear_dotenv
|
34
|
-
logger.
|
36
|
+
logger.debug ex
|
37
|
+
logger.error "halted"
|
38
|
+
raise ex
|
35
39
|
end
|
36
40
|
|
37
41
|
def down
|
38
|
-
logger.info "
|
42
|
+
logger.info "shutting down..."
|
39
43
|
compose.stop
|
40
44
|
compose.rm
|
41
45
|
clear_dotenv
|
42
|
-
logger.info "
|
43
|
-
rescue
|
44
|
-
logger.
|
46
|
+
logger.info "down"
|
47
|
+
rescue => ex
|
48
|
+
logger.debug ex
|
49
|
+
logger.info "halted"
|
45
50
|
end
|
46
51
|
|
47
52
|
def root
|
@@ -51,11 +56,8 @@ module Devup
|
|
51
56
|
private
|
52
57
|
|
53
58
|
def check
|
54
|
-
|
55
|
-
|
59
|
+
raise if missing_config
|
56
60
|
compose.check
|
57
|
-
|
58
|
-
true
|
59
61
|
end
|
60
62
|
|
61
63
|
def missing_config
|
@@ -98,5 +100,14 @@ module Devup
|
|
98
100
|
|
99
101
|
DOTENV
|
100
102
|
end
|
103
|
+
|
104
|
+
def compose
|
105
|
+
@compose ||= begin
|
106
|
+
Compose.new(
|
107
|
+
root.join("docker-compose.devup.yml"),
|
108
|
+
project: project, logger: logger, shell: shell
|
109
|
+
)
|
110
|
+
end
|
111
|
+
end
|
101
112
|
end
|
102
113
|
end
|
data/lib/devup/logger.rb
CHANGED
@@ -2,9 +2,13 @@ require "logger"
|
|
2
2
|
|
3
3
|
module Devup
|
4
4
|
class Logger < ::Logger
|
5
|
-
def self.
|
6
|
-
formatter = ->(
|
7
|
-
new(STDOUT, formatter: formatter)
|
5
|
+
def self.build(level = :info)
|
6
|
+
formatter = ->(severity, _time, _progname, msg) { "DevUp! #{severity} #{msg}\n" }
|
7
|
+
logger = new(STDOUT, formatter: formatter)
|
8
|
+
|
9
|
+
logger.level = level
|
10
|
+
|
11
|
+
logger
|
8
12
|
end
|
9
13
|
end
|
10
14
|
end
|
data/lib/devup/service.rb
CHANGED
@@ -16,10 +16,10 @@ module Devup
|
|
16
16
|
private
|
17
17
|
|
18
18
|
def fetch_ports
|
19
|
-
compose.service_ports(name).map
|
19
|
+
compose.service_ports(name).map do |from|
|
20
20
|
OpenStruct.new(
|
21
|
-
from: from
|
22
|
-
to: compose.
|
21
|
+
from: from,
|
22
|
+
to: compose.port_mapping(from)
|
23
23
|
)
|
24
24
|
end
|
25
25
|
end
|
@@ -11,7 +11,6 @@ module Devup
|
|
11
11
|
res = []
|
12
12
|
|
13
13
|
res << "# #{service.name}"
|
14
|
-
res << magic if magic?
|
15
14
|
|
16
15
|
if has_ports?
|
17
16
|
res << host_env
|
@@ -32,7 +31,7 @@ module Devup
|
|
32
31
|
def ports_env
|
33
32
|
res = []
|
34
33
|
|
35
|
-
res << port_env(to: service.ports.first.to)
|
34
|
+
res << port_env(to: service.ports.first.to)
|
36
35
|
|
37
36
|
service.ports.each do |port|
|
38
37
|
res << port_env(from: port.from, to: port.to)
|
@@ -53,36 +52,12 @@ module Devup
|
|
53
52
|
service.ports.size > 0
|
54
53
|
end
|
55
54
|
|
56
|
-
def magic?
|
57
|
-
%w[postgres redis mysql memcached].include? service.name
|
58
|
-
end
|
59
|
-
|
60
|
-
def magic
|
61
|
-
case service.name
|
62
|
-
when "postgres"
|
63
|
-
"export DATABASE_URL=postgres://postgres@0.0.0.0:#{port_to(5432)}/#{database_name}"
|
64
|
-
when "mysql"
|
65
|
-
"export DATABASE_URL=mysql2://root@0.0.0.0:#{port_to(3306)}/#{database_name}"
|
66
|
-
when "redis"
|
67
|
-
"export REDIS_URL=redis://0.0.0.0:#{port_to(6379)}"
|
68
|
-
when "memcached"
|
69
|
-
"export MEMCACHE_SERVERS=0.0.0.0:#{port_to(11211)}"
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
55
|
def port_to(from)
|
74
56
|
service.ports.find { |p| p.from == from }&.to
|
75
57
|
end
|
76
58
|
|
77
59
|
def database_name
|
78
|
-
|
79
|
-
[
|
80
|
-
project,
|
81
|
-
Rails.env
|
82
|
-
].join("_")
|
83
|
-
else
|
84
|
-
"db"
|
85
|
-
end
|
60
|
+
"db"
|
86
61
|
end
|
87
62
|
end
|
88
63
|
end
|
data/lib/devup/shell.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require "open3"
|
2
|
+
|
3
|
+
module Devup
|
4
|
+
class Shell
|
5
|
+
attr_reader :pwd, :logger
|
6
|
+
|
7
|
+
def initialize(pwd:, logger:)
|
8
|
+
@pwd = pwd
|
9
|
+
@logger = logger
|
10
|
+
end
|
11
|
+
|
12
|
+
Result = Struct.new(:data, :status) {
|
13
|
+
def success?
|
14
|
+
status
|
15
|
+
end
|
16
|
+
}
|
17
|
+
|
18
|
+
def exec(cmd)
|
19
|
+
logger.debug "$ #{cmd}"
|
20
|
+
|
21
|
+
output, error, status = Open3.capture3(cmd + ";")
|
22
|
+
|
23
|
+
logger.error(error) unless status.success?
|
24
|
+
|
25
|
+
Result.new(output, status.success?)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/devup/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergei O. Udalov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dotenv
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: dry-cli
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
description:
|
28
42
|
email:
|
29
43
|
- sergei@udalovs.ru
|
@@ -47,15 +61,24 @@ files:
|
|
47
61
|
- bin/console
|
48
62
|
- bin/setup
|
49
63
|
- devup.gemspec
|
64
|
+
- docker-compose.devup.yml
|
50
65
|
- exe/devup
|
51
66
|
- lib/devup.rb
|
52
67
|
- lib/devup/boot.rb
|
68
|
+
- lib/devup/cli.rb
|
69
|
+
- lib/devup/cli/commands/command.rb
|
70
|
+
- lib/devup/cli/commands/down.rb
|
71
|
+
- lib/devup/cli/commands/up.rb
|
53
72
|
- lib/devup/compose.rb
|
73
|
+
- lib/devup/compose/ps.rb
|
54
74
|
- lib/devup/dotenv.rb
|
75
|
+
- lib/devup/dotenv_load_list.rb
|
55
76
|
- lib/devup/environment.rb
|
56
77
|
- lib/devup/logger.rb
|
78
|
+
- lib/devup/port_checker.rb
|
57
79
|
- lib/devup/service.rb
|
58
80
|
- lib/devup/service_presenter.rb
|
81
|
+
- lib/devup/shell.rb
|
59
82
|
- lib/devup/version.rb
|
60
83
|
homepage: https://github.com/sergio-fry/devup
|
61
84
|
licenses:
|
@@ -78,8 +101,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
101
|
- !ruby/object:Gem::Version
|
79
102
|
version: '0'
|
80
103
|
requirements: []
|
81
|
-
rubygems_version: 3.
|
104
|
+
rubygems_version: 3.0.8
|
82
105
|
signing_key:
|
83
106
|
specification_version: 4
|
84
|
-
summary: A tool to manage docker-compose for
|
107
|
+
summary: A tool to manage docker-compose for development
|
85
108
|
test_files: []
|