capistrano-docker 0.0.01

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a592fc849c9d22346829a7c36469511f958f6ed4
4
+ data.tar.gz: c54393b6fa06d26e7af161d460b5c597ab55fadc
5
+ SHA512:
6
+ metadata.gz: 3da59a8592defba7141b6c595ff6251f635bf1abe3b958277112510b5ed04dd314d385e09972ef1e8ff8a9bde71793f1fbe8919015be045e537baf33da7b859b
7
+ data.tar.gz: cbfa3ff8723cf116ffd84c65048b2854ce4a5bcb2f911aca40917fd0fb58ef0c58a01d2ed6b841bce92b4285dd3a6d819a5cb56d48507bc8f0ebee5fe9d5ee2f
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ .DS_*
2
+ *.gem
3
+ .bundle
4
+ Gemfile.lock
5
+ pkg/*
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # Capistrano - Docker Appliance Deploy
2
+
3
+ This project aims to make it simple to deploy multiple apps inside Docker containers to an overall Docker Host.
4
+
5
+ ### Opinionated File Structure
6
+
7
+ To make the process as simple as possible this project specifies an opinianated file structure, it will be much easier to start with a clean slate rather than trying to backport this to legacy file setup.
8
+
9
+ Apps are namespaced by an account and an application, in a similar concept to Github account/repo structure.
10
+
11
+ ### Persistent Data Support
12
+
13
+ There is support for persistent storage via configuration of volumes. Multiple volumes are supported for each project.
14
+
15
+ ### Installation & Required Configuration
16
+
17
+ To get started you will need the following setup.
18
+
19
+ 1. A local git repo that stores your project file
20
+ 2. The root of the project needs a Dockerfile that handles the container build
21
+ 3. A remote server with Docker installed and a preferably empty filesystem for the specified user.
22
+ 4. A local Capfile that handles the configuration for the deploy.
23
+
24
+ Here's an example of the minimum requirements for your local Capfile.
25
+
26
+ ```
27
+ require 'rubygems'
28
+ require 'bundler/setup'
29
+ require 'capistrano/setup'
30
+ require 'capistrano/docker'
31
+
32
+ set :namespace, "yournamespace"
33
+ set :application, "yourapp"
34
+ set :port, "59999"
35
+ set :stage, "production"
36
+
37
+ task :production do
38
+ set :branch, "master"
39
+ server 'docker.yourserver.com', user: 'docker', roles: %w{host}
40
+ end
41
+
42
+ ```
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'capistrano-docker'
7
+ spec.version = '0.0.01'
8
+ spec.authors = ["Ross Riley"]
9
+ spec.email = ["riley.ross@gmail.com"]
10
+ spec.description = %q{Docker support for Capistrano 3.x}
11
+ spec.summary = %q{Docker support for Capistrano 3.x}
12
+ spec.homepage = 'https://github.com/rossriley/capistrano-docker'
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_dependency 'capistrano', '>= 3.1'
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.3'
23
+ spec.add_development_dependency 'rake'
24
+ end
@@ -0,0 +1,3 @@
1
+ load File.expand_path('../tasks/docker.rake', __FILE__)
2
+ load File.expand_path('../tasks/deploy.rake', __FILE__)
3
+
@@ -0,0 +1,137 @@
1
+ namespace :deploy do
2
+
3
+
4
+ desc "Checks that the required configuration parameters are set"
5
+ task :check do
6
+ on roles :all do
7
+ if roles(:host).length==0
8
+ error "You do not have any host machines defined in your capfile. Try eg: server 'host.example.com', user:youruser, roles: %w{host}"
9
+ exit
10
+ end
11
+ if !fetch(:ports) || fetch(:ports).length ==0
12
+ error "You do not have any port mappings defined in your capfile. Try eg: set :ports, {11111=>80}"
13
+ exit
14
+ end
15
+ if !fetch(:namespace)
16
+ error "You do not have a docker namespace variable defined in your capfile. Try eg: set :namespace, yourname"
17
+ exit
18
+ end
19
+ if !fetch(:password)
20
+ error "You do not have an application password defined in your capfile. Try eg: set :password, secret1234"
21
+ exit
22
+ end
23
+ if !File.exists?('Dockerfile')
24
+ error "You need to have a Dockerfile setup in the root of your project"
25
+ exit
26
+ end
27
+ run_locally do
28
+ outp = capture "git ls-files Dockerfile"
29
+ if outp.length == 0
30
+ error "You need to have a Dockerfile commited into the root of your project. Try using: git add Dockerfile and then git commit"
31
+ exit
32
+ end
33
+ end
34
+
35
+ end
36
+ end
37
+
38
+ desc "Builds project locally ready for deploy."
39
+ task :build do
40
+ puts "Preparing local build: note, only code commited to your local Git repository will be included."
41
+
42
+ run_locally do
43
+ begin
44
+ capture "ls tmp/build/.git"
45
+ rescue
46
+ execute "mkdir -p tmp/build"
47
+ execute "cd tmp/build && git clone ../../ ."
48
+ end
49
+
50
+ execute "cd tmp/build/ && git fetch && git checkout -f origin/HEAD"
51
+
52
+ fetch(:build_commands).each do |command|
53
+ execute "cd tmp/build && "+command
54
+ end
55
+
56
+ execute "echo '"+fetch(:start_commands, []).join(';\n') +"' > tmp/build/start.sh"
57
+ execute "chmod +x tmp/build/start.sh"
58
+
59
+ end
60
+
61
+
62
+ end
63
+
64
+ desc "Updates the code on the remote container"
65
+ task :update do
66
+ on roles :host do |host|
67
+ info " Running Rsync to: #{host.user}@#{host.hostname}"
68
+ run_locally do
69
+ execute "rsync -rup --exclude '.git' tmp/build/* #{host.user}@#{host.hostname}:#{fetch(:docker_buildpath)}/"
70
+ end
71
+ end
72
+ end
73
+
74
+ task :container do
75
+ invoke "docker:prepare"
76
+ end
77
+
78
+ task :deploy do
79
+ invoke "docker:build"
80
+ end
81
+
82
+ task :proxy do
83
+ on roles :host do |host|
84
+ config = ""
85
+ fetch(:proxies).each do |proxy,port|
86
+ config << "server {" + "\n"
87
+ config << " server_name "+proxy+";" + "\n"
88
+ config << " location / {" + "\n"
89
+ config << " proxy_pass http://127.0.0.1:"+port+"/;" + "\n"
90
+ config << " proxy_set_header Host $http_host;" + "\n"
91
+ config << " }" + "\n"
92
+ config << "}" + "\n"
93
+ end
94
+ basepath = "dockerappliance/conf/nginx/"
95
+ destination = basepath + fetch(:docker_appname)+".conf"
96
+ io = StringIO.new(config)
97
+ upload! io, destination
98
+ end
99
+ end
100
+
101
+ task :supervisor do
102
+ on roles :host do |host|
103
+ config = ""
104
+ config << "[program:"+fetch(:docker_appname)+"]"+"\n"
105
+ config << "command=docker start -a "+fetch(:docker_appname) + "\n"
106
+ config << "autorestart=true"+"\n"
107
+ destination = "dockerappliance/conf/supervisor/" + fetch(:docker_appname)+".conf"
108
+ io = StringIO.new(config)
109
+ upload! io, destination
110
+ end
111
+ end
112
+
113
+ task :restart do
114
+ on roles :host do |host|
115
+ execute "sudo service nginx restart"
116
+ end
117
+ end
118
+
119
+
120
+ task :finished do
121
+
122
+ end
123
+
124
+ end
125
+
126
+ desc 'Deploy a new release.'
127
+ task :deploy do
128
+ set(:deploying, true)
129
+ %w{ check build container update deploy proxy supervisor restart finished }.each do |task|
130
+ invoke "deploy:#{task}"
131
+ end
132
+ end
133
+ task default: :deploy
134
+ invoke 'load:defaults'
135
+
136
+
137
+
@@ -0,0 +1,52 @@
1
+ namespace :docker do
2
+
3
+
4
+ desc "Prepares the container to store structured docker apps"
5
+ task :prepare do
6
+ on roles :host do
7
+ execute "mkdir -p #{fetch(:docker_buildpath)}"
8
+ execute "mkdir -p #{fetch(:docker_mountpath)}"
9
+ end
10
+ end
11
+
12
+ desc "build an updated box, restart container"
13
+ task :build do
14
+ on roles :host do
15
+ execute "docker build --no-cache=true -t #{fetch(:docker_appname)}_img #{fetch(:docker_buildpath)}/"
16
+ execute "docker kill #{fetch(:docker_appname)}" rescue ""
17
+ execute "docker rm #{fetch(:docker_appname)}" rescue ""
18
+ execute build_run_command
19
+ end
20
+ end
21
+
22
+ def build_run_command()
23
+ cmd = "docker run "
24
+ fetch(:ports).each do |port,map|
25
+ cmd << "-p #{port}:#{map} "
26
+ end
27
+ fetch(:volumes).each do |name,vol|
28
+ execute "mkdir -p -m7777 #{fetch(:docker_mountpath)}/#{name}"
29
+ cmd << "-v `pwd`/#{fetch(:docker_mountpath)}/#{name}:#{vol}:rw "
30
+ end
31
+ cmd << "-name #{fetch(:docker_appname)} "
32
+ cmd << "-e APP_USER='#{fetch(:docker_appname)}' "
33
+ cmd << "-e APP_PASS='#{fetch(:password)}' "
34
+ cmd << "-e APP_DB='#{fetch(:docker_appname)}' "
35
+ cmd << "-d -t #{fetch(:docker_appname)}_img:latest "
36
+ cmd
37
+ end
38
+ end
39
+
40
+ namespace :load do
41
+
42
+ task :defaults do
43
+
44
+ set :docker_workpath, -> { "dockerappliance/containers/#{fetch(:namespace)}/#{fetch(:application)}" }
45
+ set :docker_buildpath, -> { "#{fetch(:docker_workpath)}/config" }
46
+ set :docker_mountpath, -> { "#{fetch(:docker_workpath)}/mounts" }
47
+ set :docker_appname, -> { "#{fetch(:namespace)}_#{fetch(:application)}" }
48
+
49
+
50
+ end
51
+
52
+ end
File without changes
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-docker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.01
5
+ platform: ruby
6
+ authors:
7
+ - Ross Riley
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capistrano
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Docker support for Capistrano 3.x
56
+ email:
57
+ - riley.ross@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - README.md
64
+ - capistrano-docker.gemspec
65
+ - lib/capistrano-docker.rb
66
+ - lib/capistrano/docker.rb
67
+ - lib/capistrano/tasks/deploy.rake
68
+ - lib/capistrano/tasks/docker.rake
69
+ homepage: https://github.com/rossriley/capistrano-docker
70
+ licenses:
71
+ - MIT
72
+ metadata: {}
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubyforge_project:
89
+ rubygems_version: 2.1.10
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: Docker support for Capistrano 3.x
93
+ test_files: []