lux 0.4 → 0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -2
  3. data/lib/lux.rb +42 -19
  4. data/lib/lux/version.rb +1 -1
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2d80091c120733bc4bb30d9d551fecfb1b19e19d
4
- data.tar.gz: 188b53c0ceed1fd37894980fd9f9d4195b8f0647
3
+ metadata.gz: a1eb1c7d352c7326e296feace6572c226beb98ea
4
+ data.tar.gz: 3c42a89dbc463141bbaf9da031d63fe79ef4eed7
5
5
  SHA512:
6
- metadata.gz: 6d1e9a3ce52dcda546b0c1f43c903836239a670eeb8e059f55d32747636c67de3260f659f01d04e6ad7b2570b8aecff06a86d660baabed4a1795649dcca8387b
7
- data.tar.gz: 84e506beedb7a83921a6e0e097f56a519d6496757a88779cdea55686fe31ea9a5c45d3cc8cfcfc9f3f4d8b35d62ec2c3b33b593bd169705efd58a2ce0caf60d7
6
+ metadata.gz: a90943a58a1faca71b089b1f63ef8f593ea9fd419989d1dcba5acb61371f54e3ca15f90030653ac4c31e0a2401ca28a579ac8137bad043ec4ee5cdff1374fb5c
7
+ data.tar.gz: 2bf8bb996fce1c3fbd89569f197560789787be1f109ab2f53a8998eb78cdde766dd98a75a9c7df9d762f674c3046efea95f793607260d6f4b34090486f46e85d
data/README.md CHANGED
@@ -1,12 +1,14 @@
1
1
  # Lux
2
2
 
