harbordock 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.12.3
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at leet944@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in harbor.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Lee Thomas
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,77 @@
1
+ # ⚓️ Harbor ⚓️
2
+
3
+ Tired of copying & pasting between different Dockerfiles? Harbor lets you take the re-useable parts of your Dockerfiles and combine them into one.
4
+
5
+ ## Disclaimer
6
+ This gem is not officially supported by Docker. Use at your own risk.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'harbordock'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install harbordock
23
+
24
+ ## Usage
25
+
26
+ This gem takes Dockerfile instructions written in a `Harborfile` and outputs them to a `Dockerfile`. Harborfiles are just like Dockerfiles, except they support the `INCLUDE` directive. Files get included from `~/.harbor/harborfiles` and must have a `.harbor` extension name.
27
+
28
+ Example `Harborfile`:
29
+
30
+ ```
31
+ FROM ubuntu
32
+
33
+ # Harbofiles support INCLUDE
34
+ INCLUDE ruby-2.3 # <- Located at ~/.harbor/harborfiles/ruby-2.3.harbor
35
+
36
+ RUN echo "Hello world"
37
+ ```
38
+
39
+ ```
40
+ # ~/.harbor/harborfiles/ruby-2.3.harbor
41
+ RUN sudo apt-get install ruby2.3 ruby2.3-dev
42
+ RUN touch test.rb
43
+ ```
44
+
45
+ The resulting Dockerfile looks like:
46
+ ```
47
+ FROM ubuntu
48
+
49
+ # Harbofiles support INCLUDE
50
+ # ~/.harbor/harborfiles/ruby-2.3.harbor
51
+ RUN sudo apt-get install ruby2.3 ruby2.3-dev
52
+ RUN touch test.rb
53
+
54
+ RUN echo "Hello world"
55
+ ```
56
+
57
+ ### Command Line
58
+ ```
59
+ $ harbor <YOUR_HARBORFILE> [<DOCKERFILE_OUTPUT_PATH>]
60
+ ```
61
+
62
+ ### Ruby
63
+ ```ruby
64
+ require 'harbor'
65
+ Harbor::Harborfile.new('./Harborfile')
66
+ # Dockerfile written to ./Dockerfile
67
+ ```
68
+
69
+ ## Contributing
70
+
71
+ Bug reports and pull requests are welcome on GitHub at https://github.com/leethomas/harbor. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
72
+
73
+
74
+ ## Author & License
75
+ [Lee Thomas](https://github.com/leethomas)
76
+ [leet944@gmail.com](mailto:leet944@gmail.com)
77
+ The gem is available as open source under the terms of the [MIT License](http://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 "harbor"
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
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/exe/harbor ADDED
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'harbor'
4
+ require 'optparse'
5
+
6
+ def setup
7
+ puts 'Creating ~/.harbor/harborfiles'
8
+ home_path = File.expand_path('~')
9
+
10
+ Dir.mkdir(File.expand_path('.harbor', home_path))
11
+ Dir.mkdir(File.expand_path('.harbor/harborfiles', home_path))
12
+ end
13
+
14
+ def ensure_config_exists
15
+ harborfile_dir = File.expand_path('~/.harbor/harborfiles')
16
+
17
+ if !Dir.exists?(harborfile_dir)
18
+ puts "You don't have a .harbor/harborfiles folder setup in your home directory."
19
+ print 'This is where Harbor loads .harbor files from. Do you want to set one up now? [Y\n]: '
20
+ res = gets
21
+
22
+ if res.strip.downcase == 'y'
23
+ setup
24
+ if Dir.exists?(harborfile_dir)
25
+ puts 'Done!'
26
+ else
27
+ puts "Wasn't able to create the directory for some reason..."
28
+ end
29
+ else
30
+ puts 'Ok, exiting'
31
+ exit
32
+ end
33
+ end
34
+ end
35
+
36
+ options = {}
37
+
38
+ OptionParser.new do |opts|
39
+ opts.banner = 'Usage: harbor <YOUR_HARBORFILE> [-o <DOCKERFILE_OUTPUT_PATH>]'
40
+
41
+ opts.on('-o path', '--dockerfile=path', 'Specify the path of the resultant Dockerfile') do |path|
42
+ options[:dockerfile] = path
43
+ end
44
+
45
+ opts.on_tail('-h', '--help', 'Show usage instructions') do
46
+ puts opts
47
+ exit
48
+ end
49
+ end.parse!
50
+
51
+ ensure_config_exists
52
+
53
+ harborfile = ARGV.first
54
+
55
+ begin
56
+ Harbor::Harborfile.new(harborfile, options[:dockerfile])
57
+ rescue => e
58
+ puts e.message
59
+ exit(1)
60
+ end
data/harbor.gemspec ADDED
@@ -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
+ require 'harbor/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'harbordock'
8
+ spec.version = Harbor::VERSION
9
+ spec.author = 'Lee Thomas'
10
+ spec.email = 'leet944@gmail.com'
11
+
12
+ spec.summary = %q{Combine multiple Dockerfiles into one.}
13
+ spec.homepage = 'https://github.com/leethomas/harbor'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = 'exe'
18
+ spec.executables = ['harbor']
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.12'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'rspec', '~> 3.0'
24
+ end
@@ -0,0 +1,65 @@
1
+ module Harbor::Directives
2
+ require 'set'
3
+ SUPPORTED_DIRECTIVES = Set['INCLUDE']
4
+
5
+ class << self
6
+ def run_directive(line, fstream)
7
+ cmd, *args = parse_directive(line)
8
+
9
+ if cmd.nil?
10
+ # nothing to do, just write the line straight to the file
11
+ fstream.write(line)
12
+ fstream.flush
13
+ else
14
+ directive = const_get(cmd.downcase.capitalize)
15
+ directive.run(fstream, args)
16
+ end
17
+ end
18
+
19
+ def parse_directive(line)
20
+ instructions = line.split
21
+ cmd = instructions.first
22
+
23
+ if Harbor::Directives::SUPPORTED_DIRECTIVES.include?(cmd)
24
+ [cmd] + instructions[1..-1].join.split(',')
25
+ else
26
+ return []
27
+ end
28
+ end
29
+ end
30
+
31
+ module Include
32
+ class UnsupportedHarborFileError < StandardError; end
33
+ class << self
34
+ def run(fstream, args)
35
+ check_validity(fstream, args)
36
+ filename = args.first
37
+ file_to_include = get_harbor_path(filename)
38
+
39
+ File.open(file_to_include, 'r') do |file|
40
+ file.each_line { |line| Harbor::Directives.run_directive(line, fstream) }
41
+ end
42
+ end
43
+
44
+ def get_harbor_path(filename)
45
+ harborfiles_dir = File.expand_path("#{Harbor.config_dir}/harborfiles")
46
+ harbor_name = filename + '.harbor'
47
+ local_path = File.expand_path(harbor_name)
48
+ harbor_path = File.expand_path(harbor_name, harborfiles_dir)
49
+
50
+ if File.exists?(local_path)
51
+ local_path
52
+ elsif File.exists?(harbor_path)
53
+ harbor_path
54
+ else
55
+ raise Errno::ENOENT, %Q{Could not find #{harbor_name} in
56
+ #{harborfiles_dir} or current directory.}
57
+ end
58
+ end
59
+
60
+ def check_validity(fstream, args)
61
+ raise ArgumentError if args.empty? || args.length > 1
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,29 @@
1
+ class Harbor::Harborfile
2
+ DEFAULT_OUTPUT_FILE = 'Dockerfile'
3
+ DEFAULT_INPUT_FILE = 'Harborfile'
4
+
5
+ def initialize(harborfile=nil, dockerfile=nil)
6
+ src_file = harborfile || DEFAULT_INPUT_FILE
7
+ output_file = dockerfile || DEFAULT_OUTPUT_FILE
8
+
9
+ @harborfile = File.expand_path(src_file)
10
+ @dockerfile = File.expand_path(output_file)
11
+
12
+ build_dockerfile
13
+ end
14
+
15
+ def build_dockerfile
16
+ raise 'Dockerfile already exists!' if File.exists?(@dockerfile)
17
+ docker_fstream = File.open(@dockerfile, 'w+')
18
+
19
+ raise Errno::ENOENT, "Can't find Harborfile" unless File.exists?(@harborfile)
20
+
21
+ File.open(@harborfile, 'r') do |hf|
22
+ hf.each_line do |line|
23
+ Harbor::Directives.run_directive(line, docker_fstream)
24
+ end
25
+ end
26
+
27
+ docker_fstream.close
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ module Harbor
2
+ VERSION = "0.1.0"
3
+ end
data/lib/harbor.rb ADDED
@@ -0,0 +1,10 @@
1
+ module Harbor
2
+ class << self
3
+ attr_accessor :config_dir
4
+ end
5
+ end
6
+
7
+ Harbor.config_dir = File.expand_path('~/.harbor')
8
+
9
+ require 'harbor/directives'
10
+ require 'harbor/harborfile'
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: harbordock
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Lee Thomas
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2016-10-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.12'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.12'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '10.0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '10.0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '3.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ description:
63
+ email: leet944@gmail.com
64
+ executables:
65
+ - harbor
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - .rspec
71
+ - .travis.yml
72
+ - CODE_OF_CONDUCT.md
73
+ - Gemfile
74
+ - LICENSE.txt
75
+ - README.md
76
+ - Rakefile
77
+ - bin/console
78
+ - bin/setup
79
+ - exe/harbor
80
+ - harbor.gemspec
81
+ - lib/harbor.rb
82
+ - lib/harbor/directives.rb
83
+ - lib/harbor/harborfile.rb
84
+ - lib/harbor/version.rb
85
+ homepage: https://github.com/leethomas/harbor
86
+ licenses:
87
+ - MIT
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ! '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 1.8.23
107
+ signing_key:
108
+ specification_version: 3
109
+ summary: Combine multiple Dockerfiles into one.
110
+ test_files: []