sle2docker 0.2.4 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/test/test_helper.rb CHANGED
@@ -1,8 +1,14 @@
1
- require File.expand_path('../../lib/sle2docker',__FILE__)
1
+ require 'codeclimate-test-reporter'
2
+ CodeClimate::TestReporter.start
3
+
4
+ require File.expand_path('../../lib/sle2docker', __FILE__)
5
+
2
6
  require 'minitest/autorun'
3
7
  require 'stringio'
4
8
  require 'fakefs/safe'
5
9
 
10
+ # rubocop:disable Style/Documentation, Lint/Eval
11
+
6
12
  class Object
7
13
  def capture(stream)
8
14
  begin
@@ -17,28 +23,27 @@ class Object
17
23
  end
18
24
  end
19
25
 
20
- class MiniTest::Test
21
-
22
- def read_fixture(name)
23
- File.read(File.expand_path("../fixtures/#{name}", __FILE__))
26
+ module MiniTest
27
+ class Test
28
+ def read_fixture(name)
29
+ File.read(File.expand_path("../fixtures/#{name}", __FILE__))
30
+ end
24
31
  end
25
-
26
32
  end
27
33
 
28
34
  class FakeStdin
29
-
30
35
  # @param [Array[String]] fake_input
31
36
  def initialize(fake_input)
32
37
  @fake_input = fake_input.reverse
33
38
  end
34
39
 
35
- def gets()
40
+ def gets
36
41
  @fake_input.pop
37
42
  end
38
43
 
39
- def noecho()
44
+ def noecho
40
45
  yield(self)
41
46
  end
42
-
43
47
  end
44
48
 
49
+ require 'mocha/mini_test'
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sle2docker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Flavio Castelli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-01 00:00:00.000000000 Z
11
+ date: 2015-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: docker-api
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: thor
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -39,7 +53,7 @@ dependencies:
39
53
  - !ruby/object:Gem::Version
40
54
  version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
- name: yard
56
+ name: fakefs
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - ">="
@@ -53,7 +67,77 @@ dependencies:
53
67
  - !ruby/object:Gem::Version
54
68
  version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
- name: fakefs
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: mocha
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: ronn
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: yard
57
141
  requirement: !ruby/object:Gem::Requirement
58
142
  requirements:
59
143
  - - ">="
@@ -67,11 +151,13 @@ dependencies:
67
151
  - !ruby/object:Gem::Version
68
152
  version: '0'
69
153
  description: |
70
- sle2docker is a convenience tool which creates SUSE Linux Enterprise images for Docker.
154
+ sle2docker is a convenience tool which creates SUSE Linux Enterprise images
155
+ for Docker.
71
156
 
72
157
  The tool relies on KIWI and Docker itself to build the images.
73
158
 
74
- Packages can be fetched either from Novell Customer Center (NCC) or from a local Subscription Management Tool (SMT).
159
+ Packages can be fetched either from Novell Customer Center (NCC) or from a
160
+ local Subscription Management Tool (SMT).
75
161
 
76
162
  Using DVD sources is currently unsupported.
77
163
  email:
@@ -82,35 +168,24 @@ extensions: []
82
168
  extra_rdoc_files: []
83
169
  files:
84
170
  - ".gitignore"
171
+ - ".rubocop.yml"
172
+ - ".travis.yml"
85
173
  - Changelog
86
174
  - Gemfile
87
175
  - LICENSE
88
176
  - README.md
89
177
  - Rakefile
90
178
  - bin/sle2docker
179
+ - coverage/.gitignore
91
180
  - lib/sle2docker.rb
92
- - lib/sle2docker/builder.rb
93
181
  - lib/sle2docker/cli.rb
94
182
  - lib/sle2docker/exceptions.rb
95
- - lib/sle2docker/template.rb
183
+ - lib/sle2docker/prebuilt_image.rb
96
184
  - lib/sle2docker/version.rb
97
- - lib/templates/SLE11SP2/config.sh
98
- - lib/templates/SLE11SP2/config.xml.erb
99
- - lib/templates/SLE11SP2/root/etc/resolv.conf
100
- - lib/templates/SLE11SP3/config.sh
101
- - lib/templates/SLE11SP3/config.xml.erb
102
- - lib/templates/SLE11SP3/root/etc/resolv.conf
103
- - lib/templates/SLE12/config.sh
104
- - lib/templates/SLE12/config.xml.erb
105
- - lib/templates/SLE12/root/etc/resolv.conf
185
+ - lib/templates/docker_build/dockerfile.erb
106
186
  - package/sle2docker.8.ronn
107
187
  - sle2docker.gemspec
108
- - test/builder_test.rb
109
- - test/fixtures/sle11sp3_config.xml
110
- - test/fixtures/sle11sp3_smt_auth_config.xml
111
- - test/fixtures/sle11sp3_smt_no_auth_https_config.xml
112
- - test/fixtures/sle11sp3_smt_no_auth_no_https_config.xml
113
- - test/template_test.rb
188
+ - test/prebuilt_image_test.rb
114
189
  - test/test_helper.rb