3
+ [![Gem Version](http://img.shields.io/gem/v/lux.svg)][gem]
4
+
5
+ [gem]: https://rubygems.org/gems/lux
6
+
3
7
  Shining some light on setting up and running various Docker things.
4
8
 
5
9
  Lux is both a command line tool (based on Thor) and a library of useful routines
6
10
  that can be included in Rake tasks.
7
11
 
8
- [![Gem Version](https://img.shields.io/gem/v/lux.svg?style=flat)][gem]
9
-
10
12
  ## Installation
11
13
 
12
14
  Add this line to your application's Gemfile:
data/lib/lux.rb CHANGED
@@ -61,7 +61,7 @@ class Lux::App < Thor
61
61
  image = findimage options.image
62
62
  puts "Starting #{image} container..."
63
63
  me, setup_cmd = user_setup_cmd()
64
- args = ["-v /home/#{me}:/home/#{me}"]
64
+ args = ["-v #{ENV['HOME']}:#{ENV['HOME']}"]
65
65
  args << "--env-file=#{options.env}" if options.env
66
66
  args << "--name=#{options.name}" unless options.name == '<autogenerated>'
67
67
  cid = `docker run -dit #{args.join(' ')} #{image} /bin/bash`.strip
@@ -87,7 +87,7 @@ class Lux::App < Thor
87
87
  env = ENV.reject{|k,v| EXCLUDE_VARS.include? k or v =~/\s+/}.map{|k,v| "#{k}=#{v.shellescape}"}
88
88
  env += IO.readlines(options.env).grep(/^(?!#)/).map(&:rstrip) if options.env
89
89
  cmd = setup_cmd + "su - #{me} -c 'cd #{relwd}; env -i #{env.join(' ')} #{command.join(' ')}'"
90
- args = ["-v /home/#{me}:/home/#{me}"]
90
+ args = ["-v #{ENV['HOME']}:#{ENV['HOME']}"]
91
91
  system "docker run --rm #{args.join(' ')} #{image} /bin/bash -c #{cmd.shellescape}"
92
92
  end
93
93
 
@@ -111,16 +111,40 @@ class Lux::App < Thor
111
111
  end
112
112
  end
113
113
 
114
- desc "rmimages", "Remove named Docker images (with optional pattern)"
115
- method_option :match, type: :string, aliases: '-m', default: '*', desc: 'Matching files'
116
- method_option :pattern, type: :string, aliases: '-p', default: nil, desc: 'Matching pattern (regex)'
117
- method_option :confirm, type: :boolean, aliases: '-c', default: true, desc: 'Confirm removal'
118
- def rmimages
119
- if options.pattern
120
- rx = Regexp.new(options.pattern)
114
+ desc "lsimages [PATTERN]", "List Docker images (with optional pattern)"
115
+ method_option :regex, type: :boolean, aliases: '-r', default: false, desc: 'Pattern is a regular expression'
116
+ def lsimages(pattern=nil)
117
+ if options.regex
118
+ pattern = '.*' unless pattern
119
+ rx = Regexp.new(pattern)
121
120
  matcher = lambda {|s| rx.match(s)}
122
121
  else
123
- matcher = lambda {|s| File.fnmatch?(options.match, s)}
122
+ pattern = '*' unless pattern
123
+ matcher = lambda {|s| File.fnmatch?(pattern, s)}
124
+ end
125
+ imagelines = `docker images`.split("\n")[1..-1].sort
126
+ imagelines.each do |imageline|
127
+ imageinfo = imageline.split(/\s+/)
128
+ next if imageinfo[0] == '<none>'
129
+ imagename = imageinfo[0]+':'+imageinfo[1]
130
+ imagesize = imageinfo[-2]+' '+imageinfo[-1]
131
+ imageage = imageinfo[3..-3].join(' ')
132
+ next unless matcher.call(imagename)
133
+ printf "%-54s%-16s%10s\n", imagename, imageage, imagesize
134
+ end
135
+ end
136
+
137
+ desc "rmimages [PATTERN]", "Remove Docker images (with optional pattern)"
138
+ method_option :regex, type: :boolean, aliases: '-r', default: false, desc: 'Pattern is a regular expression'
139
+ method_option :force, type: :boolean, aliases: '-f', default: false, desc: 'Do not prompt for confirmation'
140
+ def rmimages(pattern=nil)
141
+ if options.regex
142
+ pattern = '.*' unless pattern
143
+ rx = Regexp.new(pattern)
144
+ matcher = lambda {|s| rx.match(s)}
145
+ else
146
+ pattern = '*' unless pattern
147
+ matcher = lambda {|s| File.fnmatch?(pattern, s)}
124
148
  end
125
149
  imagelines = `docker images`.split("\n")[1..-1]
126
150
  imagelines.each do |imageline|
@@ -130,7 +154,7 @@ class Lux::App < Thor
130
154
  imagesize = imageinfo[-2]+' '+imageinfo[-1]
131
155
  imageage = imageinfo[3..-3].join(' ')
132
156
  next unless matcher.call(imagename)
133
- if !options.confirm or (agree("Delete #{imagename} (#{imageage}, #{imagesize})? "){|q|q.echo=true})
157
+ if options.force or (agree("Delete #{imagename} (#{imageage}, #{imagesize})? "){|q|q.echo=true})
134
158
  `docker rmi #{imageinfo[2]}`
135
159
  HighLine.say "Image <%= color('#{imagename}', RED)%> deleted"
136
160
  end
@@ -169,21 +193,20 @@ class Lux::App < Thor
169
193
  #
170
194
  def findimage image
171
195
  if image.count('/') == 0
172
- local_images = `docker images`.strip.split(/\n/)[1..-1].map{|l| l.gsub!(/^(\S+)\s+(\S+).*/,'\1:\2')}.sort
173
- matching_images = local_images.select{|l| l =~ %r[/#{image}] }
196
+ local_images = `docker images`.strip.split("\n")[1..-1].map{|l| l.gsub!(/^(\S+)\s+(\S+).*/,'\1:\2')}.sort
197
+ matching_images = local_images.select{|l| l.include? image }
174
198
  if matching_images.size > 0
175
199
  if image.count(':') == 0
176
- matching_image = matching_images.select{|l| l =~ /:latest$/ }.first
200
+ matching_image = matching_images.select{|l| l.end_with? ':latest' }.first
177
201
  end
178
202
  unless matching_image
179
203
  matching_image = matching_images.first
180
204
  end
181
205
  else
182
- matching_image = nil
206
+ die "No image found matching: #{image}"
183
207
  end
184
- image = matching_image ? matching_image : "lightside/"+image
185
208
  end
186
- return image
209
+ return matching_image
187
210
  end
188
211
 
189
212
  # Return two elements:
@@ -192,8 +215,8 @@ class Lux::App < Thor
192
215
  #
193
216
  def user_setup_cmd user = `id -nu`.strip
194
217
  [user, <<-COMMAND.gsub(/^\s*/,'').gsub(/\n/,' ; ')]
195
- uid=$(echo $(stat -c %u:%g /home/#{user}) | cut -d: -f2)
196
- useradd -M -u $uid -s #{ENV['SHELL']} #{user}
218
+ uid=$(echo $(stat -c %u:%g #{ENV['HOME']}) | cut -d: -f2)
219
+ useradd -M -d #{ENV['HOME']} -u $uid -s #{ENV['SHELL']} #{user}
197
220
  echo "#{user} ALL=(ALL:ALL) NOPASSWD: ALL" > /etc/sudoers.d/#{user}
198
221
  COMMAND
199
222
  end
@@ -1,3 +1,3 @@
1
1
  module Lux
2
- VERSION = "0.4"
2
+ VERSION = "0.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lux
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.4'
4
+ version: '0.5'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Townsend
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-15 00:00:00.000000000 Z
11
+ date: 2015-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor