lux 0.5 → 0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a1eb1c7d352c7326e296feace6572c226beb98ea
4
- data.tar.gz: 3c42a89dbc463141bbaf9da031d63fe79ef4eed7
3
+ metadata.gz: 6288ab37dee1e32be74b9ae50a4e90857ee1f175
4
+ data.tar.gz: 004c036416714fa00796143a43338b00e307f1dc
5
5
  SHA512:
6
- metadata.gz: a90943a58a1faca71b089b1f63ef8f593ea9fd419989d1dcba5acb61371f54e3ca15f90030653ac4c31e0a2401ca28a579ac8137bad043ec4ee5cdff1374fb5c
7
- data.tar.gz: 2bf8bb996fce1c3fbd89569f197560789787be1f109ab2f53a8998eb78cdde766dd98a75a9c7df9d762f674c3046efea95f793607260d6f4b34090486f46e85d
6
+ metadata.gz: 5f7504d919e5dac6496d00ab30c625858f7d79d0d7c063396fb5b6a9dcc2fc56a5e1905b6f38b0a3fa4e57bfa1a2810458488bcb949fa9c59d5853fb881e378b
7
+ data.tar.gz: 8d1ebc2248e1dc3acdb87344a5a8b0308b7d8f55e14f6ca5b802b27c2a59862f2c03021e04a118a787a8e724a94f7d3f6a10b180d1b951e7b826767cafe330dc
data/README.md CHANGED
@@ -27,8 +27,75 @@ Or install it yourself as:
27
27
 
28
28
  ## Usage
29
29
 
30
+ ### Command Line Tool
31
+
32
+ The `lux` command simplifies a number of Docker command line operations and provides
33
+ unix-style commands for listing and removing images, as well as rake-like tasks for
34
+ cleaning, tidying and clobbering containers and their images.
35
+
30
36
  Type: `lux help` to get started
31
37
 
38
+ ### Rake Tasks
39
+
40
+ When trying to write Rakefiles that start Docker containers it is useful to have a Rake
41
+ task that represents a container image. Then you can make other tasks depend on them.
42
+ If the task (when invoked) checks the local Docker server for the image, and
43
+ only executes the task body if the image is not found, then you can build Docker
44
+ dependencies elegantly into the Rakefile.
45
+
46
+ The boilerplate to do this is included in Lux as a Rake Task Generator. Here are some
47
+ examples:
48
+
49
+ ```ruby
50
+ require 'lux/dockertasks'
51
+
52
+ # Define a simple task.
53
+ # The tag will default to 'latest' and the name of the task is 'busybox'
54
+
55
+ DockerImageTask.new('busybox')
56
+
57
+ # Define a task with a tag.
58
+ # The name of the task is 'ubuntu', the tag is 'trusty'
59
+
60
+ DockerImageTask.new('ubuntu:trusty')
61
+
62
+ # Define a task with a tag and a name.
63
+ # The name of the task is 'reedy', the image is 'ubuntu' and the tag 'reedy'
64
+
65
+ DockerImageTask.new('ubuntu:reedy', :reedy)
66
+
67
+ # Define a task with a fully qualified image and a block.
68
+ # The block will be executed if the image is not found locally.
69
+ # The task object yielded has the image and tag attributes
70
+ # as well as the usual name and description.
71
+
72
+ DockerImageTask.new('quay.io/rasputin/tools:1.0') do |t|
73
+ puts "You want me to build the image #{t.image}:#{t.tag}?"
74
+ fail "Not from here I can't..."
75
+ end
76
+
77
+ desc "Run Busybox"
78
+ task :runb => 'busybox' do
79
+ sh "docker run -it busybox"
80
+ end
81
+
82
+ desc "Run Ubuntu Trusty"
83
+ task :runu => :ubuntu do
84
+ sh "docker run -it ubuntu:trusty /bin/bash"
85
+ end
86
+
87
+ desc "Run Ubuntu Reedy"
88
+ task :runr => :reedy do
89
+ sh "docker run -it ubuntu:reedy /bin/bash"
90
+ end
91
+
92
+ # Note how the task name does not include the tag
93
+ desc "Run Tools"
94
+ task :runt => 'quay.io/rasputin/tools' do
95
+ sh "docker run -it quay.io/turnitin/seu-tools:1.0 /bin/bash"
96
+ end
97
+ ```
98
+
32
99
  ## Development
