docker_deploy 0.1.2 → 0.2.0
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/context.rb +7 -1
- data/lib/docker_deploy/local_stage.rb +18 -0
- data/lib/docker_deploy/remote_stage.rb +24 -0
- data/lib/docker_deploy/stage.rb +3 -11
- data/lib/docker_deploy/task.rb +25 -19
- data/lib/docker_deploy/version.rb +1 -1
- data/lib/docker_deploy.rb +2 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 618c41243bbfc6326b2e47d0213e6706a7a27a04
|
4
|
+
data.tar.gz: 7626dd1c00d644e7a2ee649edf02b58093aa35ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ccb8cd48d557375771a5bc5519789179753083d5d79d29855ca4bb894137225096484770c8c974274fd5c0dccc00d250a069f6d63237cf58f75113acf8268aa
|
7
|
+
data.tar.gz: 172aa8b76dab46e8436e31aee6b67ae1c11e695ea7ba281fba805d6b69d8619c2f73e219784cb438a86d471221a5882d5e89f638df14f055157e0b30625d6c72
|
@@ -39,8 +39,14 @@ module DockerDeploy
|
|
39
39
|
@revision ||= `git rev-parse HEAD`.chomp[0...8]
|
40
40
|
end
|
41
41
|
|
42
|
+
def local(&block)
|
43
|
+
stage = LocalStage.new(self)
|
44
|
+
stage.instance_eval(&block)
|
45
|
+
@stages << stage
|
46
|
+
end
|
47
|
+
|
42
48
|
def stage(name, &block)
|
43
|
-
stage =
|
49
|
+
stage = RemoteStage.new(self, name)
|
44
50
|
stage.instance_eval(&block)
|
45
51
|
@stages << stage
|
46
52
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module DockerDeploy
|
2
|
+
class LocalStage < Stage
|
3
|
+
def initialize(context)
|
4
|
+
super(context, :local)
|
5
|
+
@servers = []
|
6
|
+
@deploy = ["docker:build", :restart]
|
7
|
+
end
|
8
|
+
|
9
|
+
def server(server)
|
10
|
+
@servers << SSHKit::Host.new(server)
|
11
|
+
end
|
12
|
+
|
13
|
+
def run(cmd)
|
14
|
+
sh(cmd)
|
15
|
+
end
|
16
|
+
alias_method :run_once, :run
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module DockerDeploy
|
2
|
+
class RemoteStage < Stage
|
3
|
+
def initialize(context, name)
|
4
|
+
super
|
5
|
+
@servers = []
|
6
|
+
end
|
7
|
+
|
8
|
+
def server(server)
|
9
|
+
@servers << SSHKit::Host.new(server)
|
10
|
+
end
|
11
|
+
|
12
|
+
def run(cmd)
|
13
|
+
on servers do
|
14
|
+
execute(cmd)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def run_once(cmd)
|
19
|
+
on servers.first do
|
20
|
+
execute(cmd)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/docker_deploy/stage.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
module DockerDeploy
|
2
2
|
class Stage
|
3
|
-
|
3
|
+
include Rake::FileUtilsExt
|
4
|
+
|
5
|
+
attr_reader :name, :servers, :variables, :links, :env_files, :deploy
|
4
6
|
|
5
7
|
def initialize(context, name)
|
6
8
|
@context = context
|
7
9
|
@name = name
|
8
|
-
@servers = []
|
9
10
|
@env_files = []
|
10
11
|
@variables = {}
|
11
12
|
@ports = {}
|
@@ -29,20 +30,11 @@ module DockerDeploy
|
|
29
30
|
@env_files.push(env_file)
|
30
31
|
end
|
31
32
|
|
32
|
-
def deploy(sequence = nil)
|
33
|
-
@deploy = sequence if sequence
|
34
|
-
@deploy
|
35
|
-
end
|
36
|
-
|
37
33
|
def host(name = nil)
|
38
34
|
@host = name if name
|
39
35
|
@host
|
40
36
|
end
|
41
37
|
|
42
|
-
def server(server)
|
43
|
-
@servers << SSHKit::Host.new(server)
|
44
|
-
end
|
45
|
-
|
46
38
|
def link_mappings
|
47
39
|
format_params("--link %s:%s", @context.links.merge(@links))
|
48
40
|
end
|
data/lib/docker_deploy/task.rb
CHANGED
@@ -26,40 +26,46 @@ module DockerDeploy
|
|
26
26
|
|
27
27
|
desc "Pull down code from the docker registry"
|
28
28
|
task :pull do
|
29
|
-
|
30
|
-
execute :docker, "pull #{context.image}"
|
31
|
-
end
|
29
|
+
stage.run "docker pull #{context.image}"
|
32
30
|
end
|
33
31
|
|
34
32
|
desc "Stop the application and remove its container"
|
35
33
|
task :stop do
|
36
|
-
|
37
|
-
execute :docker, "inspect #{context.container} 2>&1 > /dev/null && docker stop #{context.container} && docker rm #{context.container} || true"
|
38
|
-
end
|
34
|
+
stage.run "docker inspect #{context.container} 2>&1 > /dev/null && docker stop #{context.container} && docker rm #{context.container} || true"
|
39
35
|
end
|
40
36
|
|
41
37
|
desc "Start the application in a container using the latest image."
|
42
38
|
task :start do
|
43
|
-
|
44
|
-
execute :docker, "run -d #{stage.port_mappings} #{stage.link_mappings} #{stage.options} --name #{context.container} #{context.image}:latest"
|
45
|
-
|
46
|
-
puts "\n\nStarted: #{stage.host}\n"
|
47
|
-
end
|
39
|
+
stage.run "docker run -d #{stage.port_mappings} #{stage.link_mappings} #{stage.options} --name #{context.container} #{context.image}:latest"
|
48
40
|
end
|
49
41
|
|
50
42
|
desc "Run migrations in the latest image."
|
51
43
|
task :migrate do
|
52
|
-
|
53
|
-
execute :docker, "run #{stage.link_mappings} #{stage.options} -i -t --rm=true #{context.image}:latest bundle exec rake db:create db:migrate"
|
54
|
-
end
|
44
|
+
stage.run_once "docker run #{stage.link_mappings} #{stage.options} -i -t --rm=true #{context.image}:latest bundle exec rake db:create db:migrate"
|
55
45
|
end
|
56
46
|
|
57
|
-
desc "Run a Rails console in
|
47
|
+
desc "Run a Rails console in a container"
|
58
48
|
task :console do
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
49
|
+
cmd = "docker run #{stage.options} -i -t --rm=true #{stage.link_mappings} #{context.image}:latest bundle exec rails console"
|
50
|
+
if stage.is_a?(RemoteStage)
|
51
|
+
puts "Console is currently broken :("
|
52
|
+
puts "SSH in and run:\n"
|
53
|
+
puts cmd
|
54
|
+
else
|
55
|
+
stage.run_once(cmd)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
desc "Run a shell in a container"
|
60
|
+
task :shell do
|
61
|
+
cmd = "docker run #{stage.options} -i -t --rm=true #{stage.link_mappings} #{context.image}:latest /bin/bash"
|
62
|
+
if stage.is_a?(RemoteStage)
|
63
|
+
puts "Shell is currently broken :("
|
64
|
+
puts "SSH in and run:\n"
|
65
|
+
puts cmd
|
66
|
+
else
|
67
|
+
stage.run_once(cmd)
|
68
|
+
end
|
63
69
|
end
|
64
70
|
|
65
71
|
desc "Restart the running container."
|
data/lib/docker_deploy.rb
CHANGED
@@ -5,6 +5,8 @@ require "shellwords"
|
|
5
5
|
require "docker_deploy/version"
|
6
6
|
require "docker_deploy/context"
|
7
7
|
require "docker_deploy/stage"
|
8
|
+
require "docker_deploy/remote_stage"
|
9
|
+
require "docker_deploy/local_stage"
|
8
10
|
require "docker_deploy/task"
|
9
11
|
|
10
12
|
# Improvement on the broken piece of crap text formatter in SSHKit.
|
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.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonas Nicklas
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-11-
|
12
|
+
date: 2014-11-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sshkit
|
@@ -69,6 +69,8 @@ files:
|
|
69
69
|
- docker_deploy.gemspec
|
70
70
|
- lib/docker_deploy.rb
|
71
71
|
- lib/docker_deploy/context.rb
|
72
|
+
- lib/docker_deploy/local_stage.rb
|
73
|
+
- lib/docker_deploy/remote_stage.rb
|
72
74
|
- lib/docker_deploy/stage.rb
|
73
75
|
- lib/docker_deploy/task.rb
|
74
76
|
- lib/docker_deploy/version.rb
|