dodebui 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 040519848fb5a241f48c418cf81862520214684e
4
+ data.tar.gz: 3a7c0405fbb3f1918ee8732c5f2d3478036c60b3
5
+ SHA512:
6
+ metadata.gz: 05e200181bce533f3038d6ae62b55d665ea1ab84ec17892d3ef8a3930d60f62a7d73ca7fa2076f5fa6d15fc1ddef4830f0b894135eb39f457ce7a490d37f1773
7
+ data.tar.gz: aefd6b2cb795837bc3559d63c3adbcfd17d67018495b22af725fcca64fb72a52360fc92f50e8760e0fd3ca40c88d34681169b4f61f830aad6f820a31090bcdd2
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rubocop.yml ADDED
@@ -0,0 +1,4 @@
1
+ Metrics/ClassLength:
2
+ Max: 180
3
+ Metrics/MethodLength:
4
+ Max: 20
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in dodebui.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Christian Simon
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Dodebui
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'dodebui'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install dodebui
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/dodebui/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rubocop/rake_task'
3
+ RuboCop::RakeTask.new
data/bin/dodebui ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'dodebui/cli'
3
+ Dodebui::Cli.new.run
data/dodebui.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'dodebui/version'
5
+
6
+ desc = 'Docker Debian builder (DoDeBui): '
7
+ desc += 'Builds debian packages in Docker containers'
8
+
9
+ Gem::Specification.new do |spec|
10
+ spec.name = 'dodebui'
11
+ spec.version = Dodebui::VERSION
12
+ spec.authors = ['Christian Simon']
13
+ spec.email = ['simon@swine.de']
14
+ spec.summary = desc
15
+ spec.description = desc
16
+ spec.homepage = 'https://github.com/simonswine/dodebui'
17
+ spec.license = 'GPLv3'
18
+ spec.files = `git ls-files -z`.split("\x0")
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_dependency 'docker-api'
24
+ spec.add_development_dependency 'bundler', '~> 1.7'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'rubocop', '~> 0.30'
27
+ end
@@ -0,0 +1,190 @@
1
+ require 'dodebui/template_namespace'
2
+ require 'open3'
3
+ require 'erb'
4
+
5
+ module Dodebui
6
+ # Handles the build process of a package
7
+ class Build
8
+ attr_reader :distribution
9
+
10
+ def initialize(distribution)
11
+ @distribution = distribution
12
+ @cli = distribution.cli
13
+ end
14
+
15
+ def local_expect(desc, *args)
16
+ Open3.popen3(*args) do |_i, o, e, t|
17
+ if args[0].is_a? Hash
18
+ cmd = args[1]
19
+ else
20
+ cmd = args[0]
21
+ end
22
+ ret_val = t.value.exitstatus
23
+ if ret_val == 0
24
+ logger.debug("#{desc} (cmd=#{cmd}): succeed")
25
+ else
26
+ output = "Exec failed cmd=#{cmd} ret_val=#{ret_val}"
27
+ output += "stdout=#{o.read} stderr=#{e.read}"
28
+ fail output
29
+ end
30
+ end
31
+ end
32
+
33
+ def write_log(name, o, e)
34
+ o_path = File.join(build_dir, "#{name}.stdout.log")
35
+ e_path = File.join(build_dir, "#{name}.stderr.log")
36
+ File.open(o_path, 'w') { |file| file.write(o.join '') }
37
+ File.open(e_path, 'w') { |file| file.write(e.join '') }
38
+ end
39
+
40
+ def build_container_create_start
41
+ logger.info("Creating container #{@distribution.codename}")
42
+ @container = Docker::Container.create(
43
+ 'Image' => @distribution.image_name,
44
+ 'Cmd' => %w(sleep 3600),
45
+ 'WorkingDir' => '/_build/source'
46
+ )
47
+ logger.info("Starting container #{@distribution.codename}")
48
+ @container.start('Binds' => [
49
+ "#{File.join(cache_dir, 'archives')}:/var/cache/apt/archives",
50
+ "#{build_dir}:/_build"
51
+ ])
52
+ end
53
+
54
+ def build_dependencies
55
+ logger.info("Installing dependencies #{@distribution.codename}")
56
+ stdout, stderr, ret_val = @container.exec([
57
+ '/usr/lib/pbuilder/pbuilder-satisfydepends-aptitude'
58
+ ])
59
+ write_log('apt_install_deps', stdout, stderr)
60
+ if ret_val != 0
61
+ logger.warn("Failed installing dependencies #{@distribution.codename}")
62
+ fail
63
+ end
64
+ logger.info("Finished installing dependencies #{@distribution.codename}")
65
+ end
66
+
67
+ def build_package
68
+ logger.info("Building package #{@distribution.codename}")
69
+ stdout, stderr, ret_val = @container.exec([
70
+ 'dpkg-buildpackage'
71
+ ])
72
+ write_log('build', stdout, stderr)
73
+ if ret_val != 0
74
+ logger.warn("Failed building package #{@distribution.codename}")
75
+ fail
76
+ end
77
+ logger.info("Finished building package #{@distribution.codename}")
78
+ end
79
+
80
+ def build
81
+ build_container_create_start
82
+
83
+ build_dependencies
84
+
85
+ build_package
86
+
87
+ @container.stop
88
+
89
+ true
90
+ rescue RuntimeError
91
+ false
92
+ end
93
+
94
+ def cache_dir
95
+ File.expand_path(
96
+ File.join(
97
+ '/var/lib/dodebui',
98
+ "#{distribution.os}_#{distribution.codename}"
99
+ )
100
+ )
101
+ end
102
+
103
+ def build_dir
104
+ File.expand_path(
105
+ File.join(
106
+ @cli.wd,
107
+ '..',
108
+ '_build',
109
+ "#{distribution.os}_#{distribution.codename}"
110
+ )
111
+ )
112
+ end
113
+
114
+ def source
115
+ source_copy
116
+ source_changelog
117
+ source_templates
118
+ end
119
+
120
+ def logger
121
+ @cli.logger
122
+ end
123
+
124
+ def source_dir
125
+ File.join(build_dir, 'source')
126
+ end
127
+
128
+ def source_template_namespace
129
+ TemplateNamespace.new(
130
+ os: @distribution.os,
131
+ codename: @distribution.codename,
132
+ codename_int: @distribution.codename_int
133
+ )
134
+ end
135
+
136
+ def source_template_eval(path)
137
+ logger.debug "Evaluate template #{path}"
138
+ erb = ERB.new(
139
+ File.read(path),
140
+ nil,
141
+ '-'
142
+ )
143
+ erb.result(source_template_namespace.priv_binding)
144
+ end
145
+
146
+ def source_templates
147
+ @cli.source_templates.each do |template|
148
+ src = File.join(source_dir, template)
149
+ dest = src[0...-4]
150
+ File.open(dest, 'w') do |file|
151
+ file.write(source_template_eval(src))
152
+ end
153
+ sh "chmod +x #{template}" if template == 'debian/rules'
154
+ end
155
+ end
156
+
157
+ def source_copy
158
+ logger.debug "Start copying sources to #{source_dir}"
159
+ FileUtils.mkdir_p build_dir
160
+ FileUtils.rm_rf source_dir
161
+ FileUtils.cp_r @cli.wd, source_dir
162
+ logger.debug "Finished copying sources to #{source_dir}"
163
+ end
164
+
165
+ def source_changelog_dch(path)
166
+ output = 'dch --changelog %{path} -l "+%{cn_str}%{cn}" -D "%{cn}" '
167
+ output += '--force-distribution '
168
+ output += '"Build a changelog entry for %{cn} %{cn}"'
169
+
170
+ output % {
171
+ cn: @distribution.codename,
172
+ cn_str: @distribution.codename_str,
173
+ path: path
174
+ }
175
+ end
176
+
177
+ def source_changelog
178
+ path = File.join(source_dir, 'debian/changelog')
179
+ logger.debug "Modify changelog file #{path}"
180
+ local_expect(
181
+ 'append distribution build to changelog',
182
+ {
183
+ 'DEBFULLNAME' => 'Jenkins Autobuilder',
184
+ 'DEBEMAIL' => 'jenkins@former03.de'
185
+ },
186
+ source_changelog_dch(path)
187
+ )
188
+ end
189
+ end
190
+ end
@@ -0,0 +1,120 @@
1
+ require 'dodebui/version'
2
+ require 'dodebui/distribution'
3
+ require 'logger'
4
+ require 'docker'
5
+
6
+ module Dodebui
7
+ ## commandline interface for dodebui
8
+ class Cli
9
+ attr_accessor :source_templates, :build_distributions
10
+ attr_reader :wd
11
+
12
+ def self.logger
13
+ @logger ||= Logger.new(STDOUT)
14
+ end
15
+
16
+ def initialize
17
+ @dodebuifiles ||= ['Dodebuifile']
18
+ @original_dir = Dir.getwd
19
+ end
20
+
21
+ def dodebuifile?
22
+ @dodebuifiles.each do |fn|
23
+ return fn if File.exist?(fn)
24
+ end
25
+ nil
26
+ end
27
+
28
+ def find_dodebuifile_location # :nodoc:
29
+ here = Dir.pwd
30
+ until (fn = dodebuifile?)
31
+ Dir.chdir('..')
32
+ return nil if Dir.pwd == here
33
+ here = Dir.pwd
34
+ end
35
+ [fn, here]
36
+ ensure
37
+ Dir.chdir(@original_dir)
38
+ end
39
+
40
+ def load_dodebiufile
41
+ dodebuifile, location = find_dodebuifile_location
42
+ fail 'No Dodebuifile found' if dodebuifile.nil?
43
+ @dodebuifile = File.join(location, dodebuifile)
44
+ @wd = location
45
+ Cli.logger.info("Working directory #{@wd}")
46
+ Cli.logger.info("Config file #{@dodebuifile}")
47
+ load_dodebiufile_raw @dodebuifile
48
+ end
49
+
50
+ def load_dodebiufile_raw(path)
51
+ File.open(path, 'r') do |infile|
52
+ code = infile.read
53
+ eval(code) # rubocop:disable Lint/Eval
54
+ end
55
+ end
56
+
57
+ def run
58
+ Cli.logger.info("Initializing dodebui #{VERSION}")
59
+
60
+ load_dodebiufile
61
+
62
+ test_docker
63
+
64
+ prepare_distributions build_distributions
65
+
66
+ prepare_sources
67
+
68
+ build
69
+ end
70
+
71
+ def test_docker
72
+ Docker.options[:read_timeout] = 3600
73
+ data = Docker.version
74
+ Cli.logger.info(
75
+ "Connecting to Docker server successful (version #{data['Version']})"
76
+ )
77
+ end
78
+
79
+ def logger
80
+ Cli.logger
81
+ end
82
+
83
+ def prepare_distributions(distributions = [])
84
+ @distributions = distributions.map do |name|
85
+ Distribution.new(name, self)
86
+ end
87
+ ensure_images_updated
88
+ end
89
+
90
+ def ensure_images_updated
91
+ # ensure images are up to date
92
+ threads = []
93
+ @distributions.each do |dist|
94
+ threads << Thread.new do
95
+ dist.ensure_image_updated
96
+ end
97
+ end
98
+
99
+ # wait for all threads
100
+ threads.each(&:join)
101
+ end
102
+
103
+ def prepare_sources
104
+ @distributions.each do |dist|
105
+ dist.build.source
106
+ end
107
+ end
108
+
109
+ def build
110
+ threads = []
111
+ @distributions.each do |dist|
112
+ threads << Thread.new do
113
+ dist.build.build
114
+ end
115
+ end
116
+ # wait for all threads
117
+ threads.each(&:join)
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,173 @@
1
+ require 'date'
2
+ require 'docker'
3
+ require 'dodebui/build'
4
+ # docker debian build
5
+ module Dodebui
6
+ MAX_IMAGE_AGE = 86_400
7
+
8
+ DISTRIBUTIONS = {
9
+ debian: [
10
+ :squeeze,
11
+ :wheezy,
12
+ :jessie
13
+ ],
14
+ ubuntu: [
15
+ :precise,
16
+ :quantal,
17
+ :raring,
18
+ :saucy,
19
+ :trusty
20
+ ]
21
+ }
22
+
23
+ # handle distribution releases
24
+ class Distribution
25
+ attr_reader :os, :codename, :cli
26
+ def initialize(name, cli)
27
+ @cli = cli
28
+ # convert string
29
+ if name.is_a? String
30
+ split = name.split(':')
31
+ os = split[0].to_sym
32
+ codename = split[1].to_sym
33
+ end
34
+
35
+ if (!DISTRIBUTIONS.key? os) || (!DISTRIBUTIONS[os].include? codename)
36
+ fail "Operating system #{os} with codename #{codename} not found"
37
+ end
38
+ @os = os
39
+ @codename = codename
40
+ end
41
+
42
+ def logger
43
+ @cli.logger
44
+ end
45
+
46
+ def codename_str
47
+ format('%02d', codename_int)
48
+ end
49
+
50
+ def codename_int
51
+ DISTRIBUTIONS[os].index(codename) + 1
52
+ end
53
+
54
+ def image_age(i)
55
+ age = DateTime.now - DateTime.parse(i.info['Created'])
56
+ (age * 24 * 60 * 60).to_i
57
+ end
58
+
59
+ def ensure_image_updated
60
+ # Test if image_name exists
61
+ @image = Docker::Image.get(image_name)
62
+ if image_age(@image) > MAX_IMAGE_AGE
63
+ logger.info "Image #{image_name} is outdated renew it"
64
+ @image = create_image
65
+ end
66
+ rescue Docker::Error::NotFoundError
67
+ @image = create_image
68
+ end
69
+
70
+ def pbuilder_files
71
+ [
72
+ 'pbuilder-satisfydepends-aptitude',
73
+ 'pbuilder-satisfydepends-checkparams',
74
+ 'pbuilder-satisfydepends-funcs'
75
+ ]
76
+ end
77
+
78
+ def share_path
79
+ File.expand_path(
80
+ File.join(
81
+ File.expand_path(
82
+ File.dirname(__FILE__)
83
+ ),
84
+ '../../share'
85
+ )
86
+ )
87
+ end
88
+
89
+ def pbuilder_dir
90
+ '/usr/lib/pbuilder'
91
+ end
92
+
93
+ def create_image_dockerfile_contents
94
+ dockerfile = (
95
+ "FROM #{base_image_name}\n" \
96
+ "ENV DEBIAN_FRONTEND=noninteractive\n" \
97
+ "RUN apt-get update && \\ \n" \
98
+ " apt-get -y dist-upgrade && \\ \n" \
99
+ " apt-get -y install wget curl build-essential aptitude \n" \
100
+ "RUN mkdir -p #{pbuilder_dir}\n"
101
+ )
102
+
103
+ # add pbuilder dep resolver
104
+ pbuilder_files.each do |file|
105
+ dockerfile += "ADD #{file} #{pbuilder_dir}/#{file}\n"
106
+ end
107
+
108
+ # make dep resolver executable
109
+ dockerfile += 'RUN chmod +x '
110
+ dockerfile += "#{pbuilder_dir}/pbuilder-satisfydepends-aptitude\n"
111
+ dockerfile
112
+ end
113
+
114
+ def create_image_copy_dep_resolver(dir)
115
+ pbuilder_files.each do |file|
116
+ src = File.join(share_path, 'pbuilder', file)
117
+ dest = File.join(dir, file)
118
+ logger.debug("Copy file from #{src} to #{dest}")
119
+ FileUtils.cp src, dest
120
+ end
121
+ end
122
+
123
+ def create_image_build(dir)
124
+ image = Docker::Image.build_from_dir(
125
+ dir,
126
+ nocache: true
127
+ )
128
+
129
+ logger.info(
130
+ "Finished building a new image #{image_name} from #{base_image_name}"
131
+ )
132
+ image.tag(
133
+ repo: repo_name,
134
+ tag: @codename.to_s,
135
+ force: true
136
+ )
137
+ end
138
+
139
+ def create_image
140
+ logger.info("Start building a new image from #{base_image_name}")
141
+
142
+ # build docker build directory
143
+ Dir.mktmpdir do |dir|
144
+ # Write docker file
145
+ dockerfile_path = File.join(dir, 'Dockerfile')
146
+ File.open(dockerfile_path, 'w') do |file|
147
+ file.write(create_image_dockerfile_contents)
148
+ end
149
+
150
+ create_image_copy_dep_resolver(dir)
151
+
152
+ # build image
153
+ create_image_build(dir)
154
+ end
155
+ end
156
+
157
+ def build
158
+ @build ||= Build.new self
159
+ end
160
+
161
+ def repo_name
162
+ "dodebui_#{@os}"
163
+ end
164
+
165
+ def base_image_name
166
+ "#{@os}:#{@codename}"
167
+ end
168
+
169
+ def image_name
170
+ "#{repo_name}:#{@codename}"
171
+ end
172
+ end
173
+ end
@@ -0,0 +1,14 @@
1
+ module Dodebui
2
+ # namespace for evaluationg templates
3
+ class TemplateNamespace
4
+ def initialize(hash)
5
+ hash.each do |key, value|
6
+ singleton_class.send(:define_method, key) { value }
7
+ end
8
+ end
9
+
10
+ def priv_binding
11
+ binding
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,4 @@
1
+ # version of gem
2
+ module Dodebui
3
+ VERSION = '0.0.1'
4
+ end
data/lib/dodebui.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'dodebui/version'
2
+ # rubocop:disable Style/AvoidFor
3
+ module Dodebui
4
+ end
@@ -0,0 +1,121 @@
1
+ #!/bin/bash
2
+ # pbuilder -- personal Debian package builder
3
+ # Copyright (C) 2001,2002,2003,2005-2007 Junichi Uekawa
4
+ # Copyright (C) 2007 Loïc Minier
5
+ #
6
+ # This program is free software; you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation; either version 2 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this program; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
+ #
20
+ # module to satisfy build dependencies; aptitude flavor
21
+
22
+ set -e
23
+
24
+ export PBUILDER_PKGLIBDIR="${PBUILDER_PKGLIBDIR:-$PBUILDER_ROOT/usr/lib/pbuilder}"
25
+
26
+ . "$PBUILDER_PKGLIBDIR"/pbuilder-satisfydepends-funcs
27
+
28
+
29
+ # filter out dependencies sent on input not for this arch; deps can have
30
+ # multiple lines; output is on a single line or "" if empty
31
+ function filter_arch_deps() {
32
+ local arch="$1"
33
+ local INSTALLPKGMULTI
34
+ local INSTALLPKG
35
+
36
+ # split on ","
37
+ sed 's/[[:space:]]*,[[:space:]]*/\n/g' |
38
+ while read INSTALLPKGMULTI; do
39
+ echo "$INSTALLPKGMULTI" |
40
+ # split on "|"
41
+ sed 's/[[:space:]]*|[[:space:]]*/\n/g' |
42
+ while read INSTALLPKG; do
43
+ if echo "$INSTALLPKG" | grep -q '\['; then
44
+ if checkbuilddep_archdeps "$INSTALLPKG" "$ARCH"; then
45
+ continue
46
+ fi
47
+ fi
48
+ # output the selected package
49
+ echo "$INSTALLPKG"
50
+ done |
51
+ # remove the arch list and add " | " between entries
52
+ sed 's/\[.*\]//; $,$! s/$/ |/' |
53
+ xargs --no-run-if-empty
54
+ done |
55
+ # add ", " between entries
56
+ sed '$,$! s/$/,/' |
57
+ xargs --no-run-if-empty
58
+ }
59
+
60
+ function checkbuilddep_internal () {
61
+ # Use this function to fulfill the dependency (almost)
62
+ local ARCH=$($CHROOTEXEC dpkg-architecture -qDEB_HOST_ARCH)
63
+ local BUILD_DEP_DEB_DIR
64
+ local BUILD_DEP_DEB_CONTROL
65
+ local DEPENDS
66
+ local CONFLICTS
67
+ echo " -> Attempting to satisfy build-dependencies"
68
+ DEPENDS="$(get_build_deps | filter_arch_deps "$ARCH")"
69
+ CONFLICTS="$(get_build_conflicts | filter_arch_deps "$ARCH")"
70
+ echo " -> Creating pbuilder-satisfydepends-dummy package"
71
+ BUILD_DEP_DEB_DIR="/tmp/satisfydepends-aptitude"
72
+ BUILD_DEP_DEB_CONTROL="$BUILD_DEP_DEB_DIR/pbuilder-satisfydepends-dummy/DEBIAN/control"
73
+ $CHROOTEXEC mkdir -p "$BUILD_DEP_DEB_DIR/pbuilder-satisfydepends-dummy/DEBIAN/"
74
+ $CHROOTEXEC sh -c "cat >\"$BUILD_DEP_DEB_CONTROL\"" <<EOF
75
+ Package: pbuilder-satisfydepends-dummy
76
+ Version: 0.invalid.0
77
+ Architecture: $ARCH
78
+ Maintainer: Debian Pbuilder Team <pbuilder-maint@lists.alioth.debian.org>
79
+ Description: Dummy package to satisfy dependencies with aptitude - created by pbuilder
80
+ This package was created automatically by pbuilder to satisfy the
81
+ build-dependencies of the package being currently built.
82
+ EOF
83
+ if [ -n "$DEPENDS" ]; then
84
+ $CHROOTEXEC sh -c "echo \"Depends: $DEPENDS\" >>\"$BUILD_DEP_DEB_CONTROL\""
85
+ fi
86
+ if [ -n "$CONFLICTS" ]; then
87
+ $CHROOTEXEC sh -c "echo \"Conflicts: $CONFLICTS\" >>\"$BUILD_DEP_DEB_CONTROL\""
88
+ fi
89
+ $CHROOTEXEC sh -c "cat \"$BUILD_DEP_DEB_CONTROL\""
90
+ $CHROOTEXEC sh -c "dpkg-deb -b \"$BUILD_DEP_DEB_DIR/pbuilder-satisfydepends-dummy\""
91
+ $CHROOTEXEC dpkg -i "$BUILD_DEP_DEB_DIR/pbuilder-satisfydepends-dummy.deb" || true
92
+ $CHROOTEXEC aptitude -y --without-recommends -o APT::Install-Recommends=false "${PBUILDER_APTITUDE_CHECK_OPTS[@]}" -o Aptitude::ProblemResolver::StepScore=100 install pbuilder-satisfydepends-dummy
93
+ # check whether the aptitude's resolver kept the package
94
+ if ! $CHROOTEXEC dpkg -l pbuilder-satisfydepends-dummy 2>/dev/null | grep -q ^ii; then
95
+ echo "Aptitude couldn't satisfy the build dependencies"
96
+ exit 1
97
+ fi
98
+ echo " -> Finished parsing the build-deps"
99
+ }
100
+
101
+
102
+ function print_help () {
103
+ # print out help message
104
+ cat <<EOF
105
+ pbuilder-satisfydepends -- satisfy dependencies
106
+ Copyright 2002-2007 Junichi Uekawa <dancer@debian.org>
107
+
108
+ --help: give help
109
+ --control: specify control file (debian/control, *.dsc)
110
+ --chroot: operate inside chroot
111
+ --binary-all: include binary-all
112
+ --binary-arch: include binary-arch only
113
+ --echo: echo mode, do nothing. (--force-version required for most operation)
114
+ --force-version: skip version check.
115
+ --continue-fail: continue even when failed.
116
+
117
+ EOF
118
+ }
119
+
120
+ . "$PBUILDER_PKGLIBDIR"/pbuilder-satisfydepends-checkparams
121
+
@@ -0,0 +1,94 @@
1
+ #!/bin/bash
2
+ # pbuilder -- personal Debian package builder
3
+ # Copyright (C) 2001,2002,2003,2005-2007 Junichi Uekawa
4
+ #
5
+ # This program is free software; you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation; either version 2 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program; if not, write to the Free Software
17
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
+ #
19
+ # module to satisfy build dependencies; parse command line parameters
20
+
21
+
22
+ DEBIAN_CONTROL=debian/control
23
+ CHROOT=""
24
+ CHROOTEXEC=""
25
+ BINARY_ARCH="no"
26
+ FORCEVERSION=""
27
+ CONTINUE_FAIL="no"
28
+ CHROOTEXEC_AFTER_INTERNAL_CHROOTEXEC=no
29
+
30
+ # aptitude flag to ignore key verification
31
+ PBUILDER_APTITUDE_CHECK_OPTS=(
32
+ '-o'
33
+ 'Aptitude::CmdLine::Ignore-Trust-Violations=true' )
34
+ # apt flag to ignore key verification
35
+ PBUILDER_APT_GET_CHECK_OPTS="--force-yes"
36
+
37
+ while [ -n "$1" ]; do
38
+ case "$1" in
39
+ --control|-c)
40
+ DEBIAN_CONTROL="$2"
41
+ shift; shift
42
+ ;;
43
+
44
+ # --chroot option and --internal-chrootexec options and --echo options somewhat conflict with each other.
45
+
46
+ --chroot)
47
+ CHROOT="$2"
48
+ CHROOTEXEC="chroot $2 "
49
+ if [ ${CHROOTEXEC_AFTER_INTERNAL_CHROOTEXEC} = maybe ]; then
50
+ echo '--chroot specified after --internal-chrootexec' >&2
51
+ exit 1
52
+ fi
53
+ shift; shift
54
+ ;;
55
+ --internal-chrootexec)
56
+ CHROOTEXEC="$2"
57
+ CHROOTEXEC_AFTER_INTERNAL_CHROOTEXEC=maybe
58
+ shift; shift
59
+ ;;
60
+ --echo)
61
+ CHROOTEXEC="echo $CHROOTEXEC"
62
+ CHROOTEXEC_AFTER_INTERNAL_CHROOTEXEC=maybe
63
+ shift
64
+ ;;
65
+
66
+ --binary-all)
67
+ BINARY_ARCH="no"
68
+ shift
69
+ ;;
70
+ --binary-arch)
71
+ BINARY_ARCH="yes"
72
+ shift
73
+ ;;
74
+ --continue-fail)
75
+ CONTINUE_FAIL="yes"
76
+ shift
77
+ ;;
78
+ --force-version)
79
+ FORCEVERSION="yes"
80
+ shift;
81
+ ;;
82
+ --check-key)
83
+ unset PBUILDER_APTITUDE_CHECK_OPTS
84
+ unset PBUILDER_APT_GET_CHECK_OPTS
85
+ shift;
86
+ ;;
87
+ --help|-h|*)
88
+ print_help
89
+ exit 1
90
+ ;;
91
+ esac
92
+ done
93
+
94
+ checkbuilddep_internal
@@ -0,0 +1,206 @@
1
+ #!/bin/bash
2
+ # pbuilder -- personal Debian package builder
3
+ # Copyright (C) 2001,2002,2003,2005-2007 Junichi Uekawa
4
+ # Copyright (C) 2007 Loïc Minier
5
+ #
6
+ # This program is free software; you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation; either version 2 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this program; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
+ #
20
+ # module to satisfy build dependencies; common functions
21
+
22
+
23
+ package_versions() {
24
+ local PACKAGE="$1"
25
+ LC_ALL=C $CHROOTEXEC /usr/bin/apt-cache show "$PACKAGE" | sed -n 's/^Version: //p'
26
+ }
27
+
28
+ candidate_version() {
29
+ local PACKAGE="$1"
30
+ LC_ALL=C $CHROOTEXEC apt-cache policy "$PACKAGE" | sed -n 's/ *Candidate: //p'
31
+ }
32
+
33
+ checkbuilddep_versiondeps() {
34
+ local PACKAGE="$1"
35
+ local COMPARESTRING="$2"
36
+ local DEPSVERSION="$3"
37
+ local PACKAGEVERSIONS=$( package_versions "$PACKAGE" | xargs)
38
+ # no versioned provides.
39
+ if [ "${FORCEVERSION}" = "yes" ]; then
40
+ return 0;
41
+ fi
42
+ for PACKAGEVERSION in $PACKAGEVERSIONS ; do
43
+ if dpkg --compare-versions "$PACKAGEVERSION" "$COMPARESTRING" "$DEPSVERSION"; then
44
+ # satisfies depends
45
+ return 0;
46
+ fi
47
+ done
48
+ echo " Tried versions: $PACKAGEVERSIONS"
49
+ # cannot satisfy depends
50
+ return 1;
51
+ }
52
+
53
+ get_source_control_field() {
54
+ local field="$1"
55
+
56
+ sed -n -e "s/^$field://i" -e '
57
+ t store
58
+ /^-----BEGIN PGP SIGNED MESSAGE-----$/ {
59
+ : pgploop
60
+ n
61
+ /^$/ d
62
+ b pgploop
63
+ }
64
+ /^$/q
65
+ d
66
+ : store
67
+ H
68
+ : loop
69
+ n
70
+ /^#/ b loop
71
+ /^[ \t]/ b store
72
+ x
73
+ # output on single line
74
+ s/\n//g
75
+ # change series of tabs and spaces into a space
76
+ s/[\t ]\+/ /g
77
+ # normalize space before and after commas
78
+ s/ *, */, /g
79
+ # normalize space before and after pipes
80
+ s/ *| */ | /g
81
+ # normalize space before and after parentheses
82
+ s/ *( */ (/g
83
+ s/ *) */)/g
84
+ # normalize space before and after brackets
85
+ s/ *\[ */ [/g
86
+ s/ *\] */]/g
87
+ # normalize space after exclamation mark
88
+ s/! */!/g
89
+ # normalize space between operator and version
90
+ s/(\(>>\|>=\|>\|==\|=\|<=\|<<\|<\|!=\) *\([^)]*\))/(\1 \2)/g
91
+ # normalize space at beginning and end of line
92
+ s/^ *//
93
+ s/ *$//
94
+ p' \
95
+ "$DEBIAN_CONTROL"
96
+ }
97
+
98
+ get_build_deps() {
99
+ local output
100
+
101
+ output="`get_source_control_field "Build-Depends"`"
102
+ output="${output%, }"
103
+ if [ "$BINARY_ARCH" = no ]; then
104
+ output="${output:+$output, }`get_source_control_field "Build-Depends-Indep"`"
105
+ output="${output%, }"
106
+ fi
107
+ echo "$output"
108
+ }
109
+
110
+ get_build_conflicts() {
111
+ local output
112
+
113
+ output="`get_source_control_field "Build-Conflicts"`"
114
+ if [ "$BINARY_ARCH" = no ]; then
115
+ output="${output:+$output, }`get_source_control_field "Build-Conflicts-Indep"`"
116
+ fi
117
+ echo "$output"
118
+ }
119
+
120
+ checkbuilddep_archdeps() {
121
+ # returns FALSE on INSTALL
122
+ local INSTALLPKG="$1"
123
+ local ARCH="$2"
124
+ # architectures listed between [ and ] for this dep
125
+ local DEP_ARCHES="$(echo "$INSTALLPKG" | sed 's/.*\[\(.*\)\].*/\1/')"
126
+ # check for !$ARCH in DEP_ARCHES
127
+ if echo "$DEP_ARCHES" | egrep -q "(^|[[:space:]/]+)\![[:space:]/]*$ARCH($|[[:space:]/]+)"; then
128
+ return 0;
129
+ fi
130
+ # check for a "!" which would mean there's a !<otherarch> and hence $ARCH
131
+ # is included
132
+ if ! echo "$DEP_ARCHES" | grep -q '!'; then
133
+ # check for $ARCH in DEP_ARCHES
134
+ if ! echo "$DEP_ARCHES" | egrep -q "(^|[[:space:]/]+)$ARCH($|[[:space:]/]+)"; then
135
+ return 0;
136
+ fi
137
+ fi
138
+ return 1;
139
+ }
140
+
141
+ checkbuilddep_provides() {
142
+ local PACKAGENAME="$1"
143
+ # PROVIDED needs to be used outside of this function.
144
+ PROVIDED=$($CHROOTEXEC /usr/bin/apt-cache showpkg $PACKAGENAME | awk '{p=0}/^Reverse Provides:/,/^$/{p=1}{if(p && ($0 !~ "Reverse Provides:")){PACKAGE=$1}} END{print PACKAGE}')
145
+ }
146
+
147
+ # returns either "package=version", to append to an apt-get install line, or
148
+ # package
149
+ versioneddep_to_aptcmd() {
150
+ local INSTALLPKG="$1"
151
+
152
+ local PACKAGE
153
+ local PACKAGE_WITHVERSION
154
+ local PACKAGEVERSIONS
155
+ local CANDIDATE_VERSION
156
+ local COMPARESTRING
157
+ local DEPSVERSION
158
+
159
+ PACKAGE="$(echo "$INSTALLPKG" | sed -e 's/^[/]*//' -e 's/[[/(].*//')"
160
+ PACKAGE_WITHVERSION="$PACKAGE"
161
+
162
+ # if not versionned, we skip directly to outputting $PACKAGE
163
+ if echo "$INSTALLPKG" | grep '[(]' > /dev/null; then
164
+ # package versions returned by APT, in reversed order
165
+ PACKAGEVERSIONS="$( package_versions "$PACKAGE" | tac | xargs )"
166
+ CANDIDATE_VERSION="$( candidate_version "$PACKAGE" )"
167
+
168
+ COMPARESTRING="$(echo "$INSTALLPKG" | tr "/" " " | sed 's/^.*( *\(<<\|<=\|>=\|=\|<\|>>\|>\) *\(.*\)).*$/\1/')"
169
+ DEPSVERSION="$(echo "$INSTALLPKG" | tr "/" " " | sed 's/^.*( *\(<<\|<=\|>=\|=\|<\|>>\|>\) *\(.*\)).*$/\2/')"
170
+ # if strictly versionned, we skip to outputting that version
171
+ if [ "=" = "$COMPARESTRING" ]; then
172
+ PACKAGE_WITHVERSION="$PACKAGE=$DEPSVERSION"
173
+ else
174
+ # try the candidate version, then all available versions (asc)
175
+ for VERSION in $CANDIDATE_VERSION $PACKAGEVERSIONS; do
176
+ if dpkg --compare-versions "$VERSION" "$COMPARESTRING" "$DEPSVERSION"; then
177
+ if [ $VERSION != $CANDIDATE_VERSION ]; then
178
+ PACKAGE_WITHVERSION="$PACKAGE=$VERSION"
179
+ fi
180
+ break;
181
+ fi
182
+ done
183
+ fi
184
+ fi
185
+
186
+ echo "$PACKAGE_WITHVERSION"
187
+ }
188
+
189
+ print_help() {
190
+ # print out help message
191
+ cat <<EOF
192
+ pbuilder-satisfydepends -- satisfy dependencies
193
+ Copyright 2002-2007 Junichi Uekawa <dancer@debian.org>
194
+
195
+ --help: give help
196
+ --control: specify control file (debian/control, *.dsc)
197
+ --chroot: operate inside chroot
198
+ --binary-all: include binary-all
199
+ --binary-arch: include binary-arch only
200
+ --echo: echo mode, do nothing. (--force-version required for most operation)
201
+ --force-version: skip version check.
202
+ --continue-fail: continue even when failed.
203
+
204
+ EOF
205
+ }
206
+
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dodebui
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Christian Simon
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-08 00:00:00.000000000 Z
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'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0.30'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '0.30'
69
+ description: 'Docker Debian builder (DoDeBui): Builds debian packages in Docker containers'
70
+ email:
71
+ - simon@swine.de
72
+ executables:
73
+ - dodebui
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - .rubocop.yml
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/dodebui
84
+ - dodebui.gemspec
85
+ - lib/dodebui.rb
86
+ - lib/dodebui/build.rb
87
+ - lib/dodebui/cli.rb
88
+ - lib/dodebui/distribution.rb
89
+ - lib/dodebui/template_namespace.rb
90
+ - lib/dodebui/version.rb
91
+ - share/pbuilder/pbuilder-satisfydepends-aptitude
92
+ - share/pbuilder/pbuilder-satisfydepends-checkparams
93
+ - share/pbuilder/pbuilder-satisfydepends-funcs
94
+ homepage: https://github.com/simonswine/dodebui
95
+ licenses:
96
+ - GPLv3
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.4.3
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: 'Docker Debian builder (DoDeBui): Builds debian packages in Docker containers'
118
+ test_files: []