├── README.md ├── example-01-gnu-date └── gnu-date └── example-02-ruby-cli-app ├── Dockerfile ├── Makefile ├── ruby-cli-app-wrapper └── ruby-cli-app ├── .gitignore ├── .ruby-version ├── Gemfile ├── Gemfile.lock ├── README.rdoc ├── Rakefile ├── bin └── ruby-cli-app ├── features ├── ruby-cli-app.feature ├── step_definitions │ └── ruby-cli-app_steps.rb └── support │ └── env.rb ├── lib ├── ruby-cli-app.rb └── ruby-cli-app │ └── version.rb ├── ruby-cli-app.gemspec ├── ruby-cli-app.rdoc ├── test ├── default_test.rb └── test_helper.rb └── vendor └── cache ├── aruba-0.10.0.gem ├── builder-3.2.2.gem ├── childprocess-0.5.7.gem ├── contracts-0.12.0.gem ├── cucumber-2.1.0.gem ├── cucumber-core-1.3.0.gem ├── diff-lcs-1.2.5.gem ├── ffi-1.9.10.gem ├── gherkin3-3.1.2.gem ├── gli-2.13.2.gem ├── multi_json-1.11.2.gem ├── multi_test-0.1.2.gem ├── rake-10.4.2.gem ├── rdoc-4.2.0.gem ├── rspec-expectations-3.3.1.gem ├── rspec-support-3.3.0.gem └── thor-0.19.1.gem /README.md: -------------------------------------------------------------------------------- 1 | # Distributing Command Line Tools with Docker 2 | 3 | Example code to accompany the [blog post][] by Mike English ([@englishm][]). 4 | 5 | [blog post]: https://spin.atomicobject.com/2015/11/30/command-line-tools-docker/ 6 | [@englishm]: https://github.com/englishm 7 | -------------------------------------------------------------------------------- /example-01-gnu-date/gnu-date: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # gnu-date - a wrapper script for invoking `date(1)` from within a Docker image 3 | docker run --rm -ti ubuntu:12.04 date "$@" 4 | 5 | -------------------------------------------------------------------------------- /example-02-ruby-cli-app/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ruby:2.2 2 | 3 | COPY ./ruby-cli-app /app 4 | RUN cd /app \ 5 | && bundle install 6 | 7 | ENTRYPOINT ["ruby-cli-app"] 8 | -------------------------------------------------------------------------------- /example-02-ruby-cli-app/Makefile: -------------------------------------------------------------------------------- 1 | PREFIX ?= /usr/local 2 | VERSION = "v0.0.1" 3 | 4 | all: install 5 | 6 | install: 7 | mkdir -p $(DESTDIR)$(PREFIX)/bin 8 | install -m 0755 ruby-cli-app-wrapper $(DESTDIR)$(PREFIX)/bin/ruby-cli-app 9 | 10 | uninstall: 11 | @$(RM) $(DESTDIR)$(PREFIX)/bin/ruby-cli-app 12 | @docker rmi atomicobject/ruby-cli-app:$(VERSION) 13 | @docker rmi atomicobject/ruby-cli-app:latest 14 | 15 | build: 16 | @docker build -t atomicobject/ruby-cli-app:$(VERSION) . \ 17 | && docker tag -f atomicobject/ruby-cli-app:$(VERSION) atomicobject/ruby-cli-app:latest 18 | 19 | publish: build 20 | @docker push atomicobject/ruby-cli-app:$(VERSION) \ 21 | && docker push atomicobject/ruby-cli-app:latest 22 | 23 | .PHONY: all install uninstall build publish 24 | -------------------------------------------------------------------------------- /example-02-ruby-cli-app/ruby-cli-app-wrapper: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # ruby-cli-app 4 | # A wrapper script for invoking ruby-cli-app with docker 5 | # Put this script in $PATH as `ruby-cli-app` 6 | 7 | PROGNAME="$(basename $0)" 8 | VERSION="v0.0.1" 9 | 10 | # Helper functions for guards 11 | error(){ 12 | error_code=$1 13 | echo "ERROR: $2" >&2 14 | echo "($PROGNAME wrapper version: $VERSION, error code: $error_code )" >&2 15 | exit $1 16 | } 17 | check_cmd_in_path(){ 18 | cmd=$1 19 | which $cmd > /dev/null 2>&1 || error 1 "$cmd not found!" 20 | } 21 | 22 | # Guards (checks for dependencies) 23 | check_cmd_in_path docker 24 | check_cmd_in_path docker-machine 25 | docker-machine active > /dev/null 2>&1 || error 2 "No active docker-machine VM found." 26 | 27 | # Set up mounted volumes, environment, and run our containerized command 28 | docker run \ 29 | --interactive --tty --rm \ 30 | --volume "$PWD":/wd \ 31 | --workdir /wd \ 32 | "atomicobject/ruby-cli-app:$VERSION" "$@" 33 | -------------------------------------------------------------------------------- /example-02-ruby-cli-app/ruby-cli-app/.gitignore: -------------------------------------------------------------------------------- 1 | .bundle/ 2 | vendor/bundle/ 3 | -------------------------------------------------------------------------------- /example-02-ruby-cli-app/ruby-cli-app/.ruby-version: -------------------------------------------------------------------------------- 1 | 2.2.3 2 | -------------------------------------------------------------------------------- /example-02-ruby-cli-app/ruby-cli-app/Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | gemspec 3 | -------------------------------------------------------------------------------- /example-02-ruby-cli-app/ruby-cli-app/Gemfile.lock: -------------------------------------------------------------------------------- 1 | PATH 2 | remote: . 3 | specs: 4 | ruby-cli-app (0.0.1) 5 | gli (= 2.13.2) 6 | 7 | GEM 8 | remote: https://rubygems.org/ 9 | specs: 10 | aruba (0.10.0) 11 | childprocess (~> 0.5.6) 12 | contracts (~> 0.9) 13 | cucumber (>= 1.3.19) 14 | ffi (~> 1.9.10) 15 | rspec-expectations (>= 2.99) 16 | thor (~> 0.19) 17 | builder (3.2.2) 18 | childprocess (0.5.7) 19 | ffi (~> 1.0, >= 1.0.11) 20 | contracts (0.12.0) 21 | cucumber (2.1.0) 22 | builder (>= 2.1.2) 23 | cucumber-core (~> 1.3.0) 24 | diff-lcs (>= 1.1.3) 25 | gherkin3 (~> 3.1.0) 26 | multi_json (>= 1.7.5, < 2.0) 27 | multi_test (>= 0.1.2) 28 | cucumber-core (1.3.0) 29 | gherkin3 (~> 3.1.0) 30 | diff-lcs (1.2.5) 31 | ffi (1.9.10) 32 | gherkin3 (3.1.2) 33 | gli (2.13.2) 34 | multi_json (1.11.2) 35 | multi_test (0.1.2) 36 | rake (10.4.2) 37 | rdoc (4.2.0) 38 | rspec-expectations (3.3.1) 39 | diff-lcs (>= 1.2.0, < 2.0) 40 | rspec-support (~> 3.3.0) 41 | rspec-support (3.3.0) 42 | thor (0.19.1) 43 | 44 | PLATFORMS 45 | ruby 46 | 47 | DEPENDENCIES 48 | aruba 49 | rake 50 | rdoc 51 | ruby-cli-app! 52 | 53 | BUNDLED WITH 54 | 1.10.6 55 | -------------------------------------------------------------------------------- /example-02-ruby-cli-app/ruby-cli-app/README.rdoc: -------------------------------------------------------------------------------- 1 | = ruby-cli-app 2 | 3 | Describe your project here 4 | 5 | :include:ruby-cli-app.rdoc 6 | 7 | -------------------------------------------------------------------------------- /example-02-ruby-cli-app/ruby-cli-app/Rakefile: -------------------------------------------------------------------------------- 1 | require 'rake/clean' 2 | require 'rubygems' 3 | require 'rubygems/package_task' 4 | require 'rdoc/task' 5 | require 'cucumber' 6 | require 'cucumber/rake/task' 7 | Rake::RDocTask.new do |rd| 8 | rd.main = "README.rdoc" 9 | rd.rdoc_files.include("README.rdoc","lib/**/*.rb","bin/**/*") 10 | rd.title = 'Your application title' 11 | end 12 | 13 | spec = eval(File.read('ruby-cli-app.gemspec')) 14 | 15 | Gem::PackageTask.new(spec) do |pkg| 16 | end 17 | CUKE_RESULTS = 'results.html' 18 | CLEAN << CUKE_RESULTS 19 | desc 'Run features' 20 | Cucumber::Rake::Task.new(:features) do |t| 21 | opts = "features --format html -o #{CUKE_RESULTS} --format progress -x" 22 | opts += " --tags #{ENV['TAGS']}" if ENV['TAGS'] 23 | t.cucumber_opts = opts 24 | t.fork = false 25 | end 26 | 27 | desc 'Run features tagged as work-in-progress (@wip)' 28 | Cucumber::Rake::Task.new('features:wip') do |t| 29 | tag_opts = ' --tags ~@pending' 30 | tag_opts = ' --tags @wip' 31 | t.cucumber_opts = "features --format html -o #{CUKE_RESULTS} --format pretty -x -s#{tag_opts}" 32 | t.fork = false 33 | end 34 | 35 | task :cucumber => :features 36 | task 'cucumber:wip' => 'features:wip' 37 | task :wip => 'features:wip' 38 | require 'rake/testtask' 39 | Rake::TestTask.new do |t| 40 | t.libs << "test" 41 | t.test_files = FileList['test/*_test.rb'] 42 | end 43 | 44 | task :default => [:test,:features] 45 | -------------------------------------------------------------------------------- /example-02-ruby-cli-app/ruby-cli-app/bin/ruby-cli-app: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'gli' 3 | begin # XXX: Remove this begin/rescue before distributing your app 4 | require 'ruby-cli-app' 5 | rescue LoadError 6 | STDERR.puts "In development, you need to use `bundle exec bin/ruby-cli-app` to run your app" 7 | STDERR.puts "At install-time, RubyGems will make sure lib, etc. are in the load path" 8 | STDERR.puts "Feel free to remove this message from bin/ruby-cli-app now" 9 | exit 64 10 | end 11 | 12 | include GLI::App 13 | 14 | program_desc 'Describe your application here' 15 | 16 | version RubyCliApp::VERSION 17 | 18 | subcommand_option_handling :normal 19 | arguments :strict 20 | 21 | desc 'Describe some switch here' 22 | switch [:s,:switch] 23 | 24 | desc 'Describe some flag here' 25 | default_value 'the default' 26 | arg_name 'The name of the argument' 27 | flag [:f,:flagname] 28 | 29 | pre do |global,command,options,args| 30 | # Pre logic here 31 | # Return true to proceed; false to abort and not call the 32 | # chosen command 33 | # Use skips_pre before a command to skip this block 34 | # on that command only 35 | true 36 | end 37 | 38 | post do |global,command,options,args| 39 | # Post logic here 40 | # Use skips_post before a command to skip this 41 | # block on that command only 42 | end 43 | 44 | on_error do |exception| 45 | # Error logic here 46 | # return false to skip default error handling 47 | true 48 | end 49 | 50 | exit run(ARGV) 51 | -------------------------------------------------------------------------------- /example-02-ruby-cli-app/ruby-cli-app/features/ruby-cli-app.feature: -------------------------------------------------------------------------------- 1 | Feature: My bootstrapped app kinda works 2 | In order to get going on coding my awesome app 3 | I want to have aruba and cucumber setup 4 | So I don't have to do it myself 5 | 6 | Scenario: App just runs 7 | When I get help for "ruby-cli-app" 8 | Then the exit status should be 0 9 | -------------------------------------------------------------------------------- /example-02-ruby-cli-app/ruby-cli-app/features/step_definitions/ruby-cli-app_steps.rb: -------------------------------------------------------------------------------- 1 | When /^I get help for "([^"]*)"$/ do |app_name| 2 | @app_name = app_name 3 | step %(I run `#{app_name} help`) 4 | end 5 | 6 | # Add more step definitions here 7 | -------------------------------------------------------------------------------- /example-02-ruby-cli-app/ruby-cli-app/features/support/env.rb: -------------------------------------------------------------------------------- 1 | require 'aruba/cucumber' 2 | 3 | ENV['PATH'] = "#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}" 4 | LIB_DIR = File.join(File.expand_path(File.dirname(__FILE__)),'..','..','lib') 5 | 6 | Before do 7 | # Using "announce" causes massive warnings on 1.9.2 8 | @puts = true 9 | @original_rubylib = ENV['RUBYLIB'] 10 | ENV['RUBYLIB'] = LIB_DIR + File::PATH_SEPARATOR + ENV['RUBYLIB'].to_s 11 | end 12 | 13 | After do 14 | ENV['RUBYLIB'] = @original_rubylib 15 | end 16 | -------------------------------------------------------------------------------- /example-02-ruby-cli-app/ruby-cli-app/lib/ruby-cli-app.rb: -------------------------------------------------------------------------------- 1 | require 'ruby-cli-app/version.rb' 2 | 3 | # Add requires for other files you add to your project here, so 4 | # you just need to require this one file in your bin file 5 | -------------------------------------------------------------------------------- /example-02-ruby-cli-app/ruby-cli-app/lib/ruby-cli-app/version.rb: -------------------------------------------------------------------------------- 1 | module RubyCliApp 2 | VERSION = '0.0.1' 3 | end 4 | -------------------------------------------------------------------------------- /example-02-ruby-cli-app/ruby-cli-app/ruby-cli-app.gemspec: -------------------------------------------------------------------------------- 1 | # Ensure we require the local version and not one we might have installed already 2 | require File.join([File.dirname(__FILE__),'lib','ruby-cli-app','version.rb']) 3 | spec = Gem::Specification.new do |s| 4 | s.name = 'ruby-cli-app' 5 | s.version = RubyCliApp::VERSION 6 | s.author = 'Your Name Here' 7 | s.email = 'your@email.address.com' 8 | s.homepage = 'http://your.website.com' 9 | s.platform = Gem::Platform::RUBY 10 | s.summary = 'A description of your project' 11 | s.files = %[ 12 | .gitignore 13 | .ruby-version 14 | Gemfile 15 | Gemfile.lock 16 | README.rdoc 17 | Rakefile 18 | bin/ruby-cli-app 19 | features/ruby-cli-app.feature 20 | features/step_definitions/ruby-cli-app_steps.rb 21 | features/support/env.rb 22 | lib/ruby-cli-app.rb 23 | lib/ruby-cli-app/version.rb 24 | ruby-cli-app.gemspec 25 | ruby-cli-app.rdoc 26 | test/default_test.rb 27 | test/test_helper.rb 28 | ] 29 | s.require_paths << 'lib' 30 | s.has_rdoc = true 31 | s.extra_rdoc_files = ['README.rdoc','ruby-cli-app.rdoc'] 32 | s.rdoc_options << '--title' << 'ruby-cli-app' << '--main' << 'README.rdoc' << '-ri' 33 | s.bindir = 'bin' 34 | s.executables << 'ruby-cli-app' 35 | s.add_development_dependency('rake') 36 | s.add_development_dependency('rdoc') 37 | s.add_development_dependency('aruba') 38 | s.add_runtime_dependency('gli','2.13.2') 39 | end 40 | -------------------------------------------------------------------------------- /example-02-ruby-cli-app/ruby-cli-app/ruby-cli-app.rdoc: -------------------------------------------------------------------------------- 1 | = ruby-cli-app 2 | 3 | Generate this with 4 | ruby-cli-app rdoc 5 | After you have described your command line interface -------------------------------------------------------------------------------- /example-02-ruby-cli-app/ruby-cli-app/test/default_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | 3 | class DefaultTest < Test::Unit::TestCase 4 | 5 | def setup 6 | end 7 | 8 | def teardown 9 | end 10 | 11 | def test_the_truth 12 | assert true 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /example-02-ruby-cli-app/ruby-cli-app/test/test_helper.rb: -------------------------------------------------------------------------------- 1 | require 'test/unit' 2 | 3 | # Add test libraries you want to use here, e.g. mocha 4 | 5 | class Test::Unit::TestCase 6 | 7 | # Add global extensions to the test case class here 8 | 9 | end 10 | -------------------------------------------------------------------------------- /example-02-ruby-cli-app/ruby-cli-app/vendor/cache/aruba-0.10.0.gem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/atomicobject/docker-cli-distribution/374e14b3c39db383c117984f3ba5c39576153f24/example-02-ruby-cli-app/ruby-cli-app/vendor/cache/aruba-0.10.0.gem -------------------------------------------------------------------------------- /example-02-ruby-cli-app/ruby-cli-app/vendor/cache/builder-3.2.2.gem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/atomicobject/docker-cli-distribution/374e14b3c39db383c117984f3ba5c39576153f24/example-02-ruby-cli-app/ruby-cli-app/vendor/cache/builder-3.2.2.gem -------------------------------------------------------------------------------- /example-02-ruby-cli-app/ruby-cli-app/vendor/cache/childprocess-0.5.7.gem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/atomicobject/docker-cli-distribution/374e14b3c39db383c117984f3ba5c39576153f24/example-02-ruby-cli-app/ruby-cli-app/vendor/cache/childprocess-0.5.7.gem -------------------------------------------------------------------------------- /example-02-ruby-cli-app/ruby-cli-app/vendor/cache/contracts-0.12.0.gem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/atomicobject/docker-cli-distribution/374e14b3c39db383c117984f3ba5c39576153f24/example-02-ruby-cli-app/ruby-cli-app/vendor/cache/contracts-0.12.0.gem -------------------------------------------------------------------------------- /example-02-ruby-cli-app/ruby-cli-app/vendor/cache/cucumber-2.1.0.gem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/atomicobject/docker-cli-distribution/374e14b3c39db383c117984f3ba5c39576153f24/example-02-ruby-cli-app/ruby-cli-app/vendor/cache/cucumber-2.1.0.gem -------------------------------------------------------------------------------- /example-02-ruby-cli-app/ruby-cli-app/vendor/cache/cucumber-core-1.3.0.gem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/atomicobject/docker-cli-distribution/374e14b3c39db383c117984f3ba5c39576153f24/example-02-ruby-cli-app/ruby-cli-app/vendor/cache/cucumber-core-1.3.0.gem -------------------------------------------------------------------------------- /example-02-ruby-cli-app/ruby-cli-app/vendor/cache/diff-lcs-1.2.5.gem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/atomicobject/docker-cli-distribution/374e14b3c39db383c117984f3ba5c39576153f24/example-02-ruby-cli-app/ruby-cli-app/vendor/cache/diff-lcs-1.2.5.gem -------------------------------------------------------------------------------- /example-02-ruby-cli-app/ruby-cli-app/vendor/cache/ffi-1.9.10.gem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/atomicobject/docker-cli-distribution/374e14b3c39db383c117984f3ba5c39576153f24/example-02-ruby-cli-app/ruby-cli-app/vendor/cache/ffi-1.9.10.gem -------------------------------------------------------------------------------- /example-02-ruby-cli-app/ruby-cli-app/vendor/cache/gherkin3-3.1.2.gem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/atomicobject/docker-cli-distribution/374e14b3c39db383c117984f3ba5c39576153f24/example-02-ruby-cli-app/ruby-cli-app/vendor/cache/gherkin3-3.1.2.gem -------------------------------------------------------------------------------- /example-02-ruby-cli-app/ruby-cli-app/vendor/cache/gli-2.13.2.gem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/atomicobject/docker-cli-distribution/374e14b3c39db383c117984f3ba5c39576153f24/example-02-ruby-cli-app/ruby-cli-app/vendor/cache/gli-2.13.2.gem -------------------------------------------------------------------------------- /example-02-ruby-cli-app/ruby-cli-app/vendor/cache/multi_json-1.11.2.gem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/atomicobject/docker-cli-distribution/374e14b3c39db383c117984f3ba5c39576153f24/example-02-ruby-cli-app/ruby-cli-app/vendor/cache/multi_json-1.11.2.gem -------------------------------------------------------------------------------- /example-02-ruby-cli-app/ruby-cli-app/vendor/cache/multi_test-0.1.2.gem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/atomicobject/docker-cli-distribution/374e14b3c39db383c117984f3ba5c39576153f24/example-02-ruby-cli-app/ruby-cli-app/vendor/cache/multi_test-0.1.2.gem -------------------------------------------------------------------------------- /example-02-ruby-cli-app/ruby-cli-app/vendor/cache/rake-10.4.2.gem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/atomicobject/docker-cli-distribution/374e14b3c39db383c117984f3ba5c39576153f24/example-02-ruby-cli-app/ruby-cli-app/vendor/cache/rake-10.4.2.gem -------------------------------------------------------------------------------- /example-02-ruby-cli-app/ruby-cli-app/vendor/cache/rdoc-4.2.0.gem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/atomicobject/docker-cli-distribution/374e14b3c39db383c117984f3ba5c39576153f24/example-02-ruby-cli-app/ruby-cli-app/vendor/cache/rdoc-4.2.0.gem -------------------------------------------------------------------------------- /example-02-ruby-cli-app/ruby-cli-app/vendor/cache/rspec-expectations-3.3.1.gem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/atomicobject/docker-cli-distribution/374e14b3c39db383c117984f3ba5c39576153f24/example-02-ruby-cli-app/ruby-cli-app/vendor/cache/rspec-expectations-3.3.1.gem -------------------------------------------------------------------------------- /example-02-ruby-cli-app/ruby-cli-app/vendor/cache/rspec-support-3.3.0.gem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/atomicobject/docker-cli-distribution/374e14b3c39db383c117984f3ba5c39576153f24/example-02-ruby-cli-app/ruby-cli-app/vendor/cache/rspec-support-3.3.0.gem -------------------------------------------------------------------------------- /example-02-ruby-cli-app/ruby-cli-app/vendor/cache/thor-0.19.1.gem: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/atomicobject/docker-cli-distribution/374e14b3c39db383c117984f3ba5c39576153f24/example-02-ruby-cli-app/ruby-cli-app/vendor/cache/thor-0.19.1.gem --------------------------------------------------------------------------------