sle2docker 0.2.4 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.rubocop.yml +5 -0
- data/.travis.yml +7 -0
- data/Changelog +12 -0
- data/Gemfile +2 -0
- data/README.md +94 -65
- data/Rakefile +12 -1
- data/bin/sle2docker +11 -2
- data/lib/sle2docker.rb +3 -2
- data/lib/sle2docker/cli.rb +32 -92
- data/lib/sle2docker/exceptions.rb +8 -1
- data/lib/sle2docker/prebuilt_image.rb +114 -0
- data/lib/sle2docker/version.rb +3 -3
- data/lib/templates/docker_build/dockerfile.erb +4 -0
- data/package/sle2docker.8.ronn +94 -53
- data/sle2docker.gemspec +24 -14
- data/test/prebuilt_image_test.rb +91 -0
- data/test/test_helper.rb +15 -10
- metadata +99 -24
- data/lib/sle2docker/builder.rb +0 -118
- data/lib/sle2docker/template.rb +0 -21
- data/lib/templates/SLE11SP2/config.sh +0 -49
- data/lib/templates/SLE11SP2/config.xml.erb +0 -51
- data/lib/templates/SLE11SP2/root/etc/resolv.conf +0 -0
- data/lib/templates/SLE11SP3/config.sh +0 -49
- data/lib/templates/SLE11SP3/config.xml.erb +0 -45
- data/lib/templates/SLE11SP3/root/etc/resolv.conf +0 -0
- data/lib/templates/SLE12/config.sh +0 -49
- data/lib/templates/SLE12/config.xml.erb +0 -44
- data/lib/templates/SLE12/root/etc/resolv.conf +0 -0
- data/test/builder_test.rb +0 -190
- data/test/fixtures/sle11sp3_config.xml +0 -45
- data/test/fixtures/sle11sp3_smt_auth_config.xml +0 -45
- data/test/fixtures/sle11sp3_smt_no_auth_https_config.xml +0 -45
- data/test/fixtures/sle11sp3_smt_no_auth_no_https_config.xml +0 -45
- data/test/template_test.rb +0 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66989f86821ec67600802b06f47b06949c850ef2
|
4
|
+
data.tar.gz: 5309625b91a0c5eea400ad81c6e5d62505217dcc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61ac461a8d6aafb94ea5edbee727134340f36d49bc9f0d92eb06b41d882c4ae96a5730cf6301be51f62e9c8d3374a0128730a11b8dc15fe16b7cb4e2917a16ce
|
7
|
+
data.tar.gz: f2cb23ff54f2d3cb67da418e5527e0a796f5fdf7c4a0c89906081aa20051241e0c62d1b1bee210e0b383b622d288d16442921c3f39c30508f3e6d2c9360c7200
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/Changelog
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
Tue Jun 16 23:04:11 CEST 2015 Flavio Castelli <flavio@castelli.name>
|
2
|
+
|
3
|
+
* Version 0.4.0:
|
4
|
+
- Drop old build system: do no longer build images using kiwi
|
5
|
+
- Revisit the activation code: it is no longer necessary to copy
|
6
|
+
the org credentials or the host repositories into the final image
|
7
|
+
|
8
|
+
Mon Apr 20 17:46:52 CEST 2015 Flavio Castelli <flavio@castelli.name>
|
9
|
+
|
10
|
+
* Version 0.3.0 rc1:
|
11
|
+
- Added support for pre-built Docker images.
|
12
|
+
|
1
13
|
Mon Dec 01 17:38:53 CET 2014 Flavio Castelli <fcastelli@suse.com>
|
2
14
|
|
3
15
|
* Version 0.2.4:
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,13 +1,21 @@
|
|
1
|
-
|
2
|
-
[
|
1
|
+
[![Build Status](https://travis-ci.org/SUSE/sle2docker.svg)](https://travis-ci.org/SUSE/sle2docker)
|
2
|
+
[![Code Climate](https://codeclimate.com/github/SUSE/sle2docker/badges/gpa.svg)](https://codeclimate.com/github/SUSE/sle2docker)
|
3
|
+
[![Test Coverage](https://codeclimate.com/github/SUSE/sle2docker/badges/coverage.svg)](https://codeclimate.com/github/SUSE/sle2docker)
|
3
4
|
|
4
|
-
|
5
|
-
|
5
|
+
sle2docker is a convenience tool which imports the pre-built SUSE Linux Enterprise
|
6
|
+
images for Docker.
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
The tool takes advantage of pre-built Docker images distributed by SUSE to
|
9
|
+
create the base Docker image that users can later customize using Docker's
|
10
|
+
integrated build system. The pre-built images are distributed by SUSE as RPMs.
|
9
11
|
|
10
|
-
|
12
|
+
Pre-built images do not have repositories configured but zypper will
|
13
|
+
automatically have access to the right repositories when the Docker host has a
|
14
|
+
SLE subscription that provides access to the product used in the image. For
|
15
|
+
more details read the "Customizing the images" section below.
|
16
|
+
|
17
|
+
Previous versions of the tool built the Docker images from KIWI templates
|
18
|
+
distributed by SUSE. This is no longer possible.
|
11
19
|
|
12
20
|
# Requirements
|
13
21
|
|
@@ -24,104 +32,125 @@ The recommended way to install sle2docker is via zypper:
|
|
24
32
|
sudo zypper in sle2docker
|
25
33
|
```
|
26
34
|
|
27
|
-
However sle2docker can be installed via gem:
|
35
|
+
However sle2docker can also be installed via gem:
|
28
36
|
|
29
37
|
```
|
30
38
|
sudo gem install --no-format-exec sle2docker
|
31
39
|
```
|
32
40
|
|
33
41
|
The `--no-format-exec` is recommended otherwise the `sle2docker` binary will
|
34
|
-
be prefixed with the ruby version installed on the system (
|
42
|
+
be prefixed with the ruby version installed on the system (e.g.: the binary on
|
35
43
|
SLE12 would be called `sle2docker.ruby2.1`).
|
36
44
|
|
37
|
-
#
|
45
|
+
# Usage
|
38
46
|
|
39
|
-
|
40
|
-
source files which are filled with the informations provided by the user at
|
41
|
-
runtime.
|
47
|
+
To list the available pre-built images use the following command:
|
42
48
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
+
```
|
50
|
+
sle2docker list
|
51
|
+
Available pre-built images:
|
52
|
+
- sles11sp3-docker.x86_64-1.0.0-Build1.3
|
53
|
+
- sles12-docker.x86_64-1.0.0-Build7.4
|
54
|
+
```
|
49
55
|
|
50
|
-
|
51
|
-
downloadable from the [Docker Hub](https://registry.hub.docker.com/). The image
|
52
|
-
is built using Docker's build system by starting from the
|
53
|
-
[official openSUSE image](https://registry.hub.docker.com/_/opensuse/).
|
54
|
-
The `Dockerfile` used to create this image can be found inside of
|
55
|
-
[this](https://github.com/openSUSE/docker-containers) repository.
|
56
|
+
To activate the pre-built image use the following command:
|
56
57
|
|
57
|
-
sle2docker
|
58
|
-
system.
|
58
|
+
`sle2docker activate IMAGE_NAME`
|
59
59
|
|
60
|
-
#
|
60
|
+
# Customizing the images
|
61
61
|
|
62
|
-
To
|
62
|
+
To create custom Docker images based on the official ones use
|
63
|
+
[Docker's integrated build system](http://docs.docker.com/reference/builder/).
|
63
64
|
|
64
|
-
|
65
|
-
|
66
|
-
|
65
|
+
The pre-built images do not have any repository configured. They
|
66
|
+
contain a [zypper service](https://github.com/SUSE/container-suseconnect) that
|
67
|
+
contacts either the SUSE Customer Center (SCC) or your Subscription
|
68
|
+
Management Tool (SMT) server according to the configuration of the SLE host
|
69
|
+
running the Docker container. The service obtains the list of repositories
|
70
|
+
available for the product used by the Docker image.
|
67
71
|
|
68
|
-
|
72
|
+
There is no need to add any credential to the Docker image because the machine
|
73
|
+
credentials are automatically injected into the container by the docker daemon.
|
74
|
+
These are injected inside of the `/run/secrets` directory. The same applies to
|
75
|
+
the `/etc/SUSEConnect` file of the host system, which is automatically injected
|
76
|
+
into the `/run/secrets`.
|
69
77
|
|
70
|
-
|
71
|
-
|
72
|
-
```
|
78
|
+
The contents of the `/run/secrets` directory are never committed to a Docker
|
79
|
+
image, hence there's no risk of leaking your credentials.
|
73
80
|
|
74
|
-
|
75
|
-
following command:
|
81
|
+
To obtain the list of repositories invoke:
|
76
82
|
|
77
|
-
|
78
|
-
|
79
|
-
|
83
|
+
`zypper ref -s`
|
84
|
+
|
85
|
+
This will automatically add all the repositories to your container. For each
|
86
|
+
repository added to the system a new file is going to be created under
|
87
|
+
`/etc/zypp/repos.d`. The URLs of these repositories include an access token
|
88
|
+
that automatically expires after 12 hours. To renew the token just call the
|
89
|
+
`zypper ref -s` command. It is totally fine, and secure, to commit these files
|
90
|
+
to a Docker image.
|
91
|
+
|
92
|
+
If you want to use a different set of credentials, place a custom
|
93
|
+
`/etc/zypp/credentials.d/SCCcredentials` with the machine credentials
|
94
|
+
having the subscription you want to use inside of the Docker image.
|
95
|
+
The same applies to the `SUSEConnect` file: if you want to override the one
|
96
|
+
available on the host system running the Docker container you have to add a
|
97
|
+
custom `/etc/SUSEConnect` file inside of the Docker image.
|
80
98
|
|
81
|
-
##
|
99
|
+
## Creating a custom SLE12 image
|
82
100
|
|
83
|
-
|
84
|
-
Customer Center (SCC). Before the build starts sle2docker ask the user
|
85
|
-
his credentials. It is possible to start a build in a non interactive way by
|
86
|
-
using the following command:
|
101
|
+
This Dockerfile creates a simple Docker image based on SLE12:
|
87
102
|
|
88
103
|
```
|
89
|
-
|
104
|
+
FROM suse/sles12:latest
|
105
|
+
|
106
|
+
RUN zypper --gpg-auto-import-keys ref -s
|
107
|
+
RUN zypper -n in vim
|
90
108
|
```
|
91
109
|
|
110
|
+
When the Docker host machine is registered against an internal SMT
|
111
|
+
server the Docker image requires the ssl certificate used by SMT:
|
92
112
|
|
93
|
-
|
113
|
+
```
|
114
|
+
FROM suse/sles12:latest
|
94
115
|
|
95
|
-
|
96
|
-
|
116
|
+
# Import the crt file of our private SMT server
|
117
|
+
ADD http://smt.test.lan/smt.crt /etc/pki/trust/anchors/smt.crt
|
118
|
+
RUN update-ca-certificates
|
97
119
|
|
98
|
-
|
99
|
-
|
120
|
+
RUN zypper --gpg-auto-import-keys ref -s
|
121
|
+
RUN zypper -n in vim
|
100
122
|
```
|
101
123
|
|
102
|
-
|
103
|
-
|
104
|
-
|
124
|
+
## Creating a custom SLE11SP3 image
|
125
|
+
|
126
|
+
This Dockerfile creates a simple Docker image based on SLE12:
|
105
127
|
|
106
128
|
```
|
107
|
-
|
129
|
+
FROM suse/sles11sp3:latest
|
130
|
+
|
131
|
+
RUN zypper --gpg-auto-import-keys ref -s
|
132
|
+
RUN zypper -n in vim
|
108
133
|
```
|
109
134
|
|
110
|
-
|
111
|
-
|
135
|
+
When the Docker host machine is registered against an internal SMT
|
136
|
+
server the Docker image requires the ssl certificate used by SMT:
|
112
137
|
|
113
138
|
```
|
114
|
-
|
115
|
-
```
|
139
|
+
FROM suse/sles11sp3:latest
|
116
140
|
|
117
|
-
|
118
|
-
|
119
|
-
|
141
|
+
# Import the crt file of our private SMT server
|
142
|
+
ADD http://smt.test.lan/smt.crt /etc/ssl/certs/smt.pem
|
143
|
+
RUN c_rehash /etc/ssl/certs
|
120
144
|
|
145
|
+
RUN zypper --gpg-auto-import-keys ref -s
|
146
|
+
RUN zypper -n in vim
|
121
147
|
```
|
122
|
-
sle2docker build -s SMT_SERVER_HOSTNAME -u USERNAME -p PASSWORD TEMPLATE
|
123
|
-
```
|
124
148
|
|
149
|
+
# Additional documentation
|
150
|
+
|
151
|
+
For more information visit the
|
152
|
+
[SUSE's Docker documentation](https://www.suse.com/documentation/sles-12/dockerquick/data/dockerquick.html)
|
153
|
+
page.
|
125
154
|
|
126
155
|
# License
|
127
156
|
|
data/Rakefile
CHANGED
@@ -14,5 +14,16 @@ begin
|
|
14
14
|
require 'yard'
|
15
15
|
YARD::Rake::YardocTask.new
|
16
16
|
rescue LoadError
|
17
|
-
|
17
|
+
warn 'Yard not available. To generate documentation install it with: ' \
|
18
|
+
'gem install yard'
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'rubocop/rake_task'
|
22
|
+
RuboCop::RakeTask.new
|
23
|
+
|
24
|
+
task default: :test
|
25
|
+
|
26
|
+
desc 'Generate man pages'
|
27
|
+
task :man do
|
28
|
+
system "ronn #{File.expand_path('../package/sle2docker.8.ronn', __FILE__)}"
|
18
29
|
end
|
data/bin/sle2docker
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require_relative '../lib/sle2docker'
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
begin
|
5
|
+
Sle2Docker::Cli.start(ARGV)
|
6
|
+
rescue Sle2Docker::TemplateNotFoundError => ex
|
7
|
+
$stderr.printf(ex.message + "\n")
|
8
|
+
$stderr.printf("To list the available templates use:\n")
|
9
|
+
$stderr.printf(" sle2docker list\n")
|
10
|
+
exit(1)
|
11
|
+
rescue StandardError => e
|
12
|
+
$stderr.printf(e.message + "\n")
|
13
|
+
exit(1)
|
14
|
+
end
|
data/lib/sle2docker.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'docker'
|
2
|
+
require 'English'
|
1
3
|
require 'erb'
|
2
4
|
require 'fileutils'
|
3
5
|
require 'io/console'
|
@@ -6,7 +8,6 @@ require 'thor'
|
|
6
8
|
require 'tmpdir'
|
7
9
|
|
8
10
|
require_relative 'sle2docker/cli'
|
9
|
-
require_relative 'sle2docker/builder'
|
10
11
|
require_relative 'sle2docker/exceptions'
|
11
|
-
require_relative 'sle2docker/
|
12
|
+
require_relative 'sle2docker/prebuilt_image'
|
12
13
|
require_relative 'sle2docker/version'
|
data/lib/sle2docker/cli.rb
CHANGED
@@ -1,107 +1,47 @@
|
|
1
1
|
module Sle2Docker
|
2
|
-
|
2
|
+
# Entry point of the command line interface
|
3
3
|
class Cli < Thor
|
4
|
+
desc 'list', 'List available pre-built images'
|
5
|
+
def list
|
6
|
+
puts 'Available pre-built images:'
|
7
|
+
prebuilt_images = PrebuiltImage.list
|
8
|
+
if prebuilt_images.empty?
|
9
|
+
puts 'No pre-built image found.'
|
10
|
+
puts "\nPre-built images can be installed from SLE12 Update " \
|
11
|
+
'repository using zypper:'
|
12
|
+
puts ' zypper install \"sle*-docker-image\"'
|
13
|
+
else
|
14
|
+
prebuilt_images.each { |image| puts " - #{image}" }
|
15
|
+
end
|
16
|
+
end
|
4
17
|
|
5
|
-
|
6
|
-
|
7
|
-
|
18
|
+
desc 'activate IMAGE_NAME', 'Activate a pre-built image'
|
19
|
+
def activate(image_name)
|
20
|
+
ensure_can_access_dockerd
|
8
21
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
# exit(1)
|
15
|
-
#end
|
22
|
+
prebuilt_image = Sle2Docker::PrebuiltImage.new(image_name, options)
|
23
|
+
if prebuilt_image.activated?
|
24
|
+
warn 'Image has already been activated. Exiting'
|
25
|
+
exit(0)
|
26
|
+
end
|
16
27
|
|
17
|
-
|
18
|
-
|
19
|
-
puts "Available templates:"
|
20
|
-
Template.list.each {|template| puts " - #{template}"}
|
28
|
+
prebuilt_image.activate
|
29
|
+
puts "#{prebuilt_image.image_id} activated"
|
21
30
|
end
|
22
31
|
|
23
|
-
map
|
24
|
-
desc
|
32
|
+
map '-v' => :version
|
33
|
+
desc 'version', 'Display version'
|
25
34
|
def version
|
26
35
|
puts Sle2Docker::VERSION
|
27
36
|
end
|
28
37
|
|
29
|
-
|
30
|
-
method_option :username, :aliases => "-u", :type => :string,
|
31
|
-
:default => nil,
|
32
|
-
:desc => "Username required to access repositories"
|
33
|
-
method_option :password, :aliases => "-p", :type => :string,
|
34
|
-
:default => "",
|
35
|
-
:desc => "Password required to access repositories"
|
36
|
-
method_option :smt_host, :aliases => ["-s", "--smt-host"], :type => :string,
|
37
|
-
:default => nil,
|
38
|
-
:desc => "SMT machine hosting the repositories"
|
39
|
-
method_option :disable_https, :aliases => ["--disable-https"],
|
40
|
-
:type => :boolean,
|
41
|
-
:default => false,
|
42
|
-
:desc => "Do not use HTTPS when accessing repositories"
|
43
|
-
method_option :include_build_repositories, :aliases => ["--include-build-repos"],
|
44
|
-
:type => :boolean,
|
45
|
-
:default => true,
|
46
|
-
:desc => "Add the repositories used at build time to the Docker image"
|
47
|
-
def show(template_name)
|
48
|
-
template_dir = Template.template_dir(template_name)
|
49
|
-
builder = Builder.new(options)
|
50
|
-
template_file = builder.find_template_file(template_dir)
|
51
|
-
if template_file.end_with?('.erb')
|
52
|
-
template = builder.render_template(template_file)
|
53
|
-
puts "\n\n"
|
54
|
-
puts template
|
55
|
-
end
|
56
|
-
rescue ConfigNotFoundError => e
|
57
|
-
$stderr.printf(e.message + "\n")
|
58
|
-
exit(1)
|
59
|
-
rescue TemplateNotFoundError => ex
|
60
|
-
$stderr.printf(ex.message + "\n")
|
61
|
-
$stderr.printf("To list the available templates use:\n")
|
62
|
-
$stderr.printf(" sle2docker list\n")
|
63
|
-
exit(1)
|
64
|
-
end
|
38
|
+
private
|
65
39
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
:default => "",
|
72
|
-
:desc => "Password required to access repositories"
|
73
|
-
method_option :smt_host, :aliases => ["-s", "--smt-host"], :type => :string,
|
74
|
-
:default => nil,
|
75
|
-
:desc => "SMT machine hosting the repositories"
|
76
|
-
method_option :disable_https, :aliases => ["--disable-https"],
|
77
|
-
:type => :boolean,
|
78
|
-
:default => false,
|
79
|
-
:desc => "Do not use HTTPS when accessing repositories"
|
80
|
-
method_option :http_proxy, :aliases => ["--http-proxy"],
|
81
|
-
:default => ENV['http_proxy'],
|
82
|
-
:desc => "HTTP proxy to use (eg: http://squid.local:3128)"
|
83
|
-
method_option :include_build_repositories, :aliases => ["--include-build-repos"],
|
84
|
-
:type => :boolean,
|
85
|
-
:default => true,
|
86
|
-
:desc => "Add the repositories used at build time to the Docker image"
|
87
|
-
def build(template_name)
|
88
|
-
template_dir = Template.template_dir(template_name)
|
89
|
-
builder = Builder.new(options)
|
90
|
-
container = builder.create(template_dir)
|
91
|
-
puts "Container created, it can be imported by running the following command:"
|
92
|
-
puts " docker import - <desired image name> < #{container}"
|
93
|
-
puts "\nThen the '#{File.expand_path(File.join(File.dirname(container), '..'))}' directory and all its contents can be removed."
|
94
|
-
puts "Note well: KIWI created some of these files while running as root user, " +
|
95
|
-
"hence root privileges are required to remove them."
|
96
|
-
rescue ConfigNotFoundError => e
|
97
|
-
$stderr.printf(e.message + "\n")
|
98
|
-
exit(1)
|
99
|
-
rescue TemplateNotFoundError => ex
|
100
|
-
$stderr.printf(ex.message + "\n")
|
101
|
-
$stderr.printf("To list the available templates use:\n")
|
102
|
-
$stderr.printf(" sle2docker list\n")
|
103
|
-
exit(1)
|
40
|
+
def ensure_can_access_dockerd
|
41
|
+
output = `docker info`
|
42
|
+
if $CHILD_STATUS.exitstatus != 0
|
43
|
+
raise output
|
44
|
+
end
|
104
45
|
end
|
105
|
-
|
106
46
|
end
|
107
47
|
end
|