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 puts "Project root: #{dockit.root}" @@root_echoed=true end end |
Instance Method Details
#build(service = nil) ⇒ Object
165 166 167 168 169 |
# File 'lib/dockit/cli.rb', line 165 def build(service=nil) exec(service) do |s| s.build() end end |
#cleanup ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/dockit/cli.rb', line 128 def cleanup force = [:force] Dockit::Container.clean(force: force) if [:containers] Dockit::Image.clean(force: force) 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
141 142 143 144 145 |
# File 'lib/dockit/cli.rb', line 141 def config(service=nil) exec(service) do |s| say s.config.instance_variable_get('@config').to_yaml end end |
#git_build(service = nil) ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/dockit/cli.rb', line 174 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 # grab the Gemfiles separately for the bundler Dockerfile hack say "-> Gemfiles", :green export(repos, treeish, 'gemfile.tar.gz', 'Gemfile*') 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
158 159 160 161 162 |
# File 'lib/dockit/cli.rb', line 158 def pull(registry, service=nil) exec(service) do |s| s.pull(registry, [:tag], [:force]) end end |
#push(registry, service = nil) ⇒ Object
149 150 151 152 153 |
# File 'lib/dockit/cli.rb', line 149 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 |