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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3f15d09b5ede994585073034cba25c4c68c271aa
4
- data.tar.gz: 7a7d3c1fcdae3a14470dc0338b7d108733ea31c0
3
+ metadata.gz: 66989f86821ec67600802b06f47b06949c850ef2
4
+ data.tar.gz: 5309625b91a0c5eea400ad81c6e5d62505217dcc
5
5
  SHA512:
6
- metadata.gz: b5fd6e752a653025541797f876a0cf9e807998fa52c78704cfd9373801717c16f0f58074b2e2e6026035716bc72df3205b643c9e19767a4d5751fd2be97281ec
7
- data.tar.gz: 0ce0c1b71744653b85cb1f483493820d7da2e843c51e8e8a719661bd6642514393ec7792a86d78528143485f5d1bfaa17004bea1000921fcb3e73370daeb6a56
6
+ metadata.gz: 61ac461a8d6aafb94ea5edbee727134340f36d49bc9f0d92eb06b41d882c4ae96a5730cf6301be51f62e9c8d3374a0128730a11b8dc15fe16b7cb4e2917a16ce
7
+ data.tar.gz: f2cb23ff54f2d3cb67da418e5527e0a796f5fdf7c4a0c89906081aa20051241e0c62d1b1bee210e0b383b622d288d16442921c3f39c30508f3e6d2c9360c7200
data/.gitignore CHANGED
@@ -1 +1,4 @@
1
1
  pkg
2
+ Vagrantfile
3
+ package/sle2docker.8
4
+ package/sle2docker.8.html
data/.rubocop.yml ADDED
@@ -0,0 +1,5 @@
1
+ AllCops:
2
+ Exclude:
3
+ - Vagrantfile
4
+ - sle2docker.gemspec
5
+ - lib/templates/**/*
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.2
4
+ addons:
5
+ code_climate:
6
+ repo_token:
7
+ secure: eLzFNGAZk9F3FBXO+zCR11DxoPf7OH7mW8+4Ige4fifBgxGbwGeLEgF9YqALgNYd9MzR/UNcUR5+2Lyr2sPkmZzu9h81Bju3yi5dQICWdmldQQ26OBaeDloD4VHn9GLiunFyTFLQv8Z9GfAE1lRZYxLCS2nr+hi1hJOAazq+bhk=
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
@@ -2,3 +2,5 @@ source 'https://rubygems.org/'
2
2
 
3
3
  # Specify your gem's dependencies in sle2docker.gemspec
4
4
  gemspec
5
+
6
+ gem 'codeclimate-test-reporter', group: :test, require: nil
data/README.md CHANGED
@@ -1,13 +1,21 @@
1
- sle2docker is a convenience tool which creates SUSE Linux Enterprise images for
2
- [Docker](http://docker.com).
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
- The tool relies on [KIWI](https://github.com/openSUSE/kiwi) and Docker itself
5
- to build the images.
5
+ sle2docker is a convenience tool which imports the pre-built SUSE Linux Enterprise
6
+ images for Docker.
6
7
 
7
- Packages can be fetched either from SUSE Customer Center (SCC) or from a local
8
- Subscription Management Tool (SMT).
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
- Using DVD sources is currently unsupported.
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 (eg: the binary on
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
- # How it works
45
+ # Usage
38
46
 
39
- The sle2docker gem comes with a set of supported SLE templates. These are KIWI
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
- The image creation happens inside of
44
- [this](https://registry.hub.docker.com/u/opensuse/kiwi/)
45
- Docker image. This has to be done because on recent systems (like SLE12) KIWI
46
- cannot create SLE11 images. That happens because building a SLE11 systems
47
- requires the `db45-utils` package to be installed on the host system; this
48
- package is obsolete and is not available on SLE12.
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
- The Docker image used by sle2docker is based on openSUSE and it's freely
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 automatically fetches the `opensuse/kiwi` image if not found on the
58
- system.
58
+ `sle2docker activate IMAGE_NAME`
59
59
 
60
- # Usage
60
+ # Customizing the images
61
61
 
62
- To build a template just use the following command:
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
- sle2docker build TEMPLATE
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
- A list of the available templates may be obtained by running:
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
- sle2docker list
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
- A templated rendered with user provided data can be printed by using the
75
- following command:
81
+ To obtain the list of repositories invoke:
76
82
 
77
- ```
78
- sle2docker show TEMPLATE
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
- ## SUSE Customer Center integration
99
+ ## Creating a custom SLE12 image
82
100
 
83
- By default sle2docker downloads all the required packages from SUSE
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
- sle2docker build -u USERNAME -p PASSWORD TEMPLATE_NAME
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
- ## Subscription Management Tool integration
113
+ ```
114
+ FROM suse/sles12:latest
94
115
 
95
- It is possible to download all the required packages from a local
96
- Subscription Management Tool (SMT) instance:
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
- sle2docker build -s SMT_SERVER_HOSTNAME/repo TEMPLATE
120
+ RUN zypper --gpg-auto-import-keys ref -s
121
+ RUN zypper -n in vim
100
122
  ```
101
123
 
102
- By default sle2docker assumes the contents of the SMT server are served over
103
- HTTPS. To force the retrieval of the package over plain HTTP use the
104
- following command:
124
+ ## Creating a custom SLE11SP3 image
125
+
126
+ This Dockerfile creates a simple Docker image based on SLE12:
105
127
 
106
128
  ```
107
- sle2docker build -s SMT_SERVER_HOSTNAME/repo --disable-https TEMPLATE
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
- Example: Say the FQDN of your SMT is mysmt.company.com and you want to build a SLE12 Docker image.
111
- The corresponding call to sle2docker would look like this:
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
- sle2docker build -s mysmt.company.com/repo --disable-https SLE12
115
- ```
139
+ FROM suse/sles11sp3:latest
116
140
 
117
- By default sle2docker expects the SMT instance to not require any form of
118
- authentication. However it is possible to specify the access credentials by
119
- using the following command:
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
- puts "Yard not available. To generate documentation install it with: gem install yard"
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
- Sle2Docker::Cli.start(ARGV)
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/template'
12
+ require_relative 'sle2docker/prebuilt_image'
12
13
  require_relative 'sle2docker/version'
@@ -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
- #def initialize
6
- # @options, @template_dir = parse_options()
7
- #end
18
+ desc 'activate IMAGE_NAME', 'Activate a pre-built image'
19
+ def activate(image_name)
20
+ ensure_can_access_dockerd
8
21
 
9
- #def start
10
- # builder = Builder.new(@options)
11
- # builder.create(@template_dir)
12
- #rescue ConfigNotFoundError => e
13
- # $stderr.printf(e.message + "\n")
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
- desc "list", "List the available templates"
18
- def list
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 "-v" => :version
24
- desc "version", "Display version"
32
+ map '-v' => :version
33
+ desc 'version', 'Display version'
25
34
  def version
26
35
  puts Sle2Docker::VERSION
27
36
  end
28
37
 
29
- desc "show TEMPLATE", "Print the rendered TEMPLATE"
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
- desc "build TEMPLATE", "Use TEMPLATE to build a SLE Docker image"
67
- method_option :username, :aliases => "-u", :type => :string,
68
- :default => nil,
69
- :desc => "Username required to access repositories"
70
- method_option :password, :aliases => "-p", :type => :string,
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