33
100
 
34
101
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
@@ -0,0 +1,33 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require_relative 'lib/lux/dockertasks.rb'
4
+
5
+ DockerImageTask.new('busybox')
6
+ DockerImageTask.new('ubuntu:trusty')
7
+ DockerImageTask.new('ubuntu:reedy', :reedy)
8
+ DockerImageTask.new('quay.io/turnitin/seu-tools:1.0') do |t|
9
+ puts "You want me to build the image #{t.image}:#{t.tag}?"
10
+ fail "Not from here I can't..."
11
+ end
12
+
13
+ desc "Run Busybox"
14
+ task :runb => 'busybox' do
15
+ sh "docker run -it busybox"
16
+ end
17
+
18
+ desc "Run Ubuntu Trusty"
19
+ task :runu => :ubuntu do
20
+ sh "docker run -it ubuntu:trusty /bin/bash"
21
+ end
22
+
23
+ desc "Run Ubuntu Reedy"
24
+ task :runr => :reedy do
25
+ sh "docker run -it ubuntu:reedy /bin/bash"
26
+ end
27
+
28
+ desc "Run Tools"
29
+ task :runt => 'quay.io/turnitin/seu-tools' do
30
+ sh "docker run -it quay.io/turnitin/seu-tools /bin/bash"
31
+ end
32
+
33
+ task :default => %w{ runb runu runt runr }
@@ -0,0 +1,64 @@
1
+ require 'highline/import'
2
+ require 'rake/tasklib'
3
+
4
+ # A Task Generator for Docker images
5
+ #
6
+ # Example:
7
+ # require "lux/dockertasks"
8
+ #
9
+ # DockerImageTask.new('myimage') do
10
+ # puts "Here you can build the image"
11
+ # end
12
+ #
13
+ # task :run => 'myimage' do
14
+ # sh "docker run myimage"
15
+ # end
16
+ #
17
+ class DockerImageTask < Rake::TaskLib
18
+
19
+ # The name of the task (defaults to the image)
20
+ attr_accessor :name
21
+
22
+ # The name of the image (if different to the task name)
23
+ attr_accessor :image
24
+
25
+ # Name of tag (default is latest)
26
+ attr_accessor :tag
27
+
28
+ # Task Description (default is 'Build Docker Image <imagename>')
29
+ attr_accessor :description
30
+
31
+ # The block to execute if this needs building
32
+ attr_accessor :build
33
+
34
+ # The image may include a tag, but the tag is never part of the name
35
+ # If the tag is omitted it defaults to 'latest'
36
+ # If a name is specified it becomes the task name.
37
+ #
38
+ def initialize(image, name=nil, &block)
39
+ @image, sep, @tag = image.partition(':')
40
+ @tag = 'latest' if @tag.empty?
41
+ @name = name || @image
42
+ @description = "Build Docker Image #{@image}:#{@tag}"
43
+ @build = block
44
+ define
45
+ end
46
+
47
+ def define
48
+ desc @description
49
+ task @name do
50
+ local_images = `docker images #{@image}`.split("\n")[1..-1].map{|l| l.split(/\s+/)}
51
+ local_images.select!{|i| i[1] == @tag}
52
+ if local_images.size == 0
53
+ if @build.nil?
54
+ HighLine.say "Build Docker Image <%=BOLD%>#{@image}:#{@tag}<%=CLEAR%> before proceeding"
55
+ exit 2
56
+ else
57
+ @build.call self
58
+ end
59
+ end
60
+ end
61
+ self
62
+ end
63
+
64
+ end
@@ -1,3 +1,3 @@
1
1
  module Lux
2
- VERSION = "0.5"
2
+ VERSION = "0.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lux
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.5'
4
+ version: '0.6'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Townsend
@@ -81,8 +81,10 @@ files:
81
81
  - LICENSE.txt
82
82
  - README.md
83
83
  - Rakefile
84
+ - Rakefile.test
84
85
  - bin/lux
85
86
  - lib/lux.rb
87
+ - lib/lux/dockertasks.rb
86
88
  - lib/lux/version.rb
87
89
  - lux.gemspec
88
90
  homepage: https://github.com/townsen/lux