docker_task 0.1.2

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: de7a48febd51c58d4f82de385472a2e6fd82cbae
4
+ data.tar.gz: ac45b1cceac6624362c841a3ad2ae6b08d3ee2af
5
+ SHA512:
6
+ metadata.gz: d5e8be98ea06453f09a342a8a64b10d44108f25e2939236df4765845dcc2f3aa1345164c51ef14d837bbc1d84ed211c5c5776c2e8479b3a07b64ca5e6b6f2e3b
7
+ data.tar.gz: 8597d52ed58d07413a554ee41415963b9073b8578e58b2727c4561bf575bdb8eab62a20133adc1e5fbbb98794d3ea9e55110b57ca6c5819a116ef74b6af68ced
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ docker_task-*.gem
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.14.6
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at hi@markjeee.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in docker_task.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Mark John Buenconsejo
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,40 @@
1
+ # DockerTask
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/docker_task`. 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 'docker_task'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install docker_task
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 test` 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/nlevel/docker_task. 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.
36
+
37
+
38
+ ## License
39
+
40
+ 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,16 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+ require "gemfury/tasks"
4
+
5
+ Rake::TestTask.new(:test) do |t|
6
+ t.libs << "test"
7
+ t.libs << "lib"
8
+ t.test_files = FileList['test/**/*_test.rb']
9
+ end
10
+
11
+ task :default => :test
12
+
13
+ desc "Perform gem build and push to Gemfury as 'nlevel'"
14
+ task :fury_release do
15
+ Rake::Task['fury:release'].invoke(nil, 'nlevel')
16
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "docker_task"
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/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
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'docker_task/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "docker_task"
8
+ spec.version = DockerTask::VERSION
9
+ spec.authors = ["Mark John Buenconsejo"]
10
+ spec.email = ["mark@nlevel.io"]
11
+
12
+ spec.summary = %q{A rake helper in working with Docker containers.}
13
+ spec.description = %q{A rake helper of common tasks for use when working with Docker containers.}
14
+ spec.homepage = "https://github.com/nlevel/docker_task"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_dependency "rake"
34
+
35
+ spec.add_development_dependency "bundler", "~> 1.14"
36
+ spec.add_development_dependency "rake", "~> 10.0"
37
+ spec.add_development_dependency "minitest", "~> 5.0"
38
+ spec.add_development_dependency "gemfury"
39
+ end
@@ -0,0 +1,9 @@
1
+ require "docker_task/version"
2
+
3
+ module DockerTask
4
+ autoload :Task, 'docker_task/task'
5
+
6
+ def self.include_tasks(options = { })
7
+ Task.new(options).define!
8
+ end
9
+ end
@@ -0,0 +1,203 @@
1
+ require 'rake'
2
+ require 'rake/task'
3
+ require 'rake/tasklib'
4
+
5
+ module DockerTask
6
+ class Task < Rake::TaskLib
7
+ DEFAULT_OPTIONS = {
8
+ :namespace => :docker
9
+ }
10
+
11
+ DOCKER_CMD = 'docker'
12
+
13
+ attr_reader :options
14
+
15
+ def initialize(options = { })
16
+ @options = DEFAULT_OPTIONS.merge(options)
17
+ yield(self) if block_given?
18
+ end
19
+
20
+ def task_namespace
21
+ @options[:namespace]
22
+ end
23
+ alias :ns :task_namespace
24
+
25
+ def container_name
26
+ @options[:container_name]
27
+ end
28
+
29
+ def image_name
30
+ @options[:image_name]
31
+ end
32
+
33
+ def define!
34
+ namespace ns do
35
+ desc 'Perform whole cycle of destroy (if any), build, and run'
36
+ task :reset do
37
+ invoke_task('destroy')
38
+ invoke_task('build')
39
+ invoke_task('run')
40
+ end
41
+
42
+ desc 'Rebuild the docker image'
43
+ task :rebuild do
44
+ invoke_task('destroy')
45
+ invoke_task('build')
46
+ end
47
+
48
+ desc 'Build a new docker image based on the Dockerfile'
49
+ task :build do
50
+ docker_do 'build -t %s .' % image_name
51
+ end
52
+
53
+ desc 'Show help, and how to use this docker tool'
54
+ task :help do
55
+ puts help_text
56
+ end
57
+
58
+ desc 'Run the latest docker image'
59
+ task :run do
60
+ run_opts = [ ]
61
+
62
+ if ENV['INTERACTIVE'] == '1'
63
+ run_opts << '--rm -t -i'
64
+ else
65
+ run_opts = @options[:run].call(self, run_opts)
66
+
67
+ run_opts << '-d'
68
+ run_opts << '--name=%s' % container_name
69
+ end
70
+
71
+ run_opts << '%s:%s' % [ @options[:image_name], @options.fetch(:image_tag, 'latest') ]
72
+
73
+ if ENV['INTERACTIVE'] == '1'
74
+ docker_do 'run %s %s' % [ run_opts.join(' '), '/bin/bash -l' ], :ignore_fail => true
75
+ else
76
+ docker_do 'run %s' % run_opts.join(' ')
77
+ end
78
+ end
79
+
80
+ desc 'Run docker in interactive mode (with bash shell)'
81
+ task :runi do
82
+ ENV['INTERACTIVE'] = '1'
83
+ invoke_task('run')
84
+ end
85
+
86
+ task :bash do
87
+ if @options.include?(:bash)
88
+ exec_cmd = @options[:bash]
89
+ else
90
+ exec_cmd = 'bash -l'
91
+ end
92
+
93
+ docker_do('exec -it %s %s' % [ container_name, exec_cmd ], :ignore_fail => true)
94
+ end
95
+
96
+ desc 'Run docker container'
97
+ task :start do
98
+ docker_do 'start %s' % container_name
99
+ end
100
+
101
+ desc 'Stop docker container'
102
+ task :stop do
103
+ docker_do 'stop %s; true' % container_name
104
+ end
105
+
106
+ desc 'Restart docker container'
107
+ task :restart do
108
+ invoke_task('stop')
109
+ invoke_task('start')
110
+ end
111
+
112
+ desc 'Delete container, and create a new one'
113
+ task :reload do
114
+ docker_do 'kill %s; true' % container_name
115
+ docker_do 'rm %s; true' % container_name
116
+
117
+ invoke_task('run')
118
+ end
119
+
120
+ desc 'Push latest built image to repo'
121
+ task :push do
122
+ if @options[:push_repo]
123
+ should_create_tag = false
124
+
125
+ if !ENV['PUSH_MIRROR'].nil? && !ENV['PUSH_MIRROR'].empty?
126
+ mk = ENV['PUSH_MIRROR']
127
+ pm = @options[:push_mirrors]
128
+
129
+ if !pm.nil? && !pm.empty?
130
+ push_repo = pm[mk.to_sym]
131
+ else
132
+ push_repo = nil
133
+ end
134
+
135
+ if push_repo.nil? || push_repo.empty?
136
+ fail "Mirror %s not found" % mk
137
+ end
138
+ else
139
+ push_repo = '%s/%s' % [ @options[:registry], @options[:push_repo] ]
140
+ end
141
+
142
+ docker_do 'tag %s %s' % [ @options[:image_name], push_repo ]
143
+ docker_do 'push %s' % push_repo
144
+ else
145
+ puts 'Please specify a push_repo for this docker context'
146
+ end
147
+ end
148
+
149
+ desc 'Pull from registry based on push_repo options'
150
+ task :pull do
151
+ if @options[:push_repo]
152
+ pull_repo = '%s/%s' % [ @options[:registry], @options[:push_repo] ]
153
+
154
+ docker_do 'pull %s' % pull_repo
155
+ docker_do 'tag %s %s' % [ pull_repo, @options[:image_name] ]
156
+ else
157
+ puts 'Please specify a push_repo for this docker context'
158
+ end
159
+ end
160
+
161
+ desc 'Re-tag a local copy from latest remote (will not pull)'
162
+ task :retag do
163
+ if @options[:push_repo]
164
+ pull_repo = '%s/%s' % [ @options[:registry], @options[:push_repo] ]
165
+ docker_do 'tag %s %s' % [ pull_repo, @options[:image_name] ]
166
+ else
167
+ puts 'Please specify a push_repo for this docker context'
168
+ end
169
+ end
170
+
171
+ desc 'Destroy container and delete image'
172
+ task :destroy do
173
+ invoke_task('remove')
174
+ docker_do 'rmi %s' % image_name, :ignore_fail => true
175
+ end
176
+
177
+ desc 'Stop and remove container'
178
+ task 'remove' do
179
+ docker_do 'kill %s' % container_name, :ignore_fail => true
180
+ docker_do 'rm %s' % container_name, :ignore_fail => true
181
+ end
182
+ end
183
+ end
184
+
185
+ def docker_do(cmd, opts = { })
186
+ if opts[:ignore_fail]
187
+ cmd += '; true'
188
+ end
189
+
190
+ sh '%s %s' % [ DOCKER_CMD, cmd ]
191
+ end
192
+
193
+ def invoke_task(tname)
194
+ Rake::Task['%s:%s' % [ ns, tname ]].invoke
195
+ end
196
+
197
+ def help_text
198
+ <<-HELP
199
+ This is a set of Rake tasks that you can include in your own Rakefile, to aid in managing docker images and containers.
200
+ HELP
201
+ end
202
+ end
203
+ end
@@ -0,0 +1,3 @@
1
+ module DockerTask
2
+ VERSION = "0.1.2"
3
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: docker_task
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Mark John Buenconsejo
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-05-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
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.14'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.14'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: gemfury
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: A rake helper of common tasks for use when working with Docker containers.
84
+ email:
85
+ - mark@nlevel.io
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - CODE_OF_CONDUCT.md
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - docker_task.gemspec
100
+ - lib/docker_task.rb
101
+ - lib/docker_task/task.rb
102
+ - lib/docker_task/version.rb
103
+ homepage: https://github.com/nlevel/docker_task
104
+ licenses:
105
+ - MIT
106
+ metadata:
107
+ allowed_push_host: https://rubygems.org
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.6.11
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: A rake helper in working with Docker containers.
128
+ test_files: []