docker_deploy 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/docker_deploy/service.rb +29 -0
- data/lib/docker_deploy/stage.rb +10 -12
- data/lib/docker_deploy/task.rb +26 -4
- data/lib/docker_deploy/version.rb +1 -1
- data/lib/docker_deploy.rb +10 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b3ca2a21e28ad1002f9acf80b7863334be7955e
|
4
|
+
data.tar.gz: 81d5bbfe43edc6485be780738aa0d1be2b2e1f6b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 746749ade72e06e8cb9b4df66b280586e0b0034f32135864798fdb3c1c62da53f54274576c626dc2bff4c2741208c13a836eb417e78cc11d33c1ef126a68fef5
|
7
|
+
data.tar.gz: f2354f4399a9e42f4f7b564950621a1f2ab218eac7c5aef32f4b480adbb90e110cef61608ca700cd01a8743c9d6c6a684e6da43136d096f079ee210c3ae0801a
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module DockerDeploy
|
2
|
+
class Service
|
3
|
+
attr_reader :name, :command
|
4
|
+
|
5
|
+
def initialize(stage, name)
|
6
|
+
@stage = stage
|
7
|
+
@name = name
|
8
|
+
@ports = {}
|
9
|
+
end
|
10
|
+
|
11
|
+
def command(name = nil)
|
12
|
+
@command = name if name
|
13
|
+
@command
|
14
|
+
end
|
15
|
+
|
16
|
+
def port(ports = {})
|
17
|
+
@ports.merge!(ports)
|
18
|
+
end
|
19
|
+
|
20
|
+
def port_mappings
|
21
|
+
DockerDeploy.format_params("-p %s:%s", @ports)
|
22
|
+
end
|
23
|
+
|
24
|
+
def container(name = nil)
|
25
|
+
@container = name if name
|
26
|
+
@container or "#{@stage.container}_#{@name}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/docker_deploy/stage.rb
CHANGED
@@ -2,12 +2,13 @@ module DockerDeploy
|
|
2
2
|
class Stage
|
3
3
|
include Rake::FileUtilsExt
|
4
4
|
|
5
|
-
attr_reader :name, :servers, :variables, :links, :env_files, :deploy, :container
|
5
|
+
attr_reader :name, :servers, :variables, :links, :env_files, :deploy, :container, :services
|
6
6
|
|
7
7
|
def initialize(context, name)
|
8
8
|
@context = context
|
9
9
|
@name = name
|
10
10
|
@env_files = []
|
11
|
+
@services = []
|
11
12
|
@variables = {}
|
12
13
|
@ports = {}
|
13
14
|
@links = {}
|
@@ -36,16 +37,16 @@ module DockerDeploy
|
|
36
37
|
end
|
37
38
|
|
38
39
|
def link_mappings
|
39
|
-
format_params("--link %s:%s", @context.links.merge(@links))
|
40
|
+
DockerDeploy.format_params("--link %s:%s", @context.links.merge(@links))
|
40
41
|
end
|
41
42
|
|
42
43
|
def port_mappings
|
43
|
-
format_params("-p %s:%s", @context.ports.merge(@ports))
|
44
|
+
DockerDeploy.format_params("-p %s:%s", @context.ports.merge(@ports))
|
44
45
|
end
|
45
46
|
|
46
47
|
def options
|
47
|
-
format_params("--env-file %s", @context.env_files + @env_files) + " " +
|
48
|
-
format_params("-e %s=%s", @context.variables.merge(@variables))
|
48
|
+
DockerDeploy.format_params("--env-file %s", @context.env_files + @env_files) + " " +
|
49
|
+
DockerDeploy.format_params("-e %s=%s", @context.variables.merge(@variables))
|
49
50
|
end
|
50
51
|
|
51
52
|
def container(name = nil)
|
@@ -53,13 +54,10 @@ module DockerDeploy
|
|
53
54
|
@container or @context.container
|
54
55
|
end
|
55
56
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
args = [args].flatten.map { |v| Shellwords.escape(v) }
|
61
|
-
pattern % args
|
62
|
-
end.join(" ")
|
57
|
+
def service(name, &block)
|
58
|
+
service = Service.new(self, name)
|
59
|
+
service.instance_eval(&block)
|
60
|
+
@services << service
|
63
61
|
end
|
64
62
|
end
|
65
63
|
end
|
data/lib/docker_deploy/task.rb
CHANGED
@@ -33,7 +33,32 @@ module DockerDeploy
|
|
33
33
|
task :start do
|
34
34
|
stage.run "docker run -d #{stage.port_mappings} #{stage.link_mappings} #{stage.options} --name #{stage.container} #{context.image}:latest"
|
35
35
|
|
36
|
-
puts "\n\
|
36
|
+
puts "\n\nstarted: #{stage.host}\n"
|
37
|
+
end
|
38
|
+
|
39
|
+
desc "Restart the running container."
|
40
|
+
task restart: [:stop, :start]
|
41
|
+
|
42
|
+
stage.services.each do |service|
|
43
|
+
namespace service.name do
|
44
|
+
desc "Stop the #{service.name} service and remove its container"
|
45
|
+
task :stop do
|
46
|
+
stage.run "docker inspect #{service.container} 2>&1 > /dev/null && docker kill #{service.container} && docker rm #{service.container} || true"
|
47
|
+
end
|
48
|
+
|
49
|
+
desc "Start the #{service.name} service in a container using the latest image."
|
50
|
+
task :start do
|
51
|
+
stage.run "docker run -d #{service.port_mappings} #{stage.link_mappings} #{stage.options} --name #{service.container} #{context.image}:latest #{service.command}"
|
52
|
+
end
|
53
|
+
|
54
|
+
desc "Restart the #{service.name} service."
|
55
|
+
task restart: [:stop, :start]
|
56
|
+
|
57
|
+
desc "Tail log of the #{service.name} service."
|
58
|
+
task :tail do
|
59
|
+
stage.run "docker logs --tail 50 -f #{service.container}"
|
60
|
+
end
|
61
|
+
end
|
37
62
|
end
|
38
63
|
|
39
64
|
desc "Run migrations in the latest image."
|
@@ -67,9 +92,6 @@ module DockerDeploy
|
|
67
92
|
stage.shell
|
68
93
|
end
|
69
94
|
end
|
70
|
-
|
71
|
-
desc "Restart the running container."
|
72
|
-
task restart: [:stop, :start]
|
73
95
|
end
|
74
96
|
end
|
75
97
|
end
|
data/lib/docker_deploy.rb
CHANGED
@@ -5,12 +5,22 @@ require "io/console"
|
|
5
5
|
|
6
6
|
require "docker_deploy/version"
|
7
7
|
require "docker_deploy/shell"
|
8
|
+
require "docker_deploy/service"
|
8
9
|
require "docker_deploy/context"
|
9
10
|
require "docker_deploy/stage"
|
10
11
|
require "docker_deploy/remote_stage"
|
11
12
|
require "docker_deploy/local_stage"
|
12
13
|
require "docker_deploy/task"
|
13
14
|
|
15
|
+
module DockerDeploy
|
16
|
+
def self.format_params(pattern, enumerable)
|
17
|
+
enumerable.map do |args|
|
18
|
+
args = [args].flatten.map { |v| Shellwords.escape(v) }
|
19
|
+
pattern % args
|
20
|
+
end.join(" ")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
14
24
|
# Improvement on the broken piece of crap text formatter in SSHKit.
|
15
25
|
class PlainFormatter < SSHKit::Formatter::Abstract
|
16
26
|
def initialize(io = $stdout)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: docker_deploy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonas Nicklas
|
@@ -71,6 +71,7 @@ files:
|
|
71
71
|
- lib/docker_deploy/context.rb
|
72
72
|
- lib/docker_deploy/local_stage.rb
|
73
73
|
- lib/docker_deploy/remote_stage.rb
|
74
|
+
- lib/docker_deploy/service.rb
|
74
75
|
- lib/docker_deploy/shell.rb
|
75
76
|
- lib/docker_deploy/stage.rb
|
76
77
|
- lib/docker_deploy/task.rb
|