dev_dock 0.1.0

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: f1a1ac8d0d731242619e6b019959babddc67264c
4
+ data.tar.gz: 44fef0dbde06722769ea7e31040b810c1ed130a1
5
+ SHA512:
6
+ metadata.gz: 222e0fbbd9a69a97383a79c3c5d72ef9bd21a997e989debf7a72c5accb8f93d2a75112951c75979408b63b8396759461c061c6a8796761aafeb27249885003e7
7
+ data.tar.gz: 8c69529e65f2949cd445fea3a2001cc073268a3c37489865ad8a800aa96b40bd26eb409d9894536259917141946ab93fffb622bec142db3d5459441aa86dae8c
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ dev-dock
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.16.2
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in dev_dock.gemspec
6
+ gemspec
7
+
8
+ gem "docker-api", "~> 1.34"
data/Gemfile.lock ADDED
@@ -0,0 +1,41 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ dev_dock (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ docker-api (1.34.2)
11
+ excon (>= 0.47.0)
12
+ multi_json
13
+ excon (0.62.0)
14
+ multi_json (1.13.1)
15
+ rake (10.5.0)
16
+ rspec (3.7.0)
17
+ rspec-core (~> 3.7.0)
18
+ rspec-expectations (~> 3.7.0)
19
+ rspec-mocks (~> 3.7.0)
20
+ rspec-core (3.7.1)
21
+ rspec-support (~> 3.7.0)
22
+ rspec-expectations (3.7.0)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.7.0)
25
+ rspec-mocks (3.7.0)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.7.0)
28
+ rspec-support (3.7.1)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ bundler (~> 1.16)
35
+ dev_dock!
36
+ docker-api (~> 1.34)
37
+ rake (~> 10.0)
38
+ rspec (~> 3.0)
39
+
40
+ BUNDLED WITH
41
+ 1.16.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 AGhost-7
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # DevDock
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/dev_dock`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'dev_dock'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install dev_dock
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/dev_dock.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "dev_dock"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/dev_dock ADDED
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'dev_dock'
4
+
5
+ $help_text = <<TEXT
6
+ dev_dock <command> <options>
7
+ TEXT
8
+
9
+ def help(code = 1)
10
+ puts $help_text
11
+ exit code
12
+ end
13
+
14
+ if ARGV[0] == "-h" or ARGV[0] == "--help"
15
+ help(0)
16
+ end
17
+
18
+ if ARGV.length != 2
19
+ help
20
+ end
21
+
22
+ subcommand = ARGV.shift
23
+
24
+ if subcommand == "start"
25
+ DevDock::start ARGV[0]
26
+ elsif subcommand == "purge"
27
+ DevDock::purge ARGV[0]
28
+ else
29
+ help
30
+ end
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/dev_dock.gemspec ADDED
@@ -0,0 +1,28 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "dev_dock/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "dev_dock"
8
+ spec.version = DevDock::VERSION
9
+ spec.authors = ["AGhost-7"]
10
+ spec.email = ["jonathan.boudreau.92@gmail.com"]
11
+
12
+ spec.summary = "Manage your docker development environments."
13
+ spec.description = "Manage your development environment (including editor) using docker."
14
+ spec.homepage = "https://github.com/AGhost-7/dev-dock"
15
+ spec.license = "MIT"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.executables = ['dev_dock']
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.16"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+ end
@@ -0,0 +1,80 @@
1
+ require 'docker'
2
+ require 'dev_dock/util'
3
+ require 'dev_dock/image'
4
+ require 'dev_dock/volumes'
5
+
6
+ module DevDock
7
+
8
+ class DevContainer
9
+
10
+ def initialize(image_name)
11
+ @image = DevDock::DevImage.new(image_name)
12
+ @volumes = DevDock::DevVolumes.new(@image)
13
+ @name = DevDock::Util::snake_case("dev_dock_" + image_name)
14
+ end
15
+
16
+ def image
17
+ @image
18
+ end
19
+
20
+ def volumes
21
+ @volumes
22
+ end
23
+
24
+ def exist?
25
+ Docker::Container.get(@name)
26
+ true
27
+ rescue Docker::Error::NotFoundError
28
+ false
29
+ end
30
+
31
+ # kill container
32
+ def kill
33
+ Docker::Container.get(@name).kill
34
+ end
35
+
36
+ def enable_x11(arguments)
37
+ arguments.push '-v'
38
+ arguments.push '/tmp/.X11-unix:/tmp/.X11-unix:ro'
39
+ arguments.push '-e'
40
+ arguments.push 'DISPLAY'
41
+ end
42
+
43
+ def run
44
+ arguments = [
45
+ '/usr/local/bin/docker',
46
+ 'run',
47
+ '--privileged',
48
+ '--name', @name,
49
+ '--net=host',
50
+ '--rm',
51
+ '-ti',
52
+ '--detach-keys',
53
+ 'ctrl-q,ctrl-q',
54
+ '-e', 'GH_USER',
55
+ '-e', 'GH_PASS',
56
+ '-v', '/run/docker.sock:/var/run/docker.sock'
57
+ ]
58
+
59
+ ['workspaces', '.gitconfig', '.ssh'].each do |directory|
60
+ arguments.push '-v', "#{ENV['HOME']}/#{directory}:/home/#{@image.user}/#{directory}"
61
+ end
62
+
63
+ if RUBY_PLATFORM == "x86_64-linux"
64
+ enable_x11(arguments)
65
+ arguments.push '-v', '/etc/localhost:/etc/localhost:ro'
66
+ end
67
+
68
+ @volumes.list.each do |volume|
69
+ arguments.push '--mount', "source=#{volume.name},target=#{volume.path}"
70
+ end
71
+
72
+ arguments.push @image.name
73
+
74
+ arguments.push 'tmux'
75
+ arguments.push 'new'
76
+
77
+ exec *arguments
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,38 @@
1
+ require 'docker'
2
+
3
+ module DevDock
4
+
5
+ class DevImage
6
+
7
+ def initialize(name)
8
+ @name = name
9
+ @container_config = nil
10
+ end
11
+
12
+ def name
13
+ @name
14
+ end
15
+
16
+ def exist?
17
+ Docker::Image::exist?(@name)
18
+ end
19
+
20
+ def pull
21
+ # for some reason pulling images isn't part of the api?
22
+ `docker pull #{name}`
23
+ end
24
+
25
+ def container_config
26
+ if @container_config.nil?
27
+ image = Docker::Image.get(@name)
28
+ @container_config = image.json['ContainerConfig']
29
+ end
30
+ @container_config
31
+ end
32
+
33
+ def user
34
+ return container_config['User']
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,13 @@
1
+ module DevDock
2
+ module Log
3
+ def self.info(*stuff)
4
+ puts *stuff
5
+ end
6
+
7
+ def self.debug(*stuff)
8
+ if ENV['DEV_DOCK_DEBUG'] == '1'
9
+ puts *stuff
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,8 @@
1
+ module DevDock
2
+ module Util
3
+ def self.snake_case(characters)
4
+ characters.downcase.gsub(/\W/, '_')
5
+ end
6
+ end
7
+ end
8
+
@@ -0,0 +1,3 @@
1
+ module DevDock
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,98 @@
1
+ require 'docker'
2
+ require 'dev_dock/util'
3
+ require 'dev_dock/log'
4
+
5
+ # Automatically generated volumes based on what the image has listed in its
6
+ # dockerfile
7
+
8
+ module DevDock
9
+
10
+ # Volume which is needed for the development environment
11
+ class DevVolume
12
+ def initialize(image_name, path)
13
+ @path = path
14
+ @name = DevDock::Util::snake_case("dev_dock_#{image_name}#{path}")
15
+ end
16
+
17
+ def name
18
+ @name
19
+ end
20
+
21
+ def path
22
+ @path
23
+ end
24
+
25
+ # returns true if the volume exists
26
+ def exist?
27
+ volumes = Docker::Util.parse_json(Docker.connection.get('/volumes'))["Volumes"]
28
+ Log::debug("Volumes in docker: #{volumes}")
29
+ volumes.any? { |volume| volume['Name'] == @name }
30
+ end
31
+
32
+ # creates the volume if it does not exist
33
+ def create
34
+ Log::debug("Checking volume #{@name} for path #{@path}")
35
+ if !exist?
36
+ Log::info("Creating volume #{@name}")
37
+ Docker::Volume.create(@name)
38
+ end
39
+ end
40
+
41
+ # removes the volume if it exists
42
+ def remove
43
+ Log::debug("Checking volume #{@name} for path #{@path}")
44
+ if exist?
45
+ Log::info("Removing volume #{@name})")
46
+ Docker::Volume.get(@name).remove
47
+ end
48
+ end
49
+ end
50
+
51
+ # Collection representing volumes needed for then development environment
52
+ class DevVolumes
53
+ def initialize(image)
54
+ @image = image
55
+ end
56
+
57
+ def name
58
+ @name
59
+ end
60
+
61
+ # returns a list of volumes with their names and paths
62
+ def list
63
+ if @image.container_config['Volumes'].nil?
64
+ []
65
+ else
66
+ @image.container_config['Volumes'].keys.map do |path|
67
+ DevVolume.new(@image.name, path)
68
+ end
69
+ end
70
+ end
71
+
72
+ # returns the volume for the given volume path
73
+ def get(path)
74
+ if ! @image.container_config['Volumes'].keys.includes? path
75
+ nil
76
+ else
77
+ DevVolume.new(@image.name, path)
78
+ end
79
+ end
80
+
81
+ # creates all desired volumes based on the configuration in the image
82
+ def create
83
+ Log::debug 'DevVolumes::create'
84
+ list.each do |volume|
85
+ volume.create
86
+ end
87
+ end
88
+
89
+ # purges all related volumes
90
+ def remove
91
+ puts 'DevVolumes::remove'
92
+ list.each do |volume|
93
+ volume.remove
94
+ end
95
+ end
96
+ end
97
+
98
+ end
data/lib/dev_dock.rb ADDED
@@ -0,0 +1,26 @@
1
+ require "dev_dock/container"
2
+ require "dev_dock/log"
3
+
4
+ module DevDock
5
+
6
+ def self.start(name)
7
+ container = DevDock::DevContainer.new(name)
8
+
9
+ if not container.image.exist?
10
+ Log::info('image does not exist, pulling')
11
+ container.image.pull
12
+ end
13
+ container.volumes.create
14
+
15
+ container.run
16
+ end
17
+
18
+ def self.purge(name)
19
+ container = DevDock::DevContainer.new(name)
20
+ if container.exist?
21
+ container.kill
22
+ end
23
+ container.volumes.remove
24
+ end
25
+
26
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dev_dock
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - AGhost-7
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-06-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: Manage your development environment (including editor) using docker.
56
+ email:
57
+ - jonathan.boudreau.92@gmail.com
58
+ executables:
59
+ - dev_dock
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".ruby-gemset"
66
+ - ".travis.yml"
67
+ - Gemfile
68
+ - Gemfile.lock
69
+ - LICENSE.txt
70
+ - README.md
71
+ - Rakefile
72
+ - bin/console
73
+ - bin/dev_dock
74
+ - bin/setup
75
+ - dev_dock.gemspec
76
+ - lib/dev_dock.rb
77
+ - lib/dev_dock/container.rb
78
+ - lib/dev_dock/image.rb
79
+ - lib/dev_dock/log.rb
80
+ - lib/dev_dock/util.rb
81
+ - lib/dev_dock/version.rb
82
+ - lib/dev_dock/volumes.rb
83
+ homepage: https://github.com/AGhost-7/dev-dock
84
+ licenses:
85
+ - MIT
86
+ metadata: {}
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 2.6.11
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: Manage your docker development environments.
107
+ test_files: []