fpm-cookery 0.34.0 → 0.35.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: 3086c69abf17303cb1bd39d5745435e2166e28a7
4
- data.tar.gz: 4200c639a242f38313db74b31eb8231e749ea864
3
+ metadata.gz: 3a561efdfc9652a27acb7f35a433d93cd063bfb0
4
+ data.tar.gz: 5a20b744b3b77ea485c29553316938b3ada4982d
5
5
  SHA512:
6
- metadata.gz: 0d85461efb89f476da92433f2394a6db4ecbfc09258018cdc7a4b4151118d663a2c52c19540ae006ad1b548bb6f2ca946fa90bc44f1e6d3e80fa50a31532e805
7
- data.tar.gz: f8550d9d07dfddaa4dd74d46f62294a66d35186c49fea36c95da77f7431870d25b8c3f8f93bee0da1cd87512b12ec7906b4abad7493bed1edd3297c9660f5cad
6
+ metadata.gz: 14313ecb17e285a764f981fbd67fb60b136183999df07cb1eaf2b6c76cefc310f80d4952a9e191c854bbd9ddfca5a51d634c983285f80ef4688db342a987396a
7
+ data.tar.gz: fa98c581f573b84022e03be9bffff9b92e92e964eb7b2508e9c49eb0e0ef238006775ee5a7778e86a26f037170df8745eb156b2ce10b5d296ddc71851fe98fcf
@@ -0,0 +1,23 @@
1
+ name: Ruby
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ build:
7
+
8
+ runs-on: ubuntu-latest
9
+ strategy:
10
+ matrix:
11
+ ruby: [2.4, 2.5, 2.6]
12
+
13
+ steps:
14
+ - uses: actions/checkout@v1
15
+ - name: Set up Ruby ${{ matrix.ruby }}
16
+ uses: actions/setup-ruby@v1
17
+ with:
18
+ ruby-version: ${{ matrix.ruby }}.x
19
+ - name: Build and test with Rake
20
+ run: |
21
+ gem install bundler
22
+ bundle install --jobs 4 --retry 3
23
+ bundle exec rake
@@ -1,3 +1,6 @@
1
+ # v0.35.0 (2019-12-18)
2
+ * Add support for building packages inside Docker containers.
3
+
1
4
  # v0.34.0 (2019-06-01)
2
5
  * Use factor defaults for `platform` and `target` values. (FooBarQuaxx / #189)
3
6
  * Add `:username` and `:password` parameters to the SVN source handler. (tomeon / #191)
@@ -0,0 +1,27 @@
1
+ FROM ubuntu:16.04
2
+
3
+ RUN apt-get update
4
+ RUN \
5
+ apt-get install --no-install-recommends -y \
6
+ curl \
7
+ wget \
8
+ git \
9
+ ruby2.3-dev \
10
+ build-essential \
11
+ man-db \
12
+ && gem install --no-ri --no-rdoc fpm-cookery \
13
+ && apt-get clean \
14
+ && rm -rf \
15
+ /tmp/* \
16
+ /root/.gem \
17
+ /var/cache/debconf/* \
18
+ /var/lib/gems/*/cache/* \
19
+ /var/lib/apt/lists/* \
20
+ /var/log/* \
21
+ /usr/share/X11 \
22
+ /usr/share/doc/*
23
+
24
+ COPY docker-entrypoint.sh /
25
+
26
+ ENTRYPOINT ["/docker-entrypoint.sh"]
27
+ CMD ["fpm-cook"]
@@ -0,0 +1,38 @@
1
+ #!/bin/bash
2
+
3
+ set -eo pipefail
4
+
5
+ if [ "$1" != "fpm-cook" ]; then
6
+ exec "$@"
7
+ fi
8
+
9
+ # Signal fpm-cook that we are already running inside a container to avoid
10
+ # trying to start another one.
11
+ export FPMC_INSIDE_DOCKER=true
12
+
13
+ if [ -x "/usr/bin/apt-get" ]; then
14
+ # Ubuntu/Debian containers use a custom apt config to remove archives
15
+ # after installing a package. We don't want that because it removes
16
+ # the possibility to cache the apt archive directory.
17
+ rm -f /etc/apt/apt.conf.d/docker-clean
18
+
19
+ # Make sure we have updated apt repositories. Container images usually
20
+ # have either no updated lists or they are outdated.
21
+ if [ -n "$FPMC_DEBUG" ]; then
22
+ apt-get update
23
+ else
24
+ apt-get update >/dev/null
25
+ fi
26
+ fi
27
+
28
+ # Remove existing temporary directories to ensure a full build
29
+ rm -rf tmp-build tmp-dest
30
+
31
+ shift
32
+ fpm-cook "$@"
33
+
34
+ if [ -n "$FPMC_UID" -a -n "$FPMC_GID" ]; then
35
+ # Change ownership to make sure the user that executed fpm-cook can
36
+ # modify created files.
37
+ chown -R ${FPMC_UID}:${FPMC_GID} cache pkg tmp-build tmp-dest
38
+ fi
@@ -2,6 +2,7 @@ require 'fpm/cookery/book_hook'
2
2
  require 'fpm/cookery/recipe'
3
3
  require 'fpm/cookery/facts'
4
4
  require 'fpm/cookery/packager'
5
+ require 'fpm/cookery/docker_packager'
5
6
  require 'fpm/cookery/chain_packager'
6
7
  require 'fpm/cookery/omnibus_packager'
7
8
  require 'fpm/cookery/log'
@@ -36,6 +37,20 @@ module FPM
36
37
  option '--vendor-delimiter', 'DELIMITER', 'vendor delimiter for version string',
37
38
  :attribute_name => 'vendor_delimiter'
38
39
 
40
+ # Docker related flags
41
+ option '--docker', :flag, 'Execute fpm-cookery inside a Docker container',
42
+ :attribute_name => 'docker'
43
+ option '--docker-bin', 'BINARY', 'Docker binary to use',
44
+ :attribute_name => 'docker_bin'
45
+ option '--docker-image', 'IMAGE-NAME', 'Docker image to use',
46
+ :attribute_name => 'docker_image'
47
+ option '--docker-keep-container', :flag, 'Keep Docker container after build (e.g. to debug issues)',
48
+ :attribute_name => 'docker_keep_container'
49
+ option '--docker-cache', 'PATHS', 'Container paths to cache (can be a comma separated list)',
50
+ :attribute_name => 'docker_cache'
51
+ option '--dockerfile', 'PATHS', 'The Dockerfile to use for a custom container',
52
+ :attribute_name => 'dockerfile'
53
+
39
54
  class Command < self
40
55
  def self.add_recipe_parameter!
41
56
  parameter '[RECIPE]', 'the recipe file', :default => 'recipe.rb'
@@ -116,7 +131,10 @@ module FPM
116
131
  add_recipe_parameter!
117
132
 
118
133
  def exec(config, recipe, packager)
119
- if recipe.omnibus_package == true
134
+ # Don't try to launch a new container if we are already running inside one
135
+ if (config.docker == true or recipe.docker == true) and ENV['FPMC_INSIDE_DOCKER'].nil?
136
+ FPM::Cookery::DockerPackager.new(recipe, config).run
137
+ elsif recipe.omnibus_package == true
120
138
  FPM::Cookery::OmnibusPackager.new(packager, config).run
121
139
  elsif recipe.chain_package == true
122
140
  FPM::Cookery::ChainPackager.new(packager, config).run
@@ -146,7 +164,9 @@ module FPM
146
164
  add_recipe_parameter!
147
165
 
148
166
  def exec(config, recipe, packager)
149
- if recipe.omnibus_package == true
167
+ if config.docker == true
168
+ # Nothing to do!
169
+ elsif recipe.omnibus_package == true
150
170
  FPM::Cookery::OmnibusPackager.new(packager, config).install_build_deps
151
171
  elsif recipe.chain_package == true
152
172
  FPM::Cookery::ChainPackager.new(packager, config).install_build_deps
@@ -8,7 +8,8 @@ module FPM
8
8
  :color, :debug, :target, :platform, :maintainer, :vendor,
9
9
  :skip_package, :keep_destdir, :dependency_check, :quiet,
10
10
  :tmp_root, :pkg_dir, :cache_dir, :data_dir, :hiera_config,
11
- :vendor_delimiter
11
+ :vendor_delimiter, :docker, :docker_image, :docker_keep_container,
12
+ :docker_cache, :docker_bin, :dockerfile
12
13
  ].freeze
13
14
 
14
15
  DEFAULTS = {
@@ -17,7 +18,13 @@ module FPM
17
18
  :dependency_check => true,
18
19
  :skip_package => false,
19
20
  :keep_destdir => false,
20
- :quiet => false
21
+ :quiet => false,
22
+ :docker => false,
23
+ :docker_image => nil,
24
+ :docker_keep_container => false,
25
+ :docker_cache => nil,
26
+ :docker_bin => 'docker',
27
+ :dockerfile => 'Dockerfile'
21
28
  }.freeze
22
29
 
23
30
  def self.load_file(paths)
@@ -0,0 +1,109 @@
1
+ require 'digest/sha1'
2
+ require 'fileutils'
3
+ require 'pathname'
4
+
5
+ require 'fpm/cookery/version'
6
+ require 'fpm/cookery/facts'
7
+ require 'fpm/cookery/packager'
8
+ require 'fpm/cookery/exceptions'
9
+
10
+ # Runs the package creation inside a Docker container.
11
+ module FPM
12
+ module Cookery
13
+ class DockerPackager
14
+ include FPM::Cookery::Utils
15
+
16
+ attr_reader :packager, :recipe, :config
17
+
18
+ def initialize(recipe, config)
19
+ @recipe = recipe
20
+ @config = config
21
+ end
22
+
23
+ def run
24
+ recipe_dir = File.dirname(recipe.filename)
25
+
26
+ # The cli settings should have precendence
27
+ image_name = config.docker_image || recipe.docker_image
28
+ cache_paths = get_cache_paths
29
+ docker_bin = config.docker_bin.nil? || config.docker_bin.empty? ? 'docker' : config.docker_bin
30
+ dockerfile = get_dockerfile(recipe_dir)
31
+
32
+ if File.exist?(dockerfile)
33
+ image_name = "local/fpm-cookery/#{File.basename(recipe_dir)}:latest"
34
+ Log.info "Building custom Docker image #{image_name} from #{dockerfile}"
35
+ build_cmd = [
36
+ config.docker_bin, 'build',
37
+ '-f', dockerfile,
38
+ '-t', image_name,
39
+ '--force-rm',
40
+ '.'
41
+ ].compact.flatten.join(' ')
42
+ sh build_cmd
43
+ else
44
+ Log.warn "File #{dockerfile} does not exist - not building a custom Docker image"
45
+ end
46
+
47
+ if image_name.nil? || image_name.empty?
48
+ image_name = "fpm-cookery:#{FPM::Cookery::VERSION}-#{FPM::Cookery::Facts.platform}-#{FPM::Cookery::Facts.osrelease}"
49
+ end
50
+
51
+ Log.info "Building #{recipe.name}-#{recipe.version} inside a Docker container using image #{image_name}"
52
+ Log.info "Mounting #{recipe_dir} as /recipe"
53
+
54
+ cmd = [
55
+ config.docker_bin, "run", "-ti",
56
+ "--name", "fpm-cookery-build-#{File.basename(recipe_dir)}",
57
+ config.docker_keep_container ? nil : "--rm",
58
+ "-e", "FPMC_UID=#{Process.uid}",
59
+ "-e", "FPMC_GID=#{Process.gid}",
60
+ config.debug ? ["-e", "FPMC_DEBUG=true"] : nil,
61
+ build_cache_mounts(cache_paths),
62
+ "-v", "#{recipe_dir}:/recipe",
63
+ "-w", "/recipe",
64
+ image_name,
65
+ "fpm-cook", "package",
66
+ config.debug ? '-D' : nil,
67
+ File.basename(recipe.filename)
68
+ ].compact.flatten.join(' ')
69
+
70
+
71
+ Log.info "Running: #{cmd}"
72
+ begin
73
+ sh cmd
74
+ rescue => e
75
+ Log.debug e
76
+ end
77
+ end
78
+
79
+ private
80
+
81
+ def get_dockerfile(recipe_dir)
82
+ path = if config.dockerfile.nil? || config.dockerfile.empty?
83
+ Pathname.new(recipe.dockerfile)
84
+ else
85
+ Pathname.new(config.dockerfile)
86
+ end
87
+
88
+ path.absolute? ? path.to_s : File.join(recipe_dir, path.to_s)
89
+ end
90
+
91
+ def get_cache_paths
92
+ if config.docker_cache.nil? || config.docker_cache.empty?
93
+ recipe.docker_cache
94
+ else
95
+ config.docker_cache.split(',').select do |path|
96
+ !path.empty?
97
+ end
98
+ end
99
+ end
100
+
101
+ def build_cache_mounts(cache_paths)
102
+ cache_paths.map do |path|
103
+ next if path.nil? || path.empty?
104
+ "-v #{recipe.cachedir}/docker/#{Digest::SHA256.hexdigest(path)}:#{path}"
105
+ end
106
+ end
107
+ end
108
+ end
109
+ end
@@ -21,7 +21,7 @@ module FPM
21
21
  end
22
22
 
23
23
  def lsbcodename
24
- @lsbcodename ||= value(:lsbcodename)
24
+ @lsbcodename ||= value(:lsbcodename) || value(:lsbdistcodename)
25
25
  end
26
26
 
27
27
  def osmajorrelease
@@ -34,12 +34,12 @@ module FPM
34
34
  :revision, :section, :sha1, :sha256, :sha512, :spec, :vendor, :version,
35
35
  :pre_install, :post_install, :pre_uninstall, :post_uninstall,
36
36
  :license, :omnibus_package, :omnibus_dir, :chain_package,
37
- :default_prefix
37
+ :default_prefix, :docker, :docker_image, :dockerfile
38
38
 
39
39
  attr_rw_list :build_depends, :config_files, :conflicts, :depends,
40
40
  :exclude, :patches, :provides, :replaces, :omnibus_recipes,
41
41
  :omnibus_additional_paths, :chain_recipes,
42
- :directories
42
+ :directories, :docker_cache
43
43
 
44
44
  attr_rw_hash :fpm_attributes, :environment
45
45
 
@@ -1,5 +1,5 @@
1
1
  module FPM
2
2
  module Cookery
3
- VERSION = '0.34.0'
3
+ VERSION = '0.35.0'
4
4
  end
5
5
  end
@@ -165,7 +165,13 @@ describe 'Config' do
165
165
  :skip_package => false,
166
166
  :keep_destdir => false,
167
167
  :dependency_check => true,
168
- :quiet => false
168
+ :quiet => false,
169
+ :docker => false,
170
+ :docker_image => nil,
171
+ :docker_keep_container => false,
172
+ :docker_cache => nil,
173
+ :docker_bin => 'docker',
174
+ :dockerfile => 'Dockerfile'
169
175
  })
170
176
  end
171
177
  end
@@ -31,11 +31,11 @@ describe "Facts" do
31
31
  end
32
32
  end
33
33
 
34
- context "where lsbcodename is not present" do
35
- include_context "mock facts", { :lsbcodename => nil }
34
+ context "where lsbcodename is not present but lsbdistcodename is" do
35
+ include_context "mock facts", { :lsbcodename => nil, :lsbdistcodename => 'trusty' }
36
36
 
37
37
  it "returns nil" do
38
- expect(FPM::Cookery::Facts.lsbcodename).to be_nil
38
+ expect(FPM::Cookery::Facts.lsbcodename).to eq :trusty
39
39
  end
40
40
  end
41
41
  end
@@ -99,6 +99,24 @@ describe "Recipe" do
99
99
  end
100
100
  end
101
101
 
102
+ describe "#docker" do
103
+ it "can be set" do
104
+ check_attribute(:docker, true)
105
+ end
106
+ end
107
+
108
+ describe "#docker_image" do
109
+ it "can be set" do
110
+ check_attribute(:docker_image, "hello:world")
111
+ end
112
+ end
113
+
114
+ describe "#dockerfile" do
115
+ it "can be set" do
116
+ check_attribute(:dockerfile, "Dockefile")
117
+ end
118
+ end
119
+
102
120
  describe "#license" do
103
121
  it "can be set" do
104
122
  check_attribute(:license, 'MIT')
@@ -305,6 +323,7 @@ describe "Recipe" do
305
323
  spec_recipe_attribute_list(:omnibus_recipes, %w{one two})
306
324
  spec_recipe_attribute_list(:chain_recipes, %w{one two})
307
325
  spec_recipe_attribute_list(:directories, %w{one two})
326
+ spec_recipe_attribute_list(:docker_cache, %w{one two})
308
327
 
309
328
  describe ".source" do
310
329
  it "sets a source url" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fpm-cookery
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.34.0
4
+ version: 0.35.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bernd Ahlers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-01 00:00:00.000000000 Z
11
+ date: 2019-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -204,6 +204,7 @@ executables:
204
204
  extensions: []
205
205
  extra_rdoc_files: []
206
206
  files:
207
+ - ".github/workflows/ruby.yml"
207
208
  - ".gitignore"
208
209
  - ".travis.yml"
209
210
  - CHANGELOG.md
@@ -212,6 +213,8 @@ files:
212
213
  - README.md
213
214
  - Rakefile
214
215
  - bin/fpm-cook
216
+ - docker/Dockerfile.ubuntu-1604
217
+ - docker/docker-entrypoint.sh
215
218
  - docs/.gitignore
216
219
  - docs/Makefile
217
220
  - docs/conf.py
@@ -225,6 +228,7 @@ files:
225
228
  - lib/fpm/cookery/cli.rb
226
229
  - lib/fpm/cookery/config.rb
227
230
  - lib/fpm/cookery/dependency_inspector.rb
231
+ - lib/fpm/cookery/docker_packager.rb
228
232
  - lib/fpm/cookery/environment.rb
229
233
  - lib/fpm/cookery/exceptions.rb
230
234
  - lib/fpm/cookery/facts.rb