dockersitter 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +4 -0
- data/.gitignore +4 -0
- data/.rspec +1 -0
- data/COPYING.txt +674 -0
- data/ChangeLog.rdoc +4 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +31 -0
- data/Rakefile +36 -0
- data/bin/dockersitter +6 -0
- data/docker_mgr.gemspec +60 -0
- data/gemspec.yml +17 -0
- data/lib/command_router.rb +25 -0
- data/lib/commands/backup_app.rb +51 -0
- data/lib/commands/config.rb +9 -0
- data/lib/commands/create.rb +83 -0
- data/lib/commands/delete.rb +23 -0
- data/lib/commands/generate_backup_scripts.rb +33 -0
- data/lib/commands/init.rb +20 -0
- data/lib/commands/restore_app.rb +56 -0
- data/lib/commands/start.rb +30 -0
- data/lib/docker_mgr/version.rb +4 -0
- data/lib/docker_mgr.rb +1 -0
- data/lib/templates/Dockerfile.erb +5 -0
- data/lib/templates/admin/examples/postgres_backup +5 -0
- data/lib/templates/admin/examples/postgres_restore +4 -0
- data/lib/templates/admin/installation_scripts/install_derby.sh +2 -0
- data/lib/templates/admin/installation_scripts/install_git.sh +2 -0
- data/lib/templates/admin/installation_scripts/install_glassfish.sh +2 -0
- data/lib/templates/admin/installation_scripts/install_java.sh +6 -0
- data/lib/templates/admin/installation_scripts/install_node.sh +12 -0
- data/lib/templates/admin/installation_scripts/install_rust.sh +3 -0
- data/lib/templates/admin/installation_scripts/scriptrunner.sh +19 -0
- data/lib/templates/admin/routines/backup_routine +2 -0
- data/lib/templates/after_all.erb +3 -0
- data/lib/templates/after_all_restore.erb +3 -0
- data/lib/templates/backup.erb +8 -0
- data/lib/templates/before_all.erb +3 -0
- data/lib/templates/before_all_restore.erb +3 -0
- data/lib/templates/docker-compose.yml.erb +15 -0
- data/lib/templates/restore.erb +3 -0
- data/lib/util.rb +120 -0
- data/spec/docker_mgr_spec.rb +8 -0
- data/spec/spec_helper.rb +4 -0
- metadata +176 -0
data/ChangeLog.rdoc
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2015 Rene Richter
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
= docker_mgr
|
2
|
+
|
3
|
+
* {Homepage}[https://rubygems.org/gems/docker_mgr]
|
4
|
+
* {Documentation}[http://rubydoc.info/gems/docker_mgr/frames]
|
5
|
+
* {Email}[mailto:Richterrettich at gmail.com]
|
6
|
+
|
7
|
+
== Description
|
8
|
+
|
9
|
+
TODO: Description
|
10
|
+
|
11
|
+
== Features
|
12
|
+
|
13
|
+
== Examples
|
14
|
+
|
15
|
+
require 'docker_mgr'
|
16
|
+
|
17
|
+
== Requirements
|
18
|
+
|
19
|
+
== Install
|
20
|
+
|
21
|
+
$ gem install docker_mgr
|
22
|
+
|
23
|
+
== Synopsis
|
24
|
+
|
25
|
+
$ docker_mgr
|
26
|
+
|
27
|
+
== Copyright
|
28
|
+
|
29
|
+
Copyright (c) 2015 Rene Richter
|
30
|
+
|
31
|
+
See LICENSE.txt for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'bundler'
|
7
|
+
rescue LoadError => e
|
8
|
+
warn e.message
|
9
|
+
warn "Run `gem install bundler` to install Bundler."
|
10
|
+
exit -1
|
11
|
+
end
|
12
|
+
|
13
|
+
begin
|
14
|
+
Bundler.setup(:development)
|
15
|
+
rescue Bundler::BundlerError => e
|
16
|
+
warn e.message
|
17
|
+
warn "Run `bundle install` to install missing gems."
|
18
|
+
exit e.status_code
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'rake'
|
22
|
+
|
23
|
+
require 'rubygems/tasks'
|
24
|
+
Gem::Tasks.new
|
25
|
+
|
26
|
+
require 'rdoc/task'
|
27
|
+
RDoc::Task.new do |rdoc|
|
28
|
+
rdoc.title = "docker_mgr"
|
29
|
+
end
|
30
|
+
task :doc => :rdoc
|
31
|
+
|
32
|
+
require 'rspec/core/rake_task'
|
33
|
+
RSpec::Core::RakeTask.new
|
34
|
+
|
35
|
+
task :test => :spec
|
36
|
+
task :default => :spec
|
data/bin/dockersitter
ADDED
data/docker_mgr.gemspec
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gemspec = YAML.load_file('gemspec.yml')
|
7
|
+
|
8
|
+
gem.name = gemspec.fetch('name')
|
9
|
+
gem.version = gemspec.fetch('version') do
|
10
|
+
lib_dir = File.join(File.dirname(__FILE__),'lib')
|
11
|
+
$LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
|
12
|
+
|
13
|
+
require 'docker_mgr/version'
|
14
|
+
DockerMgr::VERSION
|
15
|
+
end
|
16
|
+
|
17
|
+
gem.summary = gemspec['summary']
|
18
|
+
gem.description = gemspec['description']
|
19
|
+
gem.licenses = Array(gemspec['license'])
|
20
|
+
gem.authors = Array(gemspec['authors'])
|
21
|
+
gem.email = gemspec['email']
|
22
|
+
gem.homepage = gemspec['homepage']
|
23
|
+
|
24
|
+
glob = lambda { |patterns| gem.files & Dir[*patterns] }
|
25
|
+
|
26
|
+
gem.files = `git ls-files`.split($/)
|
27
|
+
gem.files = glob[gemspec['files']] if gemspec['files']
|
28
|
+
|
29
|
+
gem.executables = gemspec.fetch('executables') do
|
30
|
+
glob['bin/*'].map { |path| File.basename(path) }
|
31
|
+
end
|
32
|
+
gem.default_executable = gem.executables.first if Gem::VERSION < '1.7.'
|
33
|
+
|
34
|
+
gem.extensions = glob[gemspec['extensions'] || 'ext/**/extconf.rb']
|
35
|
+
gem.test_files = glob[gemspec['test_files'] || '{test/{**/}*_test.rb']
|
36
|
+
gem.extra_rdoc_files = glob[gemspec['extra_doc_files'] || '*.{txt,rdoc}']
|
37
|
+
|
38
|
+
gem.require_paths = Array(gemspec.fetch('require_paths') {
|
39
|
+
%w[ext lib].select { |dir| File.directory?(dir) }
|
40
|
+
})
|
41
|
+
|
42
|
+
gem.requirements = gemspec['requirements']
|
43
|
+
gem.required_ruby_version = gemspec['required_ruby_version']
|
44
|
+
gem.required_rubygems_version = gemspec['required_rubygems_version']
|
45
|
+
gem.post_install_message = gemspec['post_install_message']
|
46
|
+
|
47
|
+
split = lambda { |string| string.split(/,\s*/) }
|
48
|
+
|
49
|
+
if gemspec['dependencies']
|
50
|
+
gemspec['dependencies'].each do |name,versions|
|
51
|
+
gem.add_dependency(name,split[versions])
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
if gemspec['development_dependencies']
|
56
|
+
gemspec['development_dependencies'].each do |name,versions|
|
57
|
+
gem.add_development_dependency(name,split[versions])
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/gemspec.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
name: dockersitter
|
2
|
+
summary: "a management tool for docker"
|
3
|
+
description: "generates scripts and projectstructure for docker"
|
4
|
+
license: GPL
|
5
|
+
authors: Rene Richter
|
6
|
+
email: Richterrettich@gmail.com
|
7
|
+
homepage: https://rubygems.org/gems/docker-mgr
|
8
|
+
|
9
|
+
development_dependencies:
|
10
|
+
bundler: ~> 1.0
|
11
|
+
rake: ~> 0.8
|
12
|
+
rdoc: ~> 3.0
|
13
|
+
rspec: ~> 2.4
|
14
|
+
rubygems-tasks: ~> 0.2
|
15
|
+
|
16
|
+
dependencies:
|
17
|
+
thor: ~> 0.19
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "commands/init"
|
2
|
+
require 'thor'
|
3
|
+
require 'commands/create'
|
4
|
+
require 'commands/delete'
|
5
|
+
require 'commands/generate_backup_scripts'
|
6
|
+
require 'commands/backup_app.rb'
|
7
|
+
require 'commands/restore_app.rb'
|
8
|
+
require 'commands/start.rb'
|
9
|
+
require 'util'
|
10
|
+
require 'fileutils'
|
11
|
+
|
12
|
+
module CommandRouter
|
13
|
+
class Main < Thor
|
14
|
+
include DockerMgr::Util
|
15
|
+
|
16
|
+
register(Init, 'init', 'init', 'initializes a docker-project.')
|
17
|
+
register(Create,'create','create','creates a new docker-unit.')
|
18
|
+
register(GenerateBackupScripts,'g','g','generates scripts')
|
19
|
+
register(Delete,'delete','delete','deletes a docker-unit.')
|
20
|
+
register BackupApp,'backup','backup','creates a backup of the given app.'
|
21
|
+
register RestoreApp, 'restore','restore','restores an app.'
|
22
|
+
register Start, 'start','start','starts one or multiple apps. If no apps are given, all apps will be started.'
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'open3'
|
3
|
+
require 'thor/group'
|
4
|
+
|
5
|
+
|
6
|
+
class BackupApp < Thor::Group
|
7
|
+
include DockerMgr::Util
|
8
|
+
|
9
|
+
argument :app_name
|
10
|
+
|
11
|
+
|
12
|
+
def backup
|
13
|
+
app_backup_dir = "#{backup_dir}/#{@app_name}"
|
14
|
+
tmp_dir = "#{app_backup_dir}/tmp"
|
15
|
+
|
16
|
+
FileUtils.mkdir_p app_backup_dir
|
17
|
+
FileUtils.mkdir_p tmp_dir
|
18
|
+
|
19
|
+
before_all = "#{apps_dir}/#{@app_name}/administration/hooks/backup.d/before_all"
|
20
|
+
after_all = "#{apps_dir}/#{@app_name}/administration/hooks/backup.d/after_all"
|
21
|
+
|
22
|
+
FileUtils.cd "#{apps_dir}/#{@app_name}" do
|
23
|
+
puts `#{before_all}` if File.exist? before_all
|
24
|
+
service_hooks_for(@app_name,"backup").each do | service_name |
|
25
|
+
FileUtils.mkdir_p "#{tmp_dir}/#{service_name}"
|
26
|
+
puts "executing #{apps_dir}/#{@app_name}/administration/hooks/backup.d/#{service_name} #{tmp_dir}/#{service_name}"
|
27
|
+
Open3.popen3("#{apps_dir}/#{@app_name}/administration/hooks/backup.d/#{service_name} #{tmp_dir}/#{service_name} 2>&1") do |i,o,e,th|
|
28
|
+
while line=o.gets do
|
29
|
+
puts line
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
puts `#{after_all}` if File.exist? after_all
|
34
|
+
end
|
35
|
+
|
36
|
+
puts `tar czf #{app_backup_dir}/#{@app_name}_#{Time.now.to_i}.tar.gz --directory=#{app_backup_dir} tmp`
|
37
|
+
|
38
|
+
FileUtils.rm_rf tmp_dir
|
39
|
+
|
40
|
+
entries = Dir.entries("#{app_backup_dir}")
|
41
|
+
.select { | entry | entry != "." && entry != ".." && entry.start_with?("#{@app_name}_") }
|
42
|
+
.sort { | a,b | extract_date(b) <=> extract_date(a) }
|
43
|
+
.drop(3)
|
44
|
+
.each { | entry | FileUtils.rm "#{app_backup_dir}/#{entry}"}
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
PROJECT_ROOT = '/home/rene/docker'
|
2
|
+
BACKUP_DIR = "#{PROJECT_ROOT}/backup"
|
3
|
+
APP_DIR = "#{PROJECT_ROOT}/apps"
|
4
|
+
ATTIC_DIR = "#{PROJECT_ROOT}/attic"
|
5
|
+
ADMIN_DIR = "#{PROJECT_ROOT}/admin"
|
6
|
+
TEMPLATE_DIR = "#{ADMIN_DIR}/templates"
|
7
|
+
PACKAGE_DIR = "#{ADMIN_DIR}/installation_scripts"
|
8
|
+
ROUTINE_DIR = "#{ADMIN_DIR}/routines"
|
9
|
+
BASE_IMAGE_DIR = "#{PROJECT_ROOT}/base_images"
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'erb'
|
4
|
+
require_relative '../util'
|
5
|
+
|
6
|
+
class Create < Thor
|
7
|
+
include Thor::Actions
|
8
|
+
include DockerMgr::Util
|
9
|
+
|
10
|
+
def self.source_root
|
11
|
+
File.expand_path('../templates',__dir__)
|
12
|
+
end
|
13
|
+
|
14
|
+
class_option :image,
|
15
|
+
:type => :string,
|
16
|
+
:desc => "the image which the app is based on.",
|
17
|
+
:alias => 'i',
|
18
|
+
:default => "ubuntu:14.04"
|
19
|
+
|
20
|
+
class_option :env,
|
21
|
+
:type => :array,
|
22
|
+
:desc => 'additional environment variables',
|
23
|
+
:alias => 'e',
|
24
|
+
:default => []
|
25
|
+
|
26
|
+
class_option :packages,
|
27
|
+
:type => :array,
|
28
|
+
:desc => 'additional packages to install',
|
29
|
+
:alias => 'p',
|
30
|
+
:default => []
|
31
|
+
|
32
|
+
class_option :volumes,
|
33
|
+
:type => :array,
|
34
|
+
:desc => 'the volumes your data-container will mount',
|
35
|
+
:alias => 'v',
|
36
|
+
:default => ["/var"]
|
37
|
+
|
38
|
+
desc "app APP_NAME", "create a new app."
|
39
|
+
option :dockerfile,
|
40
|
+
:type => :boolean,
|
41
|
+
:desc => 'create a dockerfile for the app',
|
42
|
+
:aliases => 'd'
|
43
|
+
def app(app_name)
|
44
|
+
@app_name = app_name
|
45
|
+
@user_email = extract_email
|
46
|
+
@user_name = extract_name
|
47
|
+
app_path = "#{apps_dir}/#{@app_name}"
|
48
|
+
template "docker-compose.yml.erb","#{app_path}/docker-compose.yml"
|
49
|
+
empty_directory "#{app_path}/administration/installation"
|
50
|
+
empty_directory "#{app_path}/administration/hooks/backup.d"
|
51
|
+
empty_directory "#{app_path}/administration/hooks/restore.d"
|
52
|
+
template "Dockerfile.erb","#{app_path}/Dockerfile" if options[:dockerfile]
|
53
|
+
unless options[:packages].empty?
|
54
|
+
options[:packages].each do |package|
|
55
|
+
FileUtils.ln("#{install_dir}/install_#{package}.sh",
|
56
|
+
"#{app_path}/administration/installation/install_#{package}.sh")
|
57
|
+
end
|
58
|
+
|
59
|
+
FileUtils.ln("#{install_dir}/scriptrunner.sh",
|
60
|
+
"#{app_path}/administration/scriptrunner.sh")
|
61
|
+
end
|
62
|
+
append_to_file "#{routine_dir}/backup_routine", "docker_mgr backup_app #{app_name}"
|
63
|
+
end
|
64
|
+
|
65
|
+
desc "image IMAGE_NAME","creates a new image."
|
66
|
+
def image(image_name)
|
67
|
+
@user_email = extract_email
|
68
|
+
@user_name = extract_name
|
69
|
+
image_path = "#{base_images_dir}/#{image_name}"
|
70
|
+
empty_directory "#{image_path}/administration/installation"
|
71
|
+
template "Dockerfile.erb","#{image_path}/Dockerfile"
|
72
|
+
unless options[:packages].empty?
|
73
|
+
options[:packages].each do |package|
|
74
|
+
FileUtils.ln("#{install_dir}/install_#{package}.sh",
|
75
|
+
"#{image_path}/administration/installation/install_#{package}.sh")
|
76
|
+
end
|
77
|
+
|
78
|
+
FileUtils.ln("#{install_dir}/scriptrunner.sh",
|
79
|
+
"#{image_path}/administration/scriptrunner.sh")
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'util'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
class Delete < Thor
|
5
|
+
include Thor::Actions
|
6
|
+
include DockerMgr::Util
|
7
|
+
|
8
|
+
desc 'app APP_NAME','deletes an app'
|
9
|
+
def app(app_name)
|
10
|
+
@app_name = app_name
|
11
|
+
abort "#{@app_name} is not a valid app" unless Dir.exist? "#{apps_dir}/#{@app_name}"
|
12
|
+
choice = ask "do you want to remove #{@app_name}? (y,N)"
|
13
|
+
abort "aborting" unless choice == 'y'
|
14
|
+
FileUtils.cd "#{apps_dir}/#{@app_name}" do
|
15
|
+
puts `echo y | sudo docker-compose rm`
|
16
|
+
end
|
17
|
+
puts `tar -zcf #{attic_dir}/#{@app_name}.tar -C #{apps_dir} #{@app_name}`
|
18
|
+
FileUtils.rm_rf "#{apps_dir}/#{@app_name}"
|
19
|
+
FileUtils.rm_rf "#{backup_dir}/#{@app_name}"
|
20
|
+
remove_line_from_routine("backup_routine","docker_mgr backup_app #{@app_name}")
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'util'
|
3
|
+
require 'yaml'
|
4
|
+
require 'thor'
|
5
|
+
require 'thor/group'
|
6
|
+
|
7
|
+
class GenerateBackupScripts < Thor::Group
|
8
|
+
include DockerMgr::Util
|
9
|
+
include Thor::Actions
|
10
|
+
|
11
|
+
def self.source_root
|
12
|
+
File.expand_path('../templates',__dir__)
|
13
|
+
end
|
14
|
+
|
15
|
+
argument :app_name,
|
16
|
+
:type => :string,
|
17
|
+
:desc => 'name of the app'
|
18
|
+
|
19
|
+
def generate_backup_scripts
|
20
|
+
app_path = "#{apps_dir}/#{@app_name}"
|
21
|
+
hooks = data_services(@app_name)
|
22
|
+
hooks << "before_all"
|
23
|
+
hooks << "after_all"
|
24
|
+
%w(backup restore).each do | hook_type |
|
25
|
+
hooks.each do | hook |
|
26
|
+
@service = hook
|
27
|
+
template_name = hook == 'before_all' || hook == 'after_all' ? hook : hook_type
|
28
|
+
template "#{template_name}.erb","#{app_path}/administration/hooks/#{hook_type}.d/#{hook}"
|
29
|
+
FileUtils.chmod 0750,"#{app_path}/administration/hooks/#{hook_type}.d/#{hook}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "thor/group"
|
2
|
+
|
3
|
+
class Init < Thor::Group
|
4
|
+
include Thor::Actions
|
5
|
+
|
6
|
+
def self.source_root
|
7
|
+
File.expand_path('../templates',__dir__)
|
8
|
+
end
|
9
|
+
|
10
|
+
def project_structure
|
11
|
+
empty_directory "docker/apps"
|
12
|
+
empty_directory "docker/attic"
|
13
|
+
empty_directory "docker/backup"
|
14
|
+
empty_directory "docker/base_images"
|
15
|
+
directory "admin","docker/admin"
|
16
|
+
empty_directory "docker/ci_runner"
|
17
|
+
puts `git init docker`
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|