lux 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +8 -0
- data/lib/lux.rb +32 -13
- data/lib/lux/app.rb +8 -3
- data/lib/lux/docker_tasks.rb +31 -9
- data/lib/lux/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8be0be4990f3bbdb5b2d7117a756996543f38262
|
4
|
+
data.tar.gz: 90e03ff7bcdd4cb679d728258d5cf27b8ec8d907
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b855936cae4a5b38ef7e94e9bbba9e9d99e2175c825132efca363a1c18627b063e7f6a9665a3f5a0515ea9158e0c4bdafd9bf8cf44fba2b4d01d5e7025646e2
|
7
|
+
data.tar.gz: ae712eb0ab6690e7edb49ced1c7592f119aedba172c4863aaa0f86f6a42a639e4a5bbfc58fd579bbd5db8a69ace4198f57ac5237646666983b8f58b4dbeae328
|
data/CHANGELOG
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
lux (1.0.6)
|
2
|
+
|
3
|
+
* Improve address check for Docker server
|
4
|
+
* Disable Docker tasks if tcp based server cannot be found
|
5
|
+
* Return Docker version number on 'dockerip' command
|
6
|
+
|
7
|
+
-- Nick Townsend <nick.townsend@mac.com> Fri, 21 Aug 2015 17:12:20 -0700
|
8
|
+
|
1
9
|
lux (1.0.5)
|
2
10
|
|
3
11
|
* Send only 'export' command to STDOUT in lux dockerip.
|
data/lib/lux.rb
CHANGED
@@ -1,32 +1,43 @@
|
|
1
1
|
require 'highline/import'
|
2
2
|
require 'uri'
|
3
3
|
require 'socket'
|
4
|
+
require 'json'
|
4
5
|
|
5
6
|
module Lux
|
6
7
|
|
8
|
+
module_function
|
9
|
+
|
7
10
|
# Determine the IPv4 address of the current Docker host
|
8
11
|
# Used to avoid long reverse DNS lookups on .local names
|
9
|
-
# Returns
|
10
|
-
# - the IPv4 address as a string
|
11
|
-
#
|
12
|
+
# Returns an array of four items:
|
13
|
+
# - the IPv4 address as a string or nil if it couldn't be found
|
14
|
+
# or wasn't an IP URL
|
12
15
|
# - a string saying which variable was used, 'URL' or 'HOST'
|
16
|
+
# - a URI object
|
17
|
+
# - a hash containing the Docker version information
|
13
18
|
# Note that DOCKER_URL is used by the docker-api client, but
|
14
19
|
# as Docker uses the misleading DOCKER_HOST we fallback to that.
|
15
20
|
#
|
16
|
-
def
|
21
|
+
def dockerip
|
17
22
|
vars = ['DOCKER_URL', 'DOCKER_HOST']
|
18
23
|
var, url = vars.map{|v| [v, ENV[v]]}.find{|d| d[1]}
|
19
|
-
return nil unless var
|
24
|
+
return nil, nil, nil, nil unless var
|
20
25
|
uri = URI.parse(url)
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
26
|
+
return nil, var, url, nil unless uri.scheme == 'tcp'
|
27
|
+
addr = nil
|
28
|
+
info = nil
|
29
|
+
Addrinfo.tcp(uri.host, uri.port).connect(timeout: 5) {|s|
|
30
|
+
addr = s.remote_address.ip_address
|
31
|
+
s.print "GET /version HTTP/1.0\r\nHost: localhost\r\n\r\n"
|
32
|
+
response, emptyline, body = s.read.partition(/(\r\n){2}/)
|
33
|
+
info = JSON.parse(body, symbolize_names: true)
|
34
|
+
} rescue nil
|
35
|
+
return addr, var, uri, info
|
25
36
|
end
|
26
37
|
|
27
38
|
# Get the current list of images and make a guess at which one it is...
|
28
39
|
#
|
29
|
-
def
|
40
|
+
def findimage image
|
30
41
|
local_images = `docker images`.strip.split("\n")[1..-1].map{|l| l.gsub!(/^(\S+)\s+(\S+).*/,'\1:\2')}.sort
|
31
42
|
matching_images = local_images.select{|l| l.include? image }
|
32
43
|
if matching_images.size > 0
|
@@ -51,7 +62,7 @@ module Lux
|
|
51
62
|
# - user name (defaults to current user), and
|
52
63
|
# - a bash script setup command
|
53
64
|
#
|
54
|
-
def
|
65
|
+
def user_setup_cmd user = `id -nu`.strip
|
55
66
|
[user, <<-COMMAND.gsub(/^\s*/,'').gsub(/\n/,' ; ')]
|
56
67
|
uid=$(echo $(stat -c %u:%g #{ENV['HOME']}) | cut -d: -f2)
|
57
68
|
useradd -M -d #{ENV['HOME']} -u $uid -s #{ENV['SHELL']} #{user}
|
@@ -59,9 +70,17 @@ module Lux
|
|
59
70
|
COMMAND
|
60
71
|
end
|
61
72
|
|
62
|
-
def
|
73
|
+
def die msg, rc = 1
|
74
|
+
error msg
|
75
|
+
exit rc
|
76
|
+
end
|
77
|
+
|
78
|
+
def error msg
|
63
79
|
HighLine.new(STDIN, STDERR).say HighLine.color(msg, HighLine::RED)
|
64
|
-
|
80
|
+
end
|
81
|
+
|
82
|
+
def info msg
|
83
|
+
HighLine.new(STDIN, STDERR).say HighLine.color(msg, HighLine::YELLOW)
|
65
84
|
end
|
66
85
|
|
67
86
|
end
|
data/lib/lux/app.rb
CHANGED
@@ -175,13 +175,18 @@ class Lux::App < Thor
|
|
175
175
|
|
176
176
|
desc "dockerip", "Show DOCKER_HOST IP address in exportable format. Use $(lux dockerip) to set it"
|
177
177
|
def dockerip
|
178
|
-
name, var, uri = Lux.dockerip
|
179
|
-
Lux.die "
|
180
|
-
STDERR.puts "Found #{var}=#{uri.to_s}"
|
178
|
+
name, var, uri, info = Lux.dockerip
|
179
|
+
Lux.die "Not found: #{var}=#{uri.to_s}" unless name
|
181
180
|
if uri.host != name
|
182
181
|
uri.host = name
|
182
|
+
msg = "Set"
|
183
183
|
puts "export #{var}=#{uri.to_s}"
|
184
|
+
else
|
185
|
+
msg = "Found"
|
184
186
|
end
|
187
|
+
msg << ": #{var}=#{uri.to_s}"
|
188
|
+
msg << " (version #{info[:Version]})" if info
|
189
|
+
Lux.info msg
|
185
190
|
end
|
186
191
|
|
187
192
|
end
|
data/lib/lux/docker_tasks.rb
CHANGED
@@ -5,11 +5,6 @@ require 'lux'
|
|
5
5
|
require 'rake'
|
6
6
|
require 'socket'
|
7
7
|
|
8
|
-
# Set this to avoid 5 sec timeouts with .local addresses
|
9
|
-
# which don't resolve in IPv6
|
10
|
-
#
|
11
|
-
Docker.options = { family: Socket::Constants::AF_INET }
|
12
|
-
|
13
8
|
module Rake
|
14
9
|
module DSL
|
15
10
|
def dockerimage(*args, &block)
|
@@ -22,6 +17,26 @@ module Rake
|
|
22
17
|
end
|
23
18
|
|
24
19
|
module Lux
|
20
|
+
|
21
|
+
addr, var, uri = Lux.dockerip
|
22
|
+
|
23
|
+
DISABLED = case
|
24
|
+
when !addr && var && uri.scheme == 'tcp'
|
25
|
+
error "Invalid Docker server, disabling Docker tasks!"
|
26
|
+
true
|
27
|
+
else
|
28
|
+
begin
|
29
|
+
# Set this to avoid 5 sec timeouts with .local addresses
|
30
|
+
# which don't resolve in IPv6
|
31
|
+
Docker.options = { family: Socket::Constants::AF_INET, connect_timeout: 5 }
|
32
|
+
Docker.validate_version!
|
33
|
+
false
|
34
|
+
rescue Exception => e
|
35
|
+
error "Docker problem (#{e.message}), tasks will be disabled"
|
36
|
+
true
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
25
40
|
class DockerImageTask < Rake::FileTask
|
26
41
|
# This task checks to see if the image is present in the local Docker Server
|
27
42
|
# If present it returns the creation date as the timestamp, if not then it
|
@@ -32,14 +47,17 @@ module Lux
|
|
32
47
|
super(task_name, app)
|
33
48
|
@imagename = @name
|
34
49
|
@imagename += ':latest' unless @imagename.index(':')
|
35
|
-
@image =
|
50
|
+
@image = DISABLED ? nil :
|
51
|
+
Docker::Image.all.select{|i| i.info['RepoTags'].include? @imagename}.first
|
36
52
|
end
|
37
53
|
|
38
54
|
def needed?
|
55
|
+
return false if DISABLED
|
39
56
|
! @image || out_of_date?(timestamp) || @application.options.build_all
|
40
57
|
end
|
41
58
|
|
42
59
|
def timestamp
|
60
|
+
return Time.now if DISABLED
|
43
61
|
if @image = Docker::Image.all.select{|i| i.info['RepoTags'].include? @imagename}.first
|
44
62
|
Time.at(@image.info['Created'])
|
45
63
|
else
|
@@ -61,12 +79,15 @@ module Lux
|
|
61
79
|
super(task_name, app)
|
62
80
|
@containername, sep, @imagename = task_name.partition('@')
|
63
81
|
raise "Task #{task_name} must be name@image" if @containername.empty? or @imagename.empty?
|
64
|
-
|
65
|
-
|
66
|
-
|
82
|
+
unless DISABLED
|
83
|
+
@container = Docker::Container.get(@containername) rescue nil
|
84
|
+
@imagename += ':latest' unless @imagename.index(':')
|
85
|
+
@image = Docker::Image.all.select{|i| i.info['RepoTags'].include? @imagename}.first
|
86
|
+
end
|
67
87
|
end
|
68
88
|
|
69
89
|
def needed?
|
90
|
+
return false if DISABLED
|
70
91
|
not @container or
|
71
92
|
@container.info["Image"] != @image.id or
|
72
93
|
not @container.info["State"]["Running"] or
|
@@ -102,6 +123,7 @@ module Lux
|
|
102
123
|
end
|
103
124
|
|
104
125
|
def timestamp
|
126
|
+
return Time.now if DISABLED
|
105
127
|
if @container = Docker::Container.get(@containername) rescue nil
|
106
128
|
Time.iso8601(@container.info['Created'])
|
107
129
|
else
|
data/lib/lux/version.rb
CHANGED
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: 1.0.
|
4
|
+
version: 1.0.6
|
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-08-
|
11
|
+
date: 2015-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|