115
190
  homepage: https://github.com/SUSE/sle2docker
116
191
  licenses:
@@ -132,7 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
207
  version: 1.3.6
133
208
  requirements: []
134
209
  rubyforge_project: sle2docker
135
- rubygems_version: 2.2.2
210
+ rubygems_version: 2.4.5
136
211
  signing_key:
137
212
  specification_version: 4
138
213
  summary: Create SLE images for Docker
@@ -1,118 +0,0 @@
1
- module Sle2Docker
2
- class Builder
3
-
4
- def initialize(options)
5
- @options = options
6
- end
7
-
8
- # Creates the actual Docker image using kiwi
9
- #
10
- # @param [String] template_dir
11
- # @return [String] path to the image created by kiwi
12
- def create(template_dir)
13
- tmp_dir = Dir.mktmpdir("sle2docker")
14
- tmp_template_dir = File.join(tmp_dir, "template")
15
- result_dir = File.join(tmp_dir, "result")
16
-
17
- FileUtils.cp_r(File.join(template_dir, "."), tmp_template_dir)
18
- FileUtils.mkdir_p(result_dir)
19
-
20
- template_file = find_template_file(tmp_template_dir)
21
- if template_file.end_with?('.erb')
22
- template = render_template(template_file)
23
- File.open(File.join(tmp_template_dir, "config.xml"), "w") do |file|
24
- file.write(template)
25
- end
26
- end
27
-
28
- docker_cmd = "docker run --rm "
29
- # dns entries - otherwise docker uses Google's DNS
30
- dns_entries.each do |entry|
31
- docker_cmd += "--dns=#{entry} "
32
- end
33
- # the HTTP proxy specified by the user
34
- if @options[:http_proxy]
35
- docker_cmd += "-e http_proxy=#{@options[:http_proxy]} "
36
- end
37
- # ensure kiwi cache is persistent
38
- docker_cmd += "-v /var/cache/kiwi:/var/cache/kiwi "
39
- # share build dir
40
- docker_cmd += "-v #{tmp_dir}:/#{tmp_dir} "
41
- # required because kiwi needs to bind mount /proc while creating the image
42
- docker_cmd += "--privileged "
43
- # the image to use
44
- docker_cmd += "opensuse/kiwi "
45
- # kiwi directives
46
- docker_cmd += "--build #{tmp_template_dir} --type docker -d #{result_dir}"
47
- begin
48
- puts "Starting build process inside of Docker container"
49
- if !system(docker_cmd)
50
- $stderr.printf("Something wrong happened during the build process\n")
51
- exit(1)
52
- end
53
- end
54
- Dir[File.join(result_dir, "*.tbz")].first
55
- end
56
-
57
- # Looks for either config.xml or config.xml.erb inside of the template
58
- # directory.
59
- #
60
- # Exits with an error if no file is found.
61
- #
62
- # @param [String] template_dir
63
- # @return [String] full path to the template file
64
- def find_template_file(template_dir)
65
- template_file = File.join(template_dir, 'config.xml.erb')
66
-
67
- if !File.exist?(template_file)
68
- raise ConfigNotFoundError.new("Cannot find config.xml.erb file inside of #{template_dir}")
69
- end
70
-
71
- template_file
72
- end
73
-
74
- # Performs the rendering of config.xml.erb
75
- #
76
- # @param [String] template_file
77
- # @return [String] rendered template
78
- def render_template(template_file)
79
- host = if @options[:smt_host]
80
- @options[:smt_host]
81
- else
82
- "nu.novell.com"
83
- end
84
-
85
- username = @options[:username]
86
- if !username && (!@options[:password].empty? || !@options[:smt_host])
87
- puts "Enter #{@options[:smt_host] ? '' : 'NCC '}username:"
88
- username = $stdin.gets.chomp
89
- end
90
-
91
- password = @options[:password]
92
- if (username || !@options[:smt_host]) && password.empty?
93
- puts "Enter #{@options[:smt_host] ? '' : 'NCC '}password:"
94
- password = $stdin.noecho(&:gets).chomp
95
- end
96
-
97
- credentials = ""
98
- if username || !password.empty?
99
- credentials = "username='#{username}' password='#{password}'"
100
- end
101
-
102
- use_ncc = !@options[:smt_host]
103
-
104
- enable_https = !@options[:disable_https]
105
-
106
- include_build_repos = @options[:include_build_repositories]
107
-
108
- ERB.new(File.read(template_file)).result(binding)
109
- end
110
-
111
- def dns_entries
112
- File.open('/etc/resolv.conf', 'r') do |file|
113
- file.readlines("\n").grep(/\Anameserver\s+/).map{|l| l.split(" ", 2)[1].strip}
114
- end
115
- end
116
- end
117
-
118
- end
@@ -1,21 +0,0 @@
1
- module Sle2Docker
2
-
3
- class Template
4
-
5
- def self.list
6
- Dir[File.expand_path('../../templates/*', __FILE__)].map do |dir|
7
- File.basename(dir)
8
- end
9
- end
10
-
11
- def self.template_dir(template_name)
12
- dir = File.expand_path("../../templates/#{template_name.upcase}", __FILE__)
13
- if !File.exists?(dir)
14
- raise TemplateNotFoundError.new("Cannot find template with name #{template_name}")
15
- end
16
- dir
17
- end
18
-
19
- end
20
-
21
- end
@@ -1,49 +0,0 @@
1
- #!/bin/bash
2
- #================
3
- # FILE : config.sh
4
- #----------------
5
- # PROJECT : OpenSuSE KIWI Image System
6
- # COPYRIGHT : (c) 2013 SUSE LLC
7
- # :
8
- # AUTHOR : Robert Schweikert <rjschwei@suse.com>
9
- # :
10
- # BELONGS TO : Operating System images
11
- # :
12
- # DESCRIPTION : configuration script for SUSE based
13
- # : operating systems
14
- # :
15
- # :
16
- # STATUS : BETA
17
- #----------------
18
- #======================================
19
- # Functions...
20
- #--------------------------------------
21
- test -f /.kconfig && . /.kconfig
22
- test -f /.profile && . /.profile
23
-
24
- #======================================
25
- # Greeting...
26
- #--------------------------------------
27
- echo "Configure image: [$kiwi_iname]..."
28
-
29
- #======================================
30
- # Setup baseproduct link
31
- #--------------------------------------
32
- suseSetupProduct
33
-
34
- #======================================
35
- # SuSEconfig
36
- #--------------------------------------
37
- suseConfig
38
-
39
- #======================================
40
- # Activate services
41
- #--------------------------------------
42
- suseActivateDefaultServices
43
-
44
- #======================================
45
- # Umount kernel filesystems
46
- #--------------------------------------
47
- baseCleanMount
48
-
49
- exit 0
@@ -1,51 +0,0 @@
1
- <?xml version="1.0" encoding="utf-8"?>
2
-
3
- <image schemaversion="6.1" name="sles-11-SP2-docker-guest">
4
- <description type="system">
5
- <author>Flavio Castelli</author>
6
- <contact>fcastelli@suse.com</contact>
7
- <specification>SLE 11 SP2 Docker image</specification>
8
- </description>
9
- <preferences>
10
- <type image="docker" container="sles11sp2">
11
- <machine>
12
- <vmdisk/>
13
- <vmnic interface="eth0" mode="veth"/>
14
- </machine>
15
- </type>
16
- <version>1.0.0</version>
17
- <packagemanager>zypper</packagemanager>
18
- <rpm-check-signatures>false</rpm-check-signatures>
19
- <rpm-force>true</rpm-force>
20
- <locale>en_US</locale>
21
- <keytable>us.map.gz</keytable>
22
- <hwclock>utc</hwclock>
23
- <timezone>US/Eastern</timezone>
24
- </preferences>
25
- <users group="root">
26
- <user password="$1$wYJUgpM5$RXMMeASDc035eX.NbYWFl0" home="/root" name="root"/>
27
- </users>
28
- <repository type="rpm-md" alias="SLES11:SP2:Updates" <%= 'imageinclude="true"' if include_build_repos %> <%= credentials %>>
29
- <source path="http<%= "s" if enable_https %>://<%= host %>/repo/$RCE/SLES11-SP2-Updates/sle-11-x86_64<%= "?credentials=NCCcredentials" if use_ncc %>"/>
30
- </repository>
31
- <repository type="rpm-md" alias="SLES11:SP2:Core" <%= 'imageinclude="true"' if include_build_repos %> <%= credentials %>>
32
- <source path="http<%= "s" if enable_https %>://<%= host %>/repo/$RCE/SLES11-SP2-Core/sle-11-x86_64<%= "?credentials=NCCcredentials" if use_ncc %>"/>
33
- </repository>
34
- <repository type="rpm-md" alias="SLES11:SP1:Updates" <%= 'imageinclude="true"' if include_build_repos %> <%= credentials %>>
35
- <source path="http<%= "s" if enable_https %>://<%= host %>/repo/$RCE/SLES11-SP1-Updates/sle-11-x86_64<%= "?credentials=NCCcredentials" if use_ncc %>"/>
36
- </repository>
37
- <repository type="rpm-md" alias="SLES11:SP1:Pool" <%= 'imageinclude="true"' if include_build_repos %> <%= credentials %>>
38
- <source path="http<%= "s" if enable_https %>://<%= host %>/repo/$RCE/SLES11-SP1-Pool/sle-11-x86_64<%= "?credentials=NCCcredentials" if use_ncc %>"/>
39
- </repository>
40
- <packages type="image">
41
- <package name="coreutils"/>
42
- <package name="iputils"/>
43
- </packages>
44
- <packages type="bootstrap">
45
- <package name="filesystem"/>
46
- <package name="glibc-locale"/>
47
- <package name="libstdc++46"/>
48
- <package name="libgcc46"/>
49
- <package name="openssl-certs"/>
50
- </packages>
51
- </image>