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.
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/dockit/cli.rb', line 50 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
179 180 181 182 183 |
# File 'lib/dockit/cli.rb', line 179 def build(service=nil) exec(service) do |s| s.build() end end |
#cleanup ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/dockit/cli.rb', line 137 def cleanup Dockit::Container.clean( force: ['force-containers'], except: ['except-containers'] ) if [:containers] Dockit::Image.clean( force: ['force-images'], 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
154 155 156 157 158 |
# File 'lib/dockit/cli.rb', line 154 def config(service=nil) exec(service) do |s| say s.config.instance_variable_get('@config').to_yaml end end |
#git_build(service = nil) ⇒ Object
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/dockit/cli.rb', line 207 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 .package unless packages = s.config.get(:package) say "'packages' not defined in config file. Exiting…", :red exit 1 end say '-> package.tar.gz', :green export(repos, treeish, 'package.tar.gz', packages) end say '-> repos.tar.gz', :green export(repos, treeish, 'repos.tar.gz') say "Creating '.branch' tag file (#{.branch})", :blue File.write('.branch', "#{.branch}\n") s.build end end |
#help(*args) ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/dockit/cli.rb', line 69 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
84 85 86 87 |
# File 'lib/dockit/cli.rb', line 84 def list _list :modules _list :services end |
#pull(registry, service = nil) ⇒ Object
172 173 174 175 176 |
# File 'lib/dockit/cli.rb', line 172 def pull(registry, service=nil) exec(service) do |s| s.pull(registry, [:tag], [:force]) end end |
#push(registry, service = nil) ⇒ Object
163 164 165 166 167 |
# File 'lib/dockit/cli.rb', line 163 def push(registry, service=nil) exec(service) do |s| s.push(registry, [:tag], [:force]) end end |
#sh(service = nil, *cmd) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/dockit/cli.rb', line 101 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
92 93 94 95 96 97 98 |
# File 'lib/dockit/cli.rb', line 92 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
78 79 80 |
# File 'lib/dockit/cli.rb', line 78 def version say "Dockit version #{Dockit::VERSION}" end |