fpm-dockery 0.1.0
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 +7 -0
- data/.gitignore +10 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +147 -0
- data/Rakefile +2 -0
- data/bin/fpm-dockery +7 -0
- data/docker/Dockerfile.ubuntu12.04 +25 -0
- data/docker/Dockerfile.ubuntu14.04 +25 -0
- data/example_recipe/recipe.rb +48 -0
- data/example_recipe/redis-server.init.d +80 -0
- data/fpm-dockery.gemspec +26 -0
- data/lib/fpm/dockery.rb +16 -0
- data/lib/fpm/dockery/cli.rb +108 -0
- data/lib/fpm/dockery/logging.rb +24 -0
- data/lib/fpm/dockery/utils.rb +36 -0
- data/lib/fpm/dockery/version.rb +5 -0
- metadata +105 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c935a1fef8fa2087d31346840b6485bc572ec539
|
4
|
+
data.tar.gz: 9d200efd489fd6d69d29ecdf16d15eed9ed9e929
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9ba023b1e3175338547cb678b8b7601d6d2fccb59c50fa942d7d01de325ca78a7d07b8d53aee03ac445edf3ee3cc1b427870a8300152d8c9a556eecab5518081
|
7
|
+
data.tar.gz: f6084650e84dc08246ada4911a3b1f22c2ac86e2ab869ae74474a75137212f5e5d244ddd3b3c400b302209548ce18e2b83f819a590bbfa5b9404e8940862944b
|
data/.gitignore
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
fpm-dockery
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.5
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Andy Sykes
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
# fpm-dockery
|
2
|
+
|
3
|
+
Build [fpm-cookery](https://github.com/forward3d/fpm-cookery) recipes with Docker!
|
4
|
+
|
5
|
+
## What is this?
|
6
|
+
|
7
|
+
This is a terribly-named wrapper around [fpm-cookery](https://github.com/forward3d/fpm-cookery)
|
8
|
+
that allows you to run fpm-cookery builds inside a container. I wrote this to allow me to run package builds
|
9
|
+
in development on my laptop in the same way that Jenkins runs them, and to allow easy building of packages
|
10
|
+
for a variety of Linux distributions.
|
11
|
+
|
12
|
+
## Why would you use this?
|
13
|
+
|
14
|
+
If you are building your own operating system packages, you should be running them in a clean
|
15
|
+
environment every time. fpm-cookery is a superb tool for expressing the process of building and packaging
|
16
|
+
using fpm, but it provides no real functionality for working in a clean environment.
|
17
|
+
|
18
|
+
With the advent of [Docker](https://www.docker.com/), it is fast and easy to bring up an isolated
|
19
|
+
environment (a container) to perform the package building in. It also allows your CI server to perform
|
20
|
+
a very simple invocation to build packages (`fpm-dockery build recipe.rb ubuntu12.04`), and allows you
|
21
|
+
to run the same build on your development machine in the same way.
|
22
|
+
|
23
|
+
If a build fails, you can easily re-run the container and be dropped into the state where the build failed.
|
24
|
+
This makes it very easy to troubleshoot why a build is failing.
|
25
|
+
|
26
|
+
## How does it work?
|
27
|
+
|
28
|
+
`fpm-dockery` has the notion of 'builder' images. These are specially prepared Docker images that
|
29
|
+
contain enough tooling to get `fpm-cookery` working, along with `fpm-cookery` itself.
|
30
|
+
|
31
|
+
You can see the Dockerfiles used to generate these images in the
|
32
|
+
[`docker` directory](https://github.com/andytinycat/fpm-dockery/tree/master/docker) of this
|
33
|
+
repository.
|
34
|
+
|
35
|
+
__NOTE: if you'd like to see more distributions supported, please contribute a Dockerfile in
|
36
|
+
a pull request - it will be welcomed! I went with what I know and use, but Centos/Fedora support should
|
37
|
+
be fairly trivial.__
|
38
|
+
|
39
|
+
These 'builder' images launch `fpm-cook` with specifically-crafted arguments to ensure a clean
|
40
|
+
build each time - and each build takes place in a new container created from the 'builder' image.
|
41
|
+
|
42
|
+
The containers launch with two volumes attached - one volume is the directory containing the recipe,
|
43
|
+
and the other volume is the output directory for the packages. The arguments supplied to `fpm-cook`
|
44
|
+
ensure packages are placed in the correct location.
|
45
|
+
|
46
|
+
## Limitations
|
47
|
+
|
48
|
+
The following limitations are imposed on recipes you use with `fpm-dockery`:
|
49
|
+
|
50
|
+
* If a recipe includes external files, these files must be in the same directory
|
51
|
+
as the recipe file, or any number of subdirectories below where the recipe file is located.
|
52
|
+
This is because the directory containing the recipe is mounted inside the Docker container
|
53
|
+
when a build occurs, so files in this directory or lower can be referenced.
|
54
|
+
* Since we're using Docker, we can only run builds on Linux distributions.
|
55
|
+
|
56
|
+
## Installation
|
57
|
+
|
58
|
+
fpm-dockery is distributed as a Rubygem:
|
59
|
+
|
60
|
+
`gem install fpm-dockery`
|
61
|
+
|
62
|
+
Once you've installed it, you will have access to the `fpm-dockery` command line tool.
|
63
|
+
|
64
|
+
## Usage
|
65
|
+
|
66
|
+
`fpm-dockery` has command line documentation, accessible by supplying the `--help argument`:
|
67
|
+
|
68
|
+
$ bin/fpm-dockery --help
|
69
|
+
Usage:
|
70
|
+
fpm-dockery [OPTIONS] SUBCOMMAND [ARG] ...
|
71
|
+
|
72
|
+
Parameters:
|
73
|
+
SUBCOMMAND subcommand
|
74
|
+
[ARG] ... subcommand arguments
|
75
|
+
|
76
|
+
Subcommands:
|
77
|
+
create-builder-image Build one of the fpm-dockery Docker 'builder' images
|
78
|
+
package Run fpm-cookery in a Docker container to produce a package
|
79
|
+
list-builders List available builders
|
80
|
+
|
81
|
+
Options:
|
82
|
+
-h, --help print help
|
83
|
+
|
84
|
+
### Building packages
|
85
|
+
|
86
|
+
To create a package, run `fpm-dockery package`, which takes two required arguments and one
|
87
|
+
optional argument:
|
88
|
+
|
89
|
+
fpm-dockery package PATH_TO_RECIPE BUILDER [PACKAGE_DIR]
|
90
|
+
|
91
|
+
The builder is one of the supported builder images. If the builder image does not exist on the
|
92
|
+
system where Docker is running, it will be automatically created first. The packages will be
|
93
|
+
created in `PATH_TO_RECIPE/pkg`.
|
94
|
+
|
95
|
+
For example, to run the supplied example recipe (which builds Redis) on Ubuntu Precise (12.04 LTS), run:
|
96
|
+
|
97
|
+
fpm-dockery package example_recipe/recipe.rb ubuntu12.04
|
98
|
+
|
99
|
+
If you'd like to override where packages are created, you can specify the optional third
|
100
|
+
argument `PACKAGE_DIR`:
|
101
|
+
|
102
|
+
fpm-dockery package example_recipe/recipe.rb ubuntu12.04 /tmp/somedir
|
103
|
+
|
104
|
+
|
105
|
+
### Viewing available builders
|
106
|
+
|
107
|
+
To see the available builders, run:
|
108
|
+
|
109
|
+
fpm-dockery list-builders
|
110
|
+
|
111
|
+
### Manually creating builder images
|
112
|
+
|
113
|
+
If you'd like to run a builder image creation task manually, you can run:
|
114
|
+
|
115
|
+
fpm-dockery create-builder-image BUILDER
|
116
|
+
|
117
|
+
For example, to build the Ubuntu Trusty (14.04 LTS) builder image, run:
|
118
|
+
|
119
|
+
fpm-dockery create-builder-image ubuntu14.04
|
120
|
+
|
121
|
+
If you want to run this image creation without the Docker cache (perhaps your image is somehow
|
122
|
+
messed up), run:
|
123
|
+
|
124
|
+
fpm-dockery create-builder-image --no-cache BUILDER
|
125
|
+
|
126
|
+
For example, to run the Trusty build again with no cache:
|
127
|
+
|
128
|
+
fpm-dockery create-builder-image --no-cache ubuntu14.04
|
129
|
+
|
130
|
+
## Contributing
|
131
|
+
|
132
|
+
Pull requests are welcomed, especially for supporting new distributions. This project was a spike to replace
|
133
|
+
some unpleasant homegrown scripts at [Forward3D](https://github.com/forward3d), so it's immature. Bugfixes and features welcomed.
|
134
|
+
|
135
|
+
1. Fork it ( https://github.com/[my-github-username]/fpm-dockery/fork )
|
136
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
137
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
138
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
139
|
+
5. Create a new Pull Request
|
140
|
+
|
141
|
+
## Acknowledgements
|
142
|
+
|
143
|
+
Thanks to [@bernd](https://github.com/bernd) for creating fpm-cookery, and [@sissel](https://github.com/jordansissel)
|
144
|
+
for creating FPM, without which life would be less pleasant.
|
145
|
+
|
146
|
+
I also used the Redis example recipe from @bernd's repository and placed it in this repository so it can be used
|
147
|
+
for a quick proof-of-concept.
|
data/Rakefile
ADDED
data/bin/fpm-dockery
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
FROM ubuntu:12.04
|
2
|
+
|
3
|
+
RUN apt-get update
|
4
|
+
|
5
|
+
# Additional tooling
|
6
|
+
RUN apt-get install -y git
|
7
|
+
RUN apt-get install -y curl
|
8
|
+
RUN apt-get install -y mercurial
|
9
|
+
RUN apt-get install -y subversion
|
10
|
+
|
11
|
+
# Build tools
|
12
|
+
RUN apt-get install -y build-essential
|
13
|
+
|
14
|
+
# Install Ruby from Brightbox's PPA
|
15
|
+
RUN apt-get -y install python-software-properties
|
16
|
+
RUN apt-add-repository ppa:brightbox/ruby-ng
|
17
|
+
RUN apt-get update
|
18
|
+
RUN apt-get -y install ruby2.1
|
19
|
+
RUN apt-get -y install ruby2.1-dev
|
20
|
+
|
21
|
+
# Install fpm-cookery
|
22
|
+
RUN gem install fpm-cookery -v 0.27.0
|
23
|
+
|
24
|
+
# Set an entry point to simplify command execution
|
25
|
+
ENTRYPOINT ["/usr/local/bin/fpm-cook"]
|
@@ -0,0 +1,25 @@
|
|
1
|
+
FROM ubuntu:14.04
|
2
|
+
|
3
|
+
RUN apt-get update
|
4
|
+
|
5
|
+
# Additional tooling
|
6
|
+
RUN apt-get install -y git
|
7
|
+
RUN apt-get install -y curl
|
8
|
+
RUN apt-get install -y mercurial
|
9
|
+
RUN apt-get install -y subversion
|
10
|
+
|
11
|
+
# Build tools
|
12
|
+
RUN apt-get install -y build-essential
|
13
|
+
|
14
|
+
# Install Ruby from Brightbox's PPA
|
15
|
+
RUN apt-get -y install software-properties-common
|
16
|
+
RUN apt-add-repository ppa:brightbox/ruby-ng
|
17
|
+
RUN apt-get update
|
18
|
+
RUN apt-get -y install ruby2.1
|
19
|
+
RUN apt-get -y install ruby2.1-dev
|
20
|
+
|
21
|
+
# Install fpm-cookery
|
22
|
+
RUN gem install fpm-cookery -v 0.27.0
|
23
|
+
|
24
|
+
# Set an entry point to simplify command execution
|
25
|
+
ENTRYPOINT ["/usr/local/bin/fpm-cook"]
|
@@ -0,0 +1,48 @@
|
|
1
|
+
class Redis < FPM::Cookery::Recipe
|
2
|
+
homepage 'http://redis.io'
|
3
|
+
|
4
|
+
# Different source methods.
|
5
|
+
#
|
6
|
+
#source 'https://github.com/antirez/redis/trunk', :with => :svn
|
7
|
+
#source 'https://github.com/antirez/redis/trunk', :with => :svn, :revision => '2400'
|
8
|
+
#
|
9
|
+
#source 'https://github.com/antirez/redis', :with => :git, :tag => '2.4.2
|
10
|
+
#source 'https://github.com/antirez/redis', :with => :git, :branch => '2.4'
|
11
|
+
#source 'https://github.com/antirez/redis', :with => :git, :sha => '072a905'
|
12
|
+
|
13
|
+
source 'http://redis.googlecode.com/files/redis-2.4.2.tar.gz'
|
14
|
+
md5 'c4b0b5e4953a11a503cb54cf6b09670e'
|
15
|
+
|
16
|
+
name 'redis-server'
|
17
|
+
version '2.4.2'
|
18
|
+
# revision '0' # => redis-server-2.2.5+fpm1
|
19
|
+
|
20
|
+
description 'An advanced key-value store.'
|
21
|
+
|
22
|
+
conflicts 'redis-server'
|
23
|
+
|
24
|
+
config_files '/etc/redis/redis.conf'
|
25
|
+
|
26
|
+
patches 'patches/test.patch'
|
27
|
+
|
28
|
+
def build
|
29
|
+
make
|
30
|
+
|
31
|
+
inline_replace 'redis.conf' do |s|
|
32
|
+
s.gsub! 'daemonize no', 'daemonize yes # non-default'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def install
|
37
|
+
# make :install, 'DESTDIR' => destdir
|
38
|
+
|
39
|
+
var('lib/redis').mkdir
|
40
|
+
|
41
|
+
%w(run log/redis).each {|p| var(p).mkdir }
|
42
|
+
|
43
|
+
bin.install ['src/redis-server', 'src/redis-cli']
|
44
|
+
|
45
|
+
etc('redis').install 'redis.conf'
|
46
|
+
etc('init.d').install workdir('redis-server.init.d') => 'redis-server'
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
#! /bin/sh
|
2
|
+
### BEGIN INIT INFO
|
3
|
+
# Provides: redis-server
|
4
|
+
# Required-Start: $syslog
|
5
|
+
# Required-Stop: $syslog
|
6
|
+
# Should-Start: $local_fs
|
7
|
+
# Should-Stop: $local_fs
|
8
|
+
# Default-Start: 2 3 4 5
|
9
|
+
# Default-Stop: 0 1 6
|
10
|
+
# Short-Description: redis-server - Persistent key-value db
|
11
|
+
# Description: redis-server - Persistent key-value db
|
12
|
+
### END INIT INFO
|
13
|
+
|
14
|
+
|
15
|
+
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
|
16
|
+
DAEMON=/usr/bin/redis-server
|
17
|
+
DAEMON_ARGS=/etc/redis/redis.conf
|
18
|
+
NAME=redis-server
|
19
|
+
DESC=redis-server
|
20
|
+
PIDFILE=/var/run/redis.pid
|
21
|
+
|
22
|
+
test -x $DAEMON || exit 0
|
23
|
+
test -x $DAEMONBOOTSTRAP || exit 0
|
24
|
+
|
25
|
+
set -e
|
26
|
+
|
27
|
+
case "$1" in
|
28
|
+
start)
|
29
|
+
echo -n "Starting $DESC: "
|
30
|
+
touch $PIDFILE
|
31
|
+
chown redis:redis $PIDFILE
|
32
|
+
chown redis:redis /var/log/redis
|
33
|
+
chown redis:redis /var/lib/redis
|
34
|
+
if start-stop-daemon --start --quiet --umask 007 --pidfile $PIDFILE --chuid redis:redis --exec $DAEMON -- $DAEMON_ARGS
|
35
|
+
then
|
36
|
+
echo "$NAME."
|
37
|
+
else
|
38
|
+
echo "failed"
|
39
|
+
fi
|
40
|
+
;;
|
41
|
+
stop)
|
42
|
+
echo -n "Stopping $DESC: "
|
43
|
+
if start-stop-daemon --stop --retry 10 --quiet --oknodo --pidfile $PIDFILE --exec $DAEMON
|
44
|
+
then
|
45
|
+
echo "$NAME."
|
46
|
+
else
|
47
|
+
echo "failed"
|
48
|
+
fi
|
49
|
+
rm -f $PIDFILE
|
50
|
+
;;
|
51
|
+
|
52
|
+
restart|force-reload)
|
53
|
+
${0} stop
|
54
|
+
${0} start
|
55
|
+
;;
|
56
|
+
status)
|
57
|
+
if [ -f $PIDFILE ]
|
58
|
+
then
|
59
|
+
PID=`cat $PIDFILE`
|
60
|
+
echo -n "Redis (pid: $PID): "
|
61
|
+
if ps aux | grep $PID > /dev/null
|
62
|
+
then
|
63
|
+
echo "running"
|
64
|
+
exit 0
|
65
|
+
else
|
66
|
+
echo "failed"
|
67
|
+
exit 3
|
68
|
+
fi
|
69
|
+
else
|
70
|
+
echo "Redis not running"
|
71
|
+
exit 3
|
72
|
+
fi
|
73
|
+
;;
|
74
|
+
*)
|
75
|
+
echo "Usage: /etc/init.d/$NAME {start|stop|restart|force-reload}" >&2
|
76
|
+
exit 1
|
77
|
+
;;
|
78
|
+
esac
|
79
|
+
|
80
|
+
exit 0
|
data/fpm-dockery.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'fpm/dockery/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "fpm-dockery"
|
8
|
+
spec.version = Fpm::Dockery::VERSION
|
9
|
+
spec.authors = ["Andy Sykes"]
|
10
|
+
spec.email = ["github@tinycat.co.uk"]
|
11
|
+
|
12
|
+
spec.summary = %q{Build fpm-cookery recipes with Docker!}
|
13
|
+
spec.description = %q{Use Docker to produce clean builds of fpm-cookery recipes by building in containers}
|
14
|
+
spec.homepage = "https://github.com/andytinycat/fpm-dockery"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_runtime_dependency "clamp", "~> 0.6.4"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.8"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
end
|
data/lib/fpm/dockery.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "clamp"
|
2
|
+
require "logger"
|
3
|
+
require "open3"
|
4
|
+
|
5
|
+
require "fpm/dockery/version"
|
6
|
+
require "fpm/dockery/logging"
|
7
|
+
require "fpm/dockery/utils"
|
8
|
+
require "fpm/dockery/cli"
|
9
|
+
|
10
|
+
module FPM
|
11
|
+
module Dockery
|
12
|
+
def self.root
|
13
|
+
File.expand_path("../../../", __FILE__)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
module FPM
|
4
|
+
module Dockery
|
5
|
+
class CLI < Clamp::Command
|
6
|
+
|
7
|
+
class BaseCommand < Clamp::Command
|
8
|
+
include Logging
|
9
|
+
include Utils
|
10
|
+
|
11
|
+
def valid_builders
|
12
|
+
Dir.glob("#{FPM::Dockery.root}/docker/Dockerfile.*").map {|f| File.basename(f.gsub('Dockerfile.', ''))}
|
13
|
+
end
|
14
|
+
|
15
|
+
def validate_builder!
|
16
|
+
unless valid_builders.include?(builder)
|
17
|
+
fatal "Image type must be one of: #{valid_builders.join(', ')}"
|
18
|
+
exit 1
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_builder_if_required
|
23
|
+
image_check = Subprocess.run("docker images | awk '{print $1}' | grep fpm-dockery/#{builder}")
|
24
|
+
unless image_check.exitstatus == 0
|
25
|
+
warn "The builder image '#{builder}' does not exist; running the image creation for you"
|
26
|
+
create_builder(false)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def create_builder(no_cache)
|
31
|
+
validate_builder!
|
32
|
+
cache_option = no_cache ? '--no-cache=true' : ''
|
33
|
+
exit_status = Subprocess.run("docker build #{cache_option} -f #{FPM::Dockery.root}/docker/Dockerfile.#{builder} -t fpm-dockery/#{builder} #{FPM::Dockery.root}")
|
34
|
+
if exit_status.exitstatus == 0
|
35
|
+
info "Build complete"
|
36
|
+
else
|
37
|
+
info "Build process exited with a non-zero exit code"
|
38
|
+
exit exit_status.exitstatus
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
class ListBuildersCommand < BaseCommand
|
45
|
+
def execute
|
46
|
+
puts valid_builders.join("\n")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class CreateBuilderImage < BaseCommand
|
51
|
+
parameter "BUILDER", "Type of builder image to build"
|
52
|
+
option "--no-cache", :flag, "Build without cache"
|
53
|
+
|
54
|
+
def execute
|
55
|
+
create_builder(no_cache?)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
class PackageCommand < BaseCommand
|
60
|
+
parameter "RECIPE", "fpm-cookery recipe to build"
|
61
|
+
parameter "BUILDER", "Builder to use"
|
62
|
+
parameter "[PACKAGE_DIR]", "Where to place the packages created by the build (defaults to /pkg in same dir as recipe)"
|
63
|
+
|
64
|
+
def execute
|
65
|
+
recipe_path = File.expand_path(recipe)
|
66
|
+
dir_to_mount = File.dirname(recipe_path)
|
67
|
+
name_of_recipe = File.basename(recipe_path)
|
68
|
+
|
69
|
+
validate_builder!
|
70
|
+
create_builder_if_required
|
71
|
+
|
72
|
+
extra_command = ''
|
73
|
+
pkg_dir = "/recipe/pkg"
|
74
|
+
|
75
|
+
if package_dir
|
76
|
+
extra_command = "-v #{File.expand_path(package_dir)}:/output"
|
77
|
+
pkg_dir = "/output"
|
78
|
+
end
|
79
|
+
|
80
|
+
command = <<eos
|
81
|
+
docker run \
|
82
|
+
-v #{dir_to_mount}:/recipe \
|
83
|
+
#{extra_command} \
|
84
|
+
fpm-dockery/ubuntu \
|
85
|
+
--tmp-root /tmp/tmproot \
|
86
|
+
--pkg-dir #{pkg_dir} \
|
87
|
+
--cache-dir /tmp/cache \
|
88
|
+
package \
|
89
|
+
/recipe/#{name_of_recipe}
|
90
|
+
eos
|
91
|
+
exit_status = Subprocess.run(command)
|
92
|
+
if exit_status.exitstatus == 0
|
93
|
+
info "Packaging complete"
|
94
|
+
else
|
95
|
+
info "Packaging process exited with a non-zero exit code"
|
96
|
+
exit exit_status.exitstatus
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
subcommand "create-builder-image", "Build one of the fpm-dockery Docker 'builder' images", CreateBuilderImage
|
103
|
+
subcommand "package", "Run fpm-cookery in a Docker container to produce a package", PackageCommand
|
104
|
+
subcommand "list-builders", "List available builders", ListBuildersCommand
|
105
|
+
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module FPM
|
2
|
+
module Dockery
|
3
|
+
module Logging
|
4
|
+
|
5
|
+
@@logger = Logger.new(STDOUT)
|
6
|
+
@@logger.formatter = proc do |severity, datetime, progname, msg|
|
7
|
+
"[#{severity}] #{msg}\n"
|
8
|
+
end
|
9
|
+
|
10
|
+
def info(msg)
|
11
|
+
@@logger.info(msg)
|
12
|
+
end
|
13
|
+
|
14
|
+
def warn(msg)
|
15
|
+
@@logger.warn(msg)
|
16
|
+
end
|
17
|
+
|
18
|
+
def fatal(msg)
|
19
|
+
@@logger.fatal(msg)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module FPM
|
2
|
+
module Dockery
|
3
|
+
module Utils
|
4
|
+
|
5
|
+
# A moderately decent way of dealing with running commands
|
6
|
+
# and coping with stdout/stderr
|
7
|
+
class Subprocess
|
8
|
+
extend Logging
|
9
|
+
def self.run(cmd, &block)
|
10
|
+
info "Running command '#{cmd}'"
|
11
|
+
log_command = "#{cmd.split(' ')[0]}"
|
12
|
+
# see: http://stackoverflow.com/a/1162850/83386
|
13
|
+
Open3.popen3(cmd) do |stdin, stdout, stderr, thread|
|
14
|
+
# read each stream from a new thread
|
15
|
+
{ :out => stdout, :err => stderr }.each do |key, stream|
|
16
|
+
Thread.new do
|
17
|
+
until (line = stream.gets).nil? do
|
18
|
+
# yield the block depending on the stream
|
19
|
+
if key == :out
|
20
|
+
info("[#{log_command}] [stdout] #{line.chomp}") unless line.nil?
|
21
|
+
else
|
22
|
+
info("[#{log_command}] [stderr] #{line.chomp}") unless line.nil?
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
thread.join # don't exit until the external process is done
|
29
|
+
return thread.value
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fpm-dockery
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andy Sykes
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: clamp
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.6.4
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.6.4
|
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.8'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.8'
|
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
|
+
description: Use Docker to produce clean builds of fpm-cookery recipes by building
|
56
|
+
in containers
|
57
|
+
email:
|
58
|
+
- github@tinycat.co.uk
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".ruby-gemset"
|
65
|
+
- ".ruby-version"
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/fpm-dockery
|
71
|
+
- docker/Dockerfile.ubuntu12.04
|
72
|
+
- docker/Dockerfile.ubuntu14.04
|
73
|
+
- example_recipe/recipe.rb
|
74
|
+
- example_recipe/redis-server.init.d
|
75
|
+
- fpm-dockery.gemspec
|
76
|
+
- lib/fpm/dockery.rb
|
77
|
+
- lib/fpm/dockery/cli.rb
|
78
|
+
- lib/fpm/dockery/logging.rb
|
79
|
+
- lib/fpm/dockery/utils.rb
|
80
|
+
- lib/fpm/dockery/version.rb
|
81
|
+
homepage: https://github.com/andytinycat/fpm-dockery
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
metadata: {}
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 2.4.3
|
102
|
+
signing_key:
|
103
|
+
specification_version: 4
|
104
|
+
summary: Build fpm-cookery recipes with Docker!
|
105
|
+
test_files: []
|