hookit 0.12.3 → 1.0.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.
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hookit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Flint
8
- - Greg Linton
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2016-05-06 00:00:00.000000000 Z
11
+ date: 2022-03-08 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: tilt
@@ -67,34 +66,6 @@ dependencies:
67
66
  - - ">="
68
67
  - !ruby/object:Gem::Version
69
68
  version: '1.3'
70
- - !ruby/object:Gem::Dependency
71
- name: excon
72
- requirement: !ruby/object:Gem::Requirement
73
- requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- version: '0'
77
- type: :runtime
78
- prerelease: false
79
- version_requirements: !ruby/object:Gem::Requirement
80
- requirements:
81
- - - ">="
82
- - !ruby/object:Gem::Version
83
- version: '0'
84
- - !ruby/object:Gem::Dependency
85
- name: faraday
86
- requirement: !ruby/object:Gem::Requirement
87
- requirements:
88
- - - ">="
89
- - !ruby/object:Gem::Version
90
- version: '0'
91
- type: :runtime
92
- prerelease: false
93
- version_requirements: !ruby/object:Gem::Requirement
94
- requirements:
95
- - - ">="
96
- - !ruby/object:Gem::Version
97
- version: '0'
98
69
  - !ruby/object:Gem::Dependency
99
70
  name: bundler
100
71
  requirement: !ruby/object:Gem::Requirement
@@ -123,9 +94,9 @@ dependencies:
123
94
  - - ">="
124
95
  - !ruby/object:Gem::Version
125
96
  version: '0'
126
- description: The core framework to provide hookit scripts with re-usable components.
97
+ description: A template, build, and configuration framework.
127
98
  email:
128
- - tyler@pagodabox.com
99
+ - tylerflint@gmail.com
129
100
  executables:
130
101
  - hookit
131
102
  extensions: []
@@ -144,41 +115,22 @@ files:
144
115
  - lib/hookit/error.rb
145
116
  - lib/hookit/exit.rb
146
117
  - lib/hookit/helper.rb
147
- - lib/hookit/helper/cron.rb
148
- - lib/hookit/helper/nfs.rb
149
118
  - lib/hookit/helper/shell.rb
150
119
  - lib/hookit/helper/xml.rb
151
120
  - lib/hookit/hook.rb
152
121
  - lib/hookit/logger.rb
153
- - lib/hookit/platform.rb
154
- - lib/hookit/platform/base.rb
155
- - lib/hookit/platform/docker.rb
156
- - lib/hookit/platform/smartos.rb
157
- - lib/hookit/platform/ubuntu.rb
158
- - lib/hookit/platforms.rb
159
122
  - lib/hookit/registry.rb
160
123
  - lib/hookit/resource.rb
161
124
  - lib/hookit/resource/base.rb
162
- - lib/hookit/resource/cron.rb
163
125
  - lib/hookit/resource/directory.rb
164
126
  - lib/hookit/resource/execute.rb
165
127
  - lib/hookit/resource/file.rb
166
128
  - lib/hookit/resource/hook_file.rb
167
129
  - lib/hookit/resource/link.rb
168
- - lib/hookit/resource/logrotate.rb
169
- - lib/hookit/resource/mount.rb
170
- - lib/hookit/resource/package.rb
171
- - lib/hookit/resource/rsync.rb
172
- - lib/hookit/resource/scp.rb
173
- - lib/hookit/resource/service.rb
174
- - lib/hookit/resource/socket.rb
175
130
  - lib/hookit/resource/template.rb
176
- - lib/hookit/resource/warning.rb
177
- - lib/hookit/resource/zfs.rb
178
131
  - lib/hookit/resources.rb
179
- - lib/hookit/setup.rb
180
132
  - lib/hookit/version.rb
181
- homepage: ''
133
+ homepage: https://github.com/tylerflint/hookit
182
134
  licenses:
183
135
  - MIT
184
136
  metadata: {}
@@ -197,10 +149,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
197
149
  - !ruby/object:Gem::Version
198
150
  version: '0'
199
151
  requirements: []
200
- rubyforge_project:
201
- rubygems_version: 2.4.5.1
152
+ rubygems_version: 3.0.3.1
202
153
  signing_key:
203
154
  specification_version: 4
204
- summary: Hookit is a framework to provide hookit scripts with re-usable components
205
- and resources via an elegant dsl.
155
+ summary: A template, build, and configuration framework, primarily intended for CI/CD
156
+ scenarios where generating configuration files, code, and running tasks like compilation
157
+ and deployment are necessary.
206
158
  test_files: []
@@ -1,42 +0,0 @@
1
- module Hookit
2
- module Helper
3
- module Cron
4
-
5
- MINUTES = 59
6
- HOURS = 23
7
- DAYS = 31
8
- MONTHS = 12
9
- WEEKDAY = 7
10
-
11
- def sanitize_cron(cron)
12
-
13
- time = cron.split(' ')
14
-
15
- time[0] = compatible_cron(time[0],MINUTES)
16
- time[1] = compatible_cron(time[1],HOURS)
17
- time[2] = compatible_cron(time[2],DAYS, 1)
18
- time[3] = compatible_cron(time[3],MONTHS, 1)
19
- time[4] = compatible_cron(time[4],WEEKDAY)
20
-
21
- time.join(' ')
22
- end
23
-
24
- protected
25
-
26
- # converts */x cron format into solaris compatible format
27
- def compatible_cron(time, limit, start = 0)
28
- if time =~ /\//
29
- increment = time.split('/')[1].to_i
30
- x, y = start, []
31
- for i in 0..limit/increment
32
- y[i] = x
33
- x +=increment
34
- end
35
- time = y.join(',')
36
- end
37
- time
38
- end
39
-
40
- end
41
- end
42
- end
@@ -1,113 +0,0 @@
1
- module Hookit
2
- module Helper
3
- module NFS
4
-
5
- def sanitize_network_dirs(payload)
6
- net_dirs = net_dirs(payload)
7
-
8
- net_dirs.each do |component, dirs|
9
- net_dirs[component] = clean_writables(dirs)
10
- end
11
-
12
- net_dirs
13
- end
14
-
15
- def net_dirs(payload)
16
- key = payload[:storage].keys.first
17
- boxfile = payload[:boxfile]
18
-
19
- if boxfile[:shared_writable_dirs]
20
- {
21
- key => boxfile[:shared_writable_dirs]
22
- }
23
- elsif boxfile[:network_dirs].is_a? String
24
- {
25
- key => [boxfile[:network_dirs]]
26
- }
27
- elsif boxfile[:network_dirs].is_a? Array
28
- {
29
- key => boxfile[:network_dirs]
30
- }
31
- else
32
- boxfile[:network_dirs] ||= {}
33
- end
34
-
35
- end
36
-
37
- def clean_writables(dirs)
38
- begin
39
- dirs = dirs.map{|i| i.to_s}
40
- rescue
41
- dirs = [dirs].map{|i| i.to_s}
42
- end
43
- dirs = remove_empty(dirs)
44
- dirs = filter_offensive(dirs)
45
- dirs = strip_leading_slash(dirs)
46
- dirs = strip_trailing_slash(dirs)
47
- dirs = remove_nested(dirs)
48
- dirs.uniq
49
- end
50
-
51
- def remove_empty(dirs)
52
- dirs.inject([]) do |res, elem|
53
- res << elem if elem && elem != ""
54
- res
55
- end
56
- end
57
-
58
- def filter_offensive(dirs)
59
- dirs.inject([]) do |res, elem|
60
- if elem[0] != '.'
61
- # ensure not going up a directory
62
- # ensure spaces are intended
63
- # ensure directory is not . or /
64
- unless elem =~ /(\*|\.?\.\/|(?<!\\)\s)|^\.$|^\/$/
65
- res << elem
66
- end
67
- end
68
- res
69
- end
70
- end
71
-
72
- def strip_leading_slash(dirs)
73
- dirs.inject([]) do |res, elem|
74
- if elem[0] == '/'
75
- elem.slice!(0)
76
- end
77
- res << elem
78
- end
79
- end
80
-
81
- def strip_trailing_slash(dirs)
82
- dirs.inject([]) do |res, elem|
83
- if elem[-1] == '/'
84
- elem.slice!(-1)
85
- end
86
- res << elem
87
- end
88
- end
89
-
90
- # this removes nested mounts like:
91
- # tmp/
92
- # tmp/cache/
93
- # tmp/assets/
94
- #
95
- # and keeps tmp/
96
- def remove_nested(dirs)
97
- dirs.sort!
98
- dirs.inject([]) do |res, elem|
99
- overlap = false
100
- # now make sure parents dont contain children
101
- res.each do |parent|
102
- if elem =~ /^#{parent}\//
103
- overlap = true
104
- end
105
- end
106
- res << elem if not overlap
107
- res
108
- end
109
- end
110
-
111
- end
112
- end
113
- end
@@ -1,11 +0,0 @@
1
- module Hookit
2
- module Platform
3
- class Base
4
-
5
- def detect?; end
6
- def name; end
7
- def os; end
8
-
9
- end
10
- end
11
- end
@@ -1,19 +0,0 @@
1
- module Hookit
2
- module Platform
3
- class Docker < Base
4
-
5
- def detect?
6
- ! `cat /proc/self/cgroup 2>/dev/null | grep docker`.empty?
7
- end
8
-
9
- def name
10
- 'docker'
11
- end
12
-
13
- def os
14
- 'linux'
15
- end
16
-
17
- end
18
- end
19
- end
@@ -1,19 +0,0 @@
1
- module Hookit
2
- module Platform
3
- class Smartos < Base
4
-
5
- def detect?
6
- ! `cat /etc/release 2>/dev/null | grep -i SmartOS`.empty?
7
- end
8
-
9
- def name
10
- 'smartos'
11
- end
12
-
13
- def os
14
- 'sun'
15
- end
16
-
17
- end
18
- end
19
- end
@@ -1,19 +0,0 @@
1
- module Hookit
2
- module Platform
3
- class Ubuntu < Base
4
-
5
- def detect?
6
- ! `[ -x /usr/bin/lsb_release ] && /usr/bin/lsb_release -i 2>/dev/null | grep Ubuntu`.empty?
7
- end
8
-
9
- def name
10
- 'ubuntu'
11
- end
12
-
13
- def os
14
- 'linux'
15
- end
16
-
17
- end
18
- end
19
- end
@@ -1,10 +0,0 @@
1
- require 'hookit/platform/base'
2
- require 'hookit/platform/docker'
3
- require 'hookit/platform/smartos'
4
- require 'hookit/platform/ubuntu'
5
-
6
- module Hookit
7
- module Platform
8
-
9
- end
10
- end
@@ -1,3 +0,0 @@
1
- Hookit.platforms.register(:docker) { Hookit::Platform::Docker }
2
- Hookit.platforms.register(:smartos) { Hookit::Platform::Smartos }
3
- Hookit.platforms.register(:ubuntu) { Hookit::Platform::Ubuntu }
@@ -1,26 +0,0 @@
1
- module Hookit
2
- module Resource
3
- class Cron < Execute
4
-
5
- def initialize(name)
6
- super
7
- timeout 60
8
- cwd '/data'
9
- end
10
-
11
- protected
12
-
13
- def run!
14
- begin
15
- Timeout::timeout(timeout) do
16
- f = IO.popen("#{cmd} || exit 0", :err=>[:child, :out])
17
- puts f.readline while true
18
- end
19
- rescue Timeout::Error
20
- $stderr.puts 'Timed out running cron! Consider using a worker.'
21
- end
22
- end
23
-
24
- end
25
- end
26
- end
@@ -1,38 +0,0 @@
1
- module Hookit
2
- module Resource
3
- class Logrotate < Base
4
-
5
- field :path
6
- field :filesize
7
- field :max_size
8
- field :count
9
-
10
- actions :create
11
- default_action :create
12
-
13
- def initialize(name)
14
- path name unless path
15
- super
16
- end
17
-
18
- def run(action)
19
- case action
20
- when :create
21
- create!
22
- end
23
- end
24
-
25
- protected
26
-
27
- def create!
28
- case platform.os
29
- when 'sun'
30
- `logadm -c -w #{path} -s #{filesize ||= '10m'} -S #{max_size ||= '500m'} -C #{count ||= '10'} -N`
31
- else
32
- raise Hookit::Error::UnsupportedPlatform, "unsupported platform '#{platform.name}'"
33
- end
34
- end
35
-
36
- end
37
- end
38
- end
@@ -1,92 +0,0 @@
1
- module Hookit
2
- module Resource
3
- class Mount < Base
4
-
5
- field :device
6
- # field :device_type
7
- # field :dump
8
- field :fstype
9
- field :mount_point
10
- field :options
11
- field :pass
12
- field :supports
13
-
14
- actions :mount, :umount, :remount, :enable, :disable
15
- default_action :mount
16
-
17
- def initialize(name)
18
- mount_point(name) unless mount_point
19
- pass('-') unless pass
20
- super
21
- end
22
-
23
- def run(action)
24
- case action
25
- when :mount
26
- mount!
27
- when :umount
28
- umount!
29
- when :remount
30
- umount!
31
- mount!
32
- when :enable
33
- disable!
34
- enable!
35
- when :disable
36
- disable!
37
- end
38
- end
39
-
40
- protected
41
-
42
- def mount!
43
- ::FileUtils.mkdir_p(mount_point)
44
- case platform.os
45
- when 'sun'
46
- run_command! "mount -O -F #{fstype} -o retry=5,timeo=300 #{options!(as_arg=true)} #{device} #{mount_point}"
47
- when 'linux'
48
- run_command! "mount -t #{fstype} -o retry=5,timeo=300 #{options!(as_arg=true)} #{device} #{mount_point}"
49
- end
50
- end
51
-
52
- def umount!
53
- run_command! "umount #{mount_point}"
54
- end
55
-
56
- def enable!
57
- entry = "#{device}\t#{device =~ /^\/dev/ ? device : "-"}\t#{mount_point}\t#{fstype}\t#{pass}\tyes\t#{options!}"
58
- case platform.os
59
- when 'sun'
60
- `echo "#{entry}" >> /etc/vfstab`
61
- when 'linux'
62
- `echo "#{entry}" >> /etc/fstab`
63
- end
64
- end
65
-
66
- def disable!
67
- case platform.os
68
- when 'sun'
69
- `egrep -v "#{device}.*#{mount_point}" /etc/vfstab > /tmp/vfstab.tmp; mv -f /tmp/vfstab.tmp /etc/vfstab`
70
- when 'linux'
71
- `egrep -v "#{device}.*#{mount_point}" /etc/fstab > /tmp/vfstab.tmp; mv -f /tmp/vfstab.tmp /etc/vfstab`
72
- end
73
- end
74
-
75
- def options!(as_arg=false)
76
- options = self.options.kind_of?(Array) ? self.options.join(',') : self.options
77
- if as_arg
78
- options ? (return "-o #{options}") : (return "")
79
- end
80
- options != "" ? (return "#{options}") : (return "-")
81
- end
82
-
83
- def run_command!(cmd, expect_code=0)
84
- `#{cmd}`
85
- code = $?.exitstatus
86
- if code != expect_code
87
- raise Hookit::Error::UnexpectedExit, "#{cmd} failed with exit code '#{code}'"
88
- end
89
- end
90
- end
91
- end
92
- end
@@ -1,74 +0,0 @@
1
- module Hookit
2
- module Resource
3
- class Package < Base
4
-
5
- field :package_name
6
- field :source
7
- field :version
8
- field :scope
9
-
10
- actions :install
11
- default_action :install
12
-
13
- def initialize(name)
14
- package_name(name) unless source
15
- scope :default unless scope
16
- super
17
- end
18
-
19
- def run(action)
20
- case action
21
- when :install
22
- install!
23
- end
24
- end
25
-
26
- def install!
27
- begin
28
- install_package
29
- rescue Hookit::Error::UnexpectedExit
30
- if not registry("pkgsrc.#{scope}.updated")
31
- update_pkg_db
32
- registry("pkgsrc.#{scope}.updated", true)
33
- retry
34
- else
35
- raise
36
- end
37
- end
38
- end
39
-
40
- protected
41
-
42
- def install_package
43
- `#{pkgin} -y in #{package}`
44
-
45
- code = $?.exitstatus
46
- if not code == 0
47
- raise Hookit::Error::UnexpectedExit, "pkgin in #{package} failed with exit code '#{code}'"
48
- end
49
- end
50
-
51
- def update_pkg_db
52
- `#{pkgin} -y up`
53
- end
54
-
55
- def package
56
- if version
57
- "#{package_name}-#{version}"
58
- else
59
- package_name
60
- end
61
- end
62
-
63
- def pkgin
64
- case scope
65
- when :default
66
- "/opt/local/bin/pkgin"
67
- when :gopagoda
68
- "/opt/gopagoda/bin/pkgin"
69
- end
70
- end
71
-
72
- end
73
- end
74
- end
@@ -1,67 +0,0 @@
1
- module Hookit
2
- module Resource
3
- class Rsync < Base
4
-
5
- field :source
6
- field :destination
7
- field :wrapper
8
- field :archive
9
- field :recursive
10
- field :checksum
11
- field :compress
12
-
13
- actions :sync
14
- default_action :sync
15
-
16
- def initialize(name)
17
- source name unless source
18
- super
19
- end
20
-
21
- def run(action)
22
- case action
23
- when :sync
24
- sync!
25
- end
26
- end
27
-
28
- def sync!
29
- run_command! "rsync -q#{archive!}#{recursive!}#{checksum!}#{compress!} #{wrapper!} #{source} #{destination}"
30
- end
31
-
32
- def archive!
33
- (return "a") if archive
34
- ""
35
- end
36
-
37
- def recursive!
38
- (return "r") if archive
39
- ""
40
- end
41
-
42
- def checksum!
43
- (return "c") if archive
44
- ""
45
- end
46
-
47
- def compress!
48
- (return "z") if archive
49
- ""
50
- end
51
-
52
- def wrapper!
53
- (return "-e '#{wrapper}'") if wrapper
54
- ""
55
- end
56
-
57
- def run_command!(cmd, expect_code=0)
58
- `#{cmd}`
59
- code = $?.exitstatus
60
- if code != expect_code
61
- raise Hookit::Error::UnexpectedExit, "#{cmd} failed with exit code '#{code}'"
62
- end
63
- end
64
-
65
- end
66
- end
67
- end