Skip to content

Commit

Permalink
Merge pull request #12 from skaes/assorted-enhancements
Browse files Browse the repository at this point in the history
Assorted enhancements
  • Loading branch information
hannesg committed Jun 3, 2016
2 parents 2ebb719 + e6cc599 commit c60a7d9
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 7 deletions.
21 changes: 15 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ PATH
fpm-fry (0.2.1)
excon (~> 0.30)
fpm (~> 1.0)
json (~> 1.8)

GEM
remote: https://rubygems.org/
Expand All @@ -16,8 +17,7 @@ GEM
cabin (0.8.1)
childprocess (0.5.9)
ffi (~> 1.0, >= 1.0.11)
clamp (0.6.5)
corefines (1.9.0)
clamp (1.0.0)
coveralls (0.8.13)
json (~> 1.8)
simplecov (~> 0.11.0)
Expand All @@ -30,20 +30,28 @@ GEM
docile (1.1.5)
excon (0.49.0)
ffi (1.9.10)
fpm (1.5.0)
fpm (1.6.0)
archive-tar-minitar
arr-pm (~> 0.0.10)
backports (>= 2.6.2)
cabin (>= 0.6.0)
childprocess
clamp (~> 0.6)
corefines (~> 1.9)
clamp (~> 1.0.0)
ffi
json (>= 1.7.7)
pleaserun (~> 0.0.24)
ruby-xz
hashdiff (0.3.0)
insist (1.0.0)
io-like (0.3.0)
json (1.8.3)
mustache (0.99.8)
pleaserun (0.0.24)
cabin (> 0)
clamp
insist
mustache (= 0.99.8)
stud
rspec (3.4.0)
rspec-core (~> 3.4.0)
rspec-expectations (~> 3.4.0)
Expand All @@ -66,6 +74,7 @@ GEM
json (~> 1.8)
simplecov-html (~> 0.10.0)
simplecov-html (0.10.0)
stud (0.0.22)
term-ansicolor (1.3.2)
tins (~> 1.0)
thor (0.19.1)
Expand All @@ -86,4 +95,4 @@ DEPENDENCIES
webmock

BUNDLED WITH
1.11.2
1.12.4
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,26 @@ end
Scripts running inside `before_install` modify the base image instead of the package. This is the ideal place to install build dependencies that are not linux packages ( gems, jars, eggs, ... ).
- `add` mount a file or directoy from the build environment into the build container (corresponds to ADD directive in a Dockerfile)
```ruby
add "images/code/install-code.sh", ".install-code.sh"
```
Mounts are added before any other build command runs in the build container.
- `apt_setup` run a command before any generated `apt-get install` or `apt-get update` is run inside the build container.
```ruby
apt_setup "echo 'deb [trusted=yes] http://somedomain/packages/#{distribution}/#{codename} ./' >> /etc/apt/sources.list"
"
```

Allows one to add custom apt repositories befor installing in package.


### Target info

- `flavour`: Returns the linux family like "redhat" or "debian"
Expand Down
1 change: 1 addition & 0 deletions bin/fpm-fry
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require "rubygems"
$: << File.expand_path(File.join( "..", "lib"),File.dirname(__FILE__))
require "json"
require "fpm"
require "fpm/command"
require "fpm/package/docker"
Expand Down
1 change: 1 addition & 0 deletions fpm-fry.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ Gem::Specification.new do |gem|

gem.add_dependency 'excon', '~> 0.30'
gem.add_dependency 'fpm', '~> 1.0'
gem.add_dependency 'json', '~> 1.8'

end
2 changes: 1 addition & 1 deletion lib/fpm/fry/command/cook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def build!
)
json = JSON.parse(res.body)
if json["StatusCode"] != 0
raise "Build failed with exit code #{json["StatusCode"]}"
raise "Build failed: #{json.inspect}"
end
return yield container
ensure
Expand Down
14 changes: 14 additions & 0 deletions lib/fpm/fry/docker_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ def dockerfile
df << "FROM #{base}"
df << "WORKDIR /tmp/build"

# need to add external sources before running any command
recipe.build_mounts.each do |source, target|
df << "ADD #{source} /tmp/build/#{target}"
end

recipe.apt_setup.each do |step|
df << "RUN #{step}"
end

if build_dependencies.any?
case(variables[:flavour])
when 'debian'
Expand Down Expand Up @@ -137,6 +146,11 @@ def tar_io
tar.add_file(NAME,'0777') do |io|
io.write(dockerfile)
end
recipe.build_mounts.each do |source, _|
tar.add_file(source,'0777') do |io|
io.write(File.read(source))
end
end
#tar.close
sio.rewind
return sio
Expand Down
4 changes: 4 additions & 0 deletions lib/fpm/fry/recipe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ def lint
end

attr_accessor :source,
:build_mounts,
:apt_setup,
:before_build_steps,
:steps,
:packages,
Expand All @@ -139,6 +141,8 @@ def initialize
@packages[0].files << '**'
@build_depends = {}
@input_hooks = []
@build_mounts = []
@apt_setup = []
end

def depends
Expand Down
8 changes: 8 additions & 0 deletions lib/fpm/fry/recipe/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,14 @@ def source( url , options = {} )
recipe.source = source
end

def add(source, target)
recipe.build_mounts << [source, target]
end

def apt_setup(cmd)
recipe.apt_setup << cmd
end

def run(*args)
if args.first.kind_of? Hash
options = args.shift
Expand Down
8 changes: 8 additions & 0 deletions lib/fpm/fry/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ def initialize(e, opts = {})
super(e.to_s)
end
end

def message
super + options.inspect
end

def to_s
super + options.inspect
end
end

module Null
Expand Down

0 comments on commit c60a7d9

Please sign in to comment.