Class: Default
- Inherits:
-
Thor
- Object
- Thor
- Default
- Defined in:
- lib/dockit/cli.rb
Constant Summary collapse
- DOCKIT_FILE =
'./Dockit.yaml'.freeze
- @@root_echoed =
false
Instance Method Summary collapse
- #build(service = nil) ⇒ Object
- #cleanup ⇒ Object
- #config(service = nil) ⇒ Object
- #git_build(service = nil) ⇒ Object
- #help(*args) ⇒ Object
-
#initialize(*args) ⇒ Default
constructor
A new instance of Default.
- #list ⇒ Object
- #pull(registry, service = nil) ⇒ Object
- #push(registry, service = nil) ⇒ Object
- #sh(service = nil, *cmd) ⇒ Object
- #start(service = nil, *cmd) ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(*args) ⇒ Default
Returns a new instance of Default.
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/dockit/cli.rb', line 47 def initialize(*args) super ENV['DOCKER_HOST'] = .host # passed to Excon, default is 60sec, Docker.[:read_timeout] = .timeout unless @@root_echoed say "Project root: #{dockit.root}", :red @@root_echoed=true end end |
Instance Method Details
#build(service = nil) ⇒ Object
171 172 173 174 175 |
# File 'lib/dockit/cli.rb', line 171 def build(service=nil) exec(service) do |s| s.build() end end |
#cleanup ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/dockit/cli.rb', line 131 def cleanup force = [:force] Dockit::Container.clean( force: force, except: ['except-containers']) if [:containers] Dockit::Image.clean( force: force, except: ['except-images']) if [:images] if [:volumes] && Docker.version['ApiVersion'].to_f >= 1.21 Dockit::Volume.clean else say "Volumes not supported on API versions < 1.21", :red end end |
#config(service = nil) ⇒ Object
147 148 149 150 151 |
# File 'lib/dockit/cli.rb', line 147 def config(service=nil) exec(service) do |s| say s.config.instance_variable_get('@config').to_yaml end end |
#git_build(service = nil) ⇒ Object
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/dockit/cli.rb', line 200 def git_build(service=nil) exec(service) do |s| unless repos = s.config.get(:repos) say "'repos' not defined in config file. Exiting", :red exit 1 end path = s.config.get(:repos_path) treeish = unless path.nil? || path.empty? "#{.branch}:#{path}" else .branch end say "Exporting in #{Dir.pwd}", :green say "<- #{repos} #{treeish}", :green if .gem || .package packages = s.config.get(:package) || 'Gemfile*' archive = .gem ? 'gemfile.tar.gz' : 'package.tar.gz' say "-> #{archive}", :green export(repos, treeish, archive, packages) end say "-> repos.tar.gz", :green export(repos, treeish, 'repos.tar.gz') s.build end end |
#help(*args) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/dockit/cli.rb', line 66 def help(*args) super if args.count < 1 say "Run 'dockit list' to see the complete list of SERVICEs." say "Run 'dockit help COMMAND' to see command specific options." end end |
#list ⇒ Object
81 82 83 84 |
# File 'lib/dockit/cli.rb', line 81 def list _list :modules _list :services end |
#pull(registry, service = nil) ⇒ Object
164 165 166 167 168 |
# File 'lib/dockit/cli.rb', line 164 def pull(registry, service=nil) exec(service) do |s| s.pull(registry, [:tag], [:force]) end end |
#push(registry, service = nil) ⇒ Object
155 156 157 158 159 |
# File 'lib/dockit/cli.rb', line 155 def push(registry, service=nil) exec(service) do |s| s.push(registry, [:tag], [:force]) end end |
#sh(service = nil, *cmd) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/dockit/cli.rb', line 98 def sh(service=nil, *cmd) exec(service) do |s| cmd = %w[bash -l] if cmd.length < 1 name = "sh-#{s.name}" # in case image has an entrypoint, use the cmd as the entrypoint (entrypoint, *cmd) = cmd say "Starting #{name} with #{entrypoint} #{cmd}", :green s.start( transient: true, verbose: .verbose, create: { Entrypoint: [entrypoint], Cmd: cmd, name: "sh-#{name}", Tty: true, AttachStdin: true, AttachStdout: true, AttachStderr: true, OpenStdin: true, StdinOnce: true, }) end end |
#start(service = nil, *cmd) ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/dockit/cli.rb', line 89 def start(service=nil, *cmd) opts = .merge(create: {tty: [:transient]}) opts[:create][:Cmd] = cmd if cmd.length > 0 exec(service) do |s| s.start(opts) end end |
#version ⇒ Object
75 76 77 |
# File 'lib/dockit/cli.rb', line 75 def version say "Dockit version #{Dockit::VERSION}" end |