fpm-fry 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/bin/fpm-fry +10 -0
  3. data/lib/cabin/nice_output.rb +70 -0
  4. data/lib/fpm/fry/block_enumerator.rb +25 -0
  5. data/lib/fpm/fry/build_output_parser.rb +22 -0
  6. data/lib/fpm/fry/client.rb +162 -0
  7. data/lib/fpm/fry/command/cook.rb +370 -0
  8. data/lib/fpm/fry/command.rb +90 -0
  9. data/lib/fpm/fry/detector.rb +109 -0
  10. data/lib/fpm/fry/docker_file.rb +149 -0
  11. data/lib/fpm/fry/joined_io.rb +63 -0
  12. data/lib/fpm/fry/os_db.rb +35 -0
  13. data/lib/fpm/fry/plugin/alternatives.rb +90 -0
  14. data/lib/fpm/fry/plugin/edit_staging.rb +66 -0
  15. data/lib/fpm/fry/plugin/exclude.rb +18 -0
  16. data/lib/fpm/fry/plugin/init.rb +53 -0
  17. data/lib/fpm/fry/plugin/platforms.rb +10 -0
  18. data/lib/fpm/fry/plugin/script_helper.rb +176 -0
  19. data/lib/fpm/fry/plugin/service.rb +100 -0
  20. data/lib/fpm/fry/plugin.rb +3 -0
  21. data/lib/fpm/fry/recipe/builder.rb +267 -0
  22. data/lib/fpm/fry/recipe.rb +141 -0
  23. data/lib/fpm/fry/source/dir.rb +56 -0
  24. data/lib/fpm/fry/source/git.rb +90 -0
  25. data/lib/fpm/fry/source/package.rb +202 -0
  26. data/lib/fpm/fry/source/patched.rb +118 -0
  27. data/lib/fpm/fry/source.rb +47 -0
  28. data/lib/fpm/fry/stream_parser.rb +98 -0
  29. data/lib/fpm/fry/tar.rb +71 -0
  30. data/lib/fpm/fry/templates/debian/after_install.erb +9 -0
  31. data/lib/fpm/fry/templates/debian/before_install.erb +13 -0
  32. data/lib/fpm/fry/templates/debian/before_remove.erb +13 -0
  33. data/lib/fpm/fry/templates/redhat/after_install.erb +2 -0
  34. data/lib/fpm/fry/templates/redhat/before_install.erb +6 -0
  35. data/lib/fpm/fry/templates/redhat/before_remove.erb +6 -0
  36. data/lib/fpm/fry/templates/sysv.erb +125 -0
  37. data/lib/fpm/fry/templates/upstart.erb +15 -0
  38. data/lib/fpm/fry/ui.rb +12 -0
  39. data/lib/fpm/package/docker.rb +186 -0
  40. metadata +111 -0
@@ -0,0 +1,13 @@
1
+ #!/bin/bash
2
+
3
+ case "$1" in
4
+ remove)
5
+ <%= remove.join("\n") %>
6
+ ;;
7
+ upgrade)
8
+ <%= upgrade.join("\n") %>
9
+ ;;
10
+ *)
11
+ exit 1
12
+ ;;
13
+ esac
@@ -0,0 +1,2 @@
1
+ #!/bin/bash
2
+ <%= configure.join("\n") %>
@@ -0,0 +1,6 @@
1
+ #!/bin/bash
2
+ if [[ $1 -eq 1 ]] ; then
3
+ <%= install.join("\n") %>
4
+ elif [[ $1 -ge 2 ]] ; then
5
+ <%= upgrade.join("\n") %>
6
+ fi
@@ -0,0 +1,6 @@
1
+ #!/bin/bash
2
+ if [[ $1 -eq 0 ]] ; then
3
+ <%= remove.join("\n") %>
4
+ elif [[ $1 -ge 1 ]] ; then
5
+ <%= upgrade.join("\n") %>
6
+ fi
@@ -0,0 +1,125 @@
1
+ #!/bin/sh
2
+ ### BEGIN INIT INFO
3
+ # Provides: <%= name %>
4
+ # Required-Start: $remote_fs $syslog
5
+ # Required-Stop: $remote_fs $syslog
6
+ # Default-Start: 2 3 4 5
7
+ # Default-Stop: 0 1 6
8
+ # Description: <%= description %>
9
+ ### END INIT INFO
10
+
11
+ # PATH should only include /usr/* if it runs after the mountnfs.sh script
12
+ PATH=/sbin:/usr/sbin:/bin:/usr/bin
13
+ DESC=<%= name.inspect %>
14
+ NAME=<%= name.inspect %>
15
+ DAEMON=<%= command[0].inspect %>
16
+ DAEMON_ARGS=<%= Shellwords.shelljoin(command[1..-1]).inspect %>
17
+ PIDFILE=/var/run/$NAME.pid
18
+ SCRIPTNAME=/etc/init.d/$NAME
19
+
20
+ # Exit if the package is not installed
21
+ [ -x "$DAEMON" ] || exit 0
22
+
23
+ # Read configuration variable file if it is present
24
+ [ -r /etc/default/$NAME ] && . /etc/default/$NAME
25
+
26
+ # Load the VERBOSE setting and other rcS variables
27
+ . /lib/init/vars.sh
28
+
29
+ # Define LSB log_* functions.
30
+ # Depend on lsb-base (>= 3.2-14) to ensure that this file is present
31
+ # and status_of_proc is working.
32
+ . /lib/lsb/init-functions
33
+
34
+ #
35
+ # Function that starts the daemon/service
36
+ #
37
+ do_start()
38
+ {
39
+ # Return
40
+ # 0 if daemon has been started
41
+ # 1 if daemon was already running
42
+ # 2 if daemon could not be started
43
+ start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
44
+ || return 1
45
+ start-stop-daemon --start --quiet --pidfile $PIDFILE --background --exec $DAEMON -- \
46
+ $DAEMON_ARGS \
47
+ || return 2
48
+ # Add code here, if necessary, that waits for the process to be ready
49
+ # to handle requests from services started subsequently which depend
50
+ # on this one. As a last resort, sleep for some time.
51
+ }
52
+
53
+ #
54
+ # Function that stops the daemon/service
55
+ #
56
+ do_stop()
57
+ {
58
+ # Return
59
+ # 0 if daemon has been stopped
60
+ # 1 if daemon was already stopped
61
+ # 2 if daemon could not be stopped
62
+ # other if a failure occurred
63
+ start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
64
+ RETVAL="$?"
65
+ [ "$RETVAL" = 2 ] && return 2
66
+ # Wait for children to finish too if this is a daemon that forks
67
+ # and if the daemon is only ever run from this initscript.
68
+ # If the above conditions are not satisfied then add some other code
69
+ # that waits for the process to drop all resources that could be
70
+ # needed by services started subsequently. A last resort is to
71
+ # sleep for some time.
72
+ start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
73
+ [ "$?" = 2 ] && return 2
74
+ # Many daemons don't delete their pidfiles when they exit.
75
+ rm -f $PIDFILE
76
+ return "$RETVAL"
77
+ }
78
+
79
+ case "$1" in
80
+ start)
81
+ [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
82
+ do_start
83
+ case "$?" in
84
+ 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
85
+ 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
86
+ esac
87
+ ;;
88
+ stop)
89
+ [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
90
+ do_stop
91
+ case "$?" in
92
+ 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
93
+ 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
94
+ esac
95
+ ;;
96
+ status)
97
+ status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $?
98
+ ;;
99
+ restart|force-reload)
100
+ #
101
+ # If the "reload" option is implemented then remove the
102
+ # 'force-reload' alias
103
+ #
104
+ log_daemon_msg "Restarting $DESC" "$NAME"
105
+ do_stop
106
+ case "$?" in
107
+ 0|1)
108
+ do_start
109
+ case "$?" in
110
+ 0) log_end_msg 0 ;;
111
+ 1) log_end_msg 1 ;; # Old process is still running
112
+ *) log_end_msg 1 ;; # Failed to start
113
+ esac
114
+ ;;
115
+ *)
116
+ # Failed to stop
117
+ log_end_msg 1
118
+ ;;
119
+ esac
120
+ ;;
121
+ *)
122
+ echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2
123
+ exit 3
124
+ ;;
125
+ esac
@@ -0,0 +1,15 @@
1
+ description <%= description == "" ? '"a service"' : description.inspect %>
2
+ start on runlevel [2345]
3
+ stop on runlevel [!2345]
4
+
5
+ env DESC=<%= name.inspect %>
6
+ env NAME=<%= name.inspect %>
7
+ env DAEMON=<%= command[0].inspect %>
8
+ env DAEMON_ARGS=<%= Shellwords.shelljoin(command[1..-1]).inspect %>
9
+
10
+ respawn
11
+
12
+ script
13
+ [ -r /etc/default/$NAME ] && . /etc/default/$NAME
14
+ exec "$DAEMON" $DAEMON_ARGS
15
+ end script
data/lib/fpm/fry/ui.rb ADDED
@@ -0,0 +1,12 @@
1
+ require 'cabin/nice_output'
2
+ module FPM; module Fry
3
+ class UI < Struct.new(:out, :err, :logger, :tmpdir)
4
+
5
+ def initialize( out = STDOUT, err = STDERR, logger = nil , tmpdir = '/tmp/fpm-fry' )
6
+ logger ||= Cabin::Channel.new.tap{|chan| chan.subscribe(Cabin::NiceOutput.new(out)) }
7
+ FileUtils.mkdir_p( tmpdir )
8
+ super( out, err, logger, tmpdir )
9
+ end
10
+
11
+ end
12
+ end ; end
@@ -0,0 +1,186 @@
1
+ require 'fpm'
2
+ require 'fpm/package'
3
+
4
+ require 'fpm/fry/client'
5
+
6
+ class FPM::Package::Docker < FPM::Package
7
+
8
+ def initialize( options = {} )
9
+ super()
10
+ if options[:logger]
11
+ @logger = options[:logger]
12
+ end
13
+ if options[:client]
14
+ @client = options[:client]
15
+ end
16
+ if @logger.nil?
17
+ @logger = Cabin::Channel.get
18
+ end
19
+ end
20
+
21
+ def input(name)
22
+ split( name, '**' => staging_path)
23
+ end
24
+
25
+ def split( name, map )
26
+ changes = changes(name)
27
+ changes.remove_modified_leaves! do | ml |
28
+ @logger.warn("Found a modified file. You can only create new files in a package",file: ml)
29
+ end
30
+ fmap = {}
31
+ changes.leaves.each do | change |
32
+ map.each do | match, to |
33
+ if File.fnmatch?(match, change)
34
+ fmap[ change ] = File.join(to, change)
35
+ break
36
+ end
37
+ end
38
+ end
39
+ directories = changes.smallest_superset
40
+ directories.each do |chg|
41
+ client.copy(name, chg, fmap ,chown: false)
42
+ end
43
+ end
44
+
45
+ private
46
+
47
+ def client
48
+ @client ||= FPM::Fry::Client.new(logger: @logger)
49
+ end
50
+
51
+ def changes(name)
52
+ fs = Node.read(client.changes(name))
53
+ fs.reject!(&method(:ignore?))
54
+ return fs
55
+ end
56
+
57
+ def copy(name, chg, options = {})
58
+ client.copy(name, chg, staging_path(chg), {chown: false}.merge(options))
59
+ end
60
+
61
+ IGNORED_PATTERNS = [
62
+ %r!\A/dev(/|\z)!,%r!\A/tmp(/|\z)!,'/root/.bash_history','/.bash_history'
63
+ ]
64
+
65
+ def ignore?(chg)
66
+ return true if IGNORED_PATTERNS.any?{|pattern| pattern === chg }
67
+ Array(attributes[:excludes]).each do |wildcard|
68
+ if File.fnmatch(wildcard, chg) || File.fnmatch(wildcard, chg[1..-1])
69
+ return true
70
+ end
71
+ end
72
+ return false
73
+ end
74
+
75
+ class Node < Struct.new(:children, :kind)
76
+
77
+ def initialize
78
+ super(Hash.new{|hsh,key| hsh[key] = Node.new },nil)
79
+ end
80
+
81
+ def [](name)
82
+ children[name]
83
+ end
84
+
85
+ def leaf?
86
+ children.none?
87
+ end
88
+
89
+ def leaves( prefix = '/', &block )
90
+ return to_enum(:leaves, prefix) unless block
91
+ if leaf?
92
+ yield prefix, false
93
+ else
94
+ children.each do |name, cld|
95
+ cld.leaves( File.join(prefix,name), &block )
96
+ end
97
+ end
98
+ return self
99
+ end
100
+
101
+ def contains_leaves?
102
+ children.any?{|_,c| c.leaf? }
103
+ end
104
+
105
+ def modified_leaves( prefix = '/', &block )
106
+ return to_enum(:modified_leaves, prefix) unless block
107
+ if leaf?
108
+ if kind != 1
109
+ yield prefix
110
+ end
111
+ else
112
+ children.each do |name, cld|
113
+ cld.modified_leaves( File.join(prefix,name), &block)
114
+ end
115
+ end
116
+ end
117
+
118
+ def remove_modified_leaves!( prefix = '/', &block )
119
+ to_remove = {}
120
+ children.each do |name, cld|
121
+ removed_children = cld.remove_modified_leaves!(File.join(prefix,name), &block)
122
+ if cld.leaf? and cld.kind != 1
123
+ to_remove[name] = removed_children
124
+ end
125
+ end
126
+ if to_remove.any?
127
+ to_remove.each do |name, removed_children|
128
+ children.delete(name)
129
+ if !removed_children
130
+ yield File.join(prefix,name)
131
+ end
132
+ end
133
+ return true
134
+ end
135
+ return false
136
+ end
137
+
138
+ def smallest_superset( prefix = '/', &block )
139
+ return to_enum(:smallest_superset, prefix) unless block
140
+ if leaf?
141
+ return
142
+ elsif contains_leaves?
143
+ yield prefix
144
+ else
145
+ children.each do |name, cld|
146
+ cld.smallest_superset( File.join(prefix,name), &block)
147
+ end
148
+ end
149
+ end
150
+
151
+ def reject!( prefix = '/',&block )
152
+ children.reject! do |name, cld|
153
+ p = File.join(prefix,name)
154
+ if yield p
155
+ true
156
+ else
157
+ cld.reject!(p,&block)
158
+ false
159
+ end
160
+ end
161
+ end
162
+
163
+ def delete(path)
164
+ _, key, rest = path.split('/',3)
165
+ if rest.nil?
166
+ children.delete(key)
167
+ else
168
+ children[key].delete("/#{rest}")
169
+ end
170
+ end
171
+
172
+ def self.read(enum)
173
+ fs = Node.new
174
+ enum.each do |ch|
175
+ n = fs
176
+ ch['Path'].split('/').each do |part|
177
+ n = n[part]
178
+ end
179
+ n.kind = ch['Kind']
180
+ end
181
+ return fs
182
+ end
183
+ end
184
+
185
+ end
186
+
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fpm-fry
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Hannes Georg
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-10-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: excon
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.30'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.30'
27
+ - !ruby/object:Gem::Dependency
28
+ name: fpm
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ description: packages docker changes with fpm
42
+ email: hannes.georg@xing.com
43
+ executables:
44
+ - fpm-fry
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - bin/fpm-fry
49
+ - lib/cabin/nice_output.rb
50
+ - lib/fpm/fry/block_enumerator.rb
51
+ - lib/fpm/fry/build_output_parser.rb
52
+ - lib/fpm/fry/client.rb
53
+ - lib/fpm/fry/command.rb
54
+ - lib/fpm/fry/command/cook.rb
55
+ - lib/fpm/fry/detector.rb
56
+ - lib/fpm/fry/docker_file.rb
57
+ - lib/fpm/fry/joined_io.rb
58
+ - lib/fpm/fry/os_db.rb
59
+ - lib/fpm/fry/plugin.rb
60
+ - lib/fpm/fry/plugin/alternatives.rb
61
+ - lib/fpm/fry/plugin/edit_staging.rb
62
+ - lib/fpm/fry/plugin/exclude.rb
63
+ - lib/fpm/fry/plugin/init.rb
64
+ - lib/fpm/fry/plugin/platforms.rb
65
+ - lib/fpm/fry/plugin/script_helper.rb
66
+ - lib/fpm/fry/plugin/service.rb
67
+ - lib/fpm/fry/recipe.rb
68
+ - lib/fpm/fry/recipe/builder.rb
69
+ - lib/fpm/fry/source.rb
70
+ - lib/fpm/fry/source/dir.rb
71
+ - lib/fpm/fry/source/git.rb
72
+ - lib/fpm/fry/source/package.rb
73
+ - lib/fpm/fry/source/patched.rb
74
+ - lib/fpm/fry/stream_parser.rb
75
+ - lib/fpm/fry/tar.rb
76
+ - lib/fpm/fry/templates/debian/after_install.erb
77
+ - lib/fpm/fry/templates/debian/before_install.erb
78
+ - lib/fpm/fry/templates/debian/before_remove.erb
79
+ - lib/fpm/fry/templates/redhat/after_install.erb
80
+ - lib/fpm/fry/templates/redhat/before_install.erb
81
+ - lib/fpm/fry/templates/redhat/before_remove.erb
82
+ - lib/fpm/fry/templates/sysv.erb
83
+ - lib/fpm/fry/templates/upstart.erb
84
+ - lib/fpm/fry/ui.rb
85
+ - lib/fpm/package/docker.rb
86
+ homepage: https://github.com/xing/fpm-fry
87
+ licenses:
88
+ - MIT
89
+ metadata: {}
90
+ post_install_message:
91
+ rdoc_options: []
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project:
106
+ rubygems_version: 2.2.1
107
+ signing_key:
108
+ specification_version: 4
109
+ summary: FPM Fry
110
+ test_files: []
111
+ has_rdoc: