buildizer 0.0.1 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.gitignore +1 -1
- data/{Packagefile.example.1 → Buildizer.example.1} +1 -1
- data/{Packagefile.example.2 → Buildizer.example.2} +0 -0
- data/{Packagefile.example.3 → Buildizer.example.3} +0 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +12 -4
- data/bin/buildizer +1 -941
- data/buildizer.gemspec +2 -2
- data/lib/buildizer/builder/base.rb +173 -0
- data/lib/buildizer/builder/fpm.rb +129 -0
- data/lib/buildizer/builder.rb +4 -0
- data/lib/buildizer/cli.rb +58 -0
- data/lib/buildizer/docker.rb +95 -0
- data/lib/buildizer/error.rb +4 -0
- data/lib/buildizer/image/base.rb +56 -0
- data/lib/buildizer/image/centos.rb +52 -0
- data/lib/buildizer/image/centos6.rb +9 -0
- data/lib/buildizer/image/centos7.rb +9 -0
- data/lib/buildizer/image/ubuntu.rb +39 -0
- data/lib/buildizer/image/ubuntu1204.rb +13 -0
- data/lib/buildizer/image/ubuntu1404.rb +13 -0
- data/lib/buildizer/image.rb +4 -0
- data/lib/buildizer/packager.rb +260 -0
- data/lib/buildizer/refine.rb +11 -0
- data/lib/buildizer/target/base.rb +39 -0
- data/lib/buildizer/target/fpm.rb +17 -0
- data/lib/buildizer/target.rb +4 -0
- data/lib/buildizer/version.rb +1 -1
- data/lib/buildizer.rb +26 -0
- metadata +49 -30
@@ -0,0 +1,260 @@
|
|
1
|
+
module Buildizer
|
2
|
+
class Packager
|
3
|
+
attr_reader :package_path
|
4
|
+
attr_reader :buildizer_conf_path
|
5
|
+
attr_reader :options_path
|
6
|
+
attr_reader :travis_path
|
7
|
+
attr_reader :debug
|
8
|
+
|
9
|
+
def initialize(options: {}, debug: false)
|
10
|
+
@package_path = Pathname.new(ENV['BUILDIZER_PATH'] || '.').expand_path
|
11
|
+
@buildizer_conf_path = package_path.join('Buildizer')
|
12
|
+
@options_path = package_path.join('.buildizer.yml')
|
13
|
+
@travis_path = package_path.join('.travis.yml')
|
14
|
+
@_options = options
|
15
|
+
@debug = debug
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialized?
|
19
|
+
options_path.exist?
|
20
|
+
end
|
21
|
+
|
22
|
+
def enabled?
|
23
|
+
not (ENV['TRAVIS_TAG'] || ENV['CI_BUILD_TAG']).empty?
|
24
|
+
end
|
25
|
+
|
26
|
+
def init!
|
27
|
+
raise Error, error: :logical_error, message: "already initialized" if initialized?
|
28
|
+
|
29
|
+
git_precommit_init!
|
30
|
+
options_setup!
|
31
|
+
travis_setup!
|
32
|
+
end
|
33
|
+
|
34
|
+
def deinit!
|
35
|
+
raise Error, error: :logical_error, message: "not initialized" unless initialized?
|
36
|
+
options_path.delete
|
37
|
+
git_precommit_deinit!
|
38
|
+
end
|
39
|
+
|
40
|
+
def update!
|
41
|
+
travis_setup!
|
42
|
+
end
|
43
|
+
|
44
|
+
def prepare!
|
45
|
+
builder.prepare
|
46
|
+
end
|
47
|
+
|
48
|
+
def build!
|
49
|
+
builder.build
|
50
|
+
end
|
51
|
+
|
52
|
+
def deploy!
|
53
|
+
builder.deploy
|
54
|
+
end
|
55
|
+
|
56
|
+
def buildizer_conf
|
57
|
+
@buildizer_conf ||= YAML.load(buildizer_conf_path.read)
|
58
|
+
end
|
59
|
+
|
60
|
+
def options
|
61
|
+
@options ||= (YAML.load(options_path.read) rescue {}).tap do |res|
|
62
|
+
@_options.each do |k, v|
|
63
|
+
res[k] = v unless v.nil?
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def options_setup!
|
69
|
+
options_path.write YAML.dump(options)
|
70
|
+
@options = nil
|
71
|
+
end
|
72
|
+
|
73
|
+
def travis
|
74
|
+
@travis ||= (travis_path.exist? ? YAML.load(travis_path.read) : {})
|
75
|
+
rescue Psych::Exception => err
|
76
|
+
raise Error, error: :input_error, message: "bad travis config file #{file}: #{err.message}"
|
77
|
+
end
|
78
|
+
|
79
|
+
def travis_setup!
|
80
|
+
install = [
|
81
|
+
'sudo apt-get update',
|
82
|
+
'sudo apt-get install -y apt-transport-https ca-certificates',
|
83
|
+
'sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D',
|
84
|
+
'echo "deb https://apt.dockerproject.org/repo ubuntu-trusty main" | sudo tee /etc/apt/sources.list.d/docker.list',
|
85
|
+
'sudo apt-get update',
|
86
|
+
'sudo apt-get -o dpkg::options::="--force-confnew" install -y docker-engine=1.9.1-0~trusty', # FIXME [https://github.com/docker/docker/issues/20316]
|
87
|
+
'echo "docker-engine hold" | sudo dpkg --set-selections',
|
88
|
+
]
|
89
|
+
install.push(*Array(buildizer_install_instructions(latest: options['latest'])))
|
90
|
+
|
91
|
+
env = targets.map {|t| "BUILDIZER_TARGET=#{t}"}
|
92
|
+
|
93
|
+
travis_path.write YAML.dump(travis.merge(
|
94
|
+
'dist' => 'trusty',
|
95
|
+
'sudo' => 'required',
|
96
|
+
'cache' => 'apt',
|
97
|
+
'language' => 'ruby',
|
98
|
+
'rvm' => '2.2.1',
|
99
|
+
'install' => install,
|
100
|
+
'before_script' => 'buildizer prepare',
|
101
|
+
'script' => 'buildizer build',
|
102
|
+
'env' => env,
|
103
|
+
'after_success' => 'buildizer deploy',
|
104
|
+
))
|
105
|
+
@travis = nil
|
106
|
+
end
|
107
|
+
|
108
|
+
def git_hooks_path
|
109
|
+
package_path.join('.git').join('hooks')
|
110
|
+
end
|
111
|
+
|
112
|
+
def git_old_hooks_path
|
113
|
+
git_hooks_path.join('old-hooks')
|
114
|
+
end
|
115
|
+
|
116
|
+
def git_precommit_path
|
117
|
+
git_hooks_path.join('pre-commit')
|
118
|
+
end
|
119
|
+
|
120
|
+
def git_old_precommit_path
|
121
|
+
git_old_hooks_path.join('pre-commit')
|
122
|
+
end
|
123
|
+
|
124
|
+
def git_precommit_init!
|
125
|
+
if git_precommit_path.exist?
|
126
|
+
raise(Error,
|
127
|
+
error: :logical_error,
|
128
|
+
message: [
|
129
|
+
"unable to backup existing precommit script: ",
|
130
|
+
"file already exists: #{git_old_precommit_path}",
|
131
|
+
].join) if git_old_precommit_path.exist?
|
132
|
+
git_old_hooks_path.mkpath
|
133
|
+
FileUtils.cp git_precommit_path, git_old_precommit_path
|
134
|
+
end
|
135
|
+
|
136
|
+
git_precommit_path.write <<-EOF
|
137
|
+
#!/bin/bash
|
138
|
+
buildizer update
|
139
|
+
git add -v .travis.yml
|
140
|
+
EOF
|
141
|
+
git_precommit_path.chmod 0755
|
142
|
+
end
|
143
|
+
|
144
|
+
def git_precommit_deinit!
|
145
|
+
git_precommit_path.delete if git_precommit_path.exist?
|
146
|
+
FileUtils.cp git_old_precommit_path, git_precommit_path if git_old_precommit_path.exist?
|
147
|
+
git_old_hooks_path.rmtree if git_old_hooks_path.exist?
|
148
|
+
end
|
149
|
+
|
150
|
+
def package_name
|
151
|
+
buildizer_conf['package_name']
|
152
|
+
end
|
153
|
+
|
154
|
+
def package_version
|
155
|
+
buildizer_conf['package_version']
|
156
|
+
end
|
157
|
+
|
158
|
+
def os_params(os)
|
159
|
+
buildizer_conf['os'].to_h[os.to_s].to_h
|
160
|
+
end
|
161
|
+
|
162
|
+
def before_prepare
|
163
|
+
Array(buildizer_conf['before_prepare'])
|
164
|
+
end
|
165
|
+
|
166
|
+
def after_prepare
|
167
|
+
Array(buildizer_conf['after_prepare'])
|
168
|
+
end
|
169
|
+
|
170
|
+
def targets
|
171
|
+
targets = Array(buildizer_conf['target'])
|
172
|
+
restrict_targets = ENV['BUILDIZER_TARGET']
|
173
|
+
restrict_targets = restrict_targets.split(',').map(&:strip) if restrict_targets
|
174
|
+
targets = targets & restrict_targets if restrict_targets
|
175
|
+
targets
|
176
|
+
end
|
177
|
+
|
178
|
+
def prepare
|
179
|
+
Array(buildizer_conf['prepare'])
|
180
|
+
end
|
181
|
+
|
182
|
+
def build_dep
|
183
|
+
Array(buildizer_conf['build_dep']).to_set
|
184
|
+
end
|
185
|
+
|
186
|
+
def before_build
|
187
|
+
Array(buildizer_conf['before_build'])
|
188
|
+
end
|
189
|
+
|
190
|
+
def docker_server
|
191
|
+
buildizer_conf['docker_server']
|
192
|
+
end
|
193
|
+
|
194
|
+
def docker_image
|
195
|
+
buildizer_conf['image']
|
196
|
+
end
|
197
|
+
|
198
|
+
def package_cloud
|
199
|
+
buildizer_conf['package_cloud']
|
200
|
+
end
|
201
|
+
|
202
|
+
def package_cloud_token
|
203
|
+
ENV['PACKAGECLOUD_TOKEN'] || begin
|
204
|
+
raise Error, error: :input_error, message: "PACKAGECLOUD_TOKEN env variable required"
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
def docker_username
|
209
|
+
ENV['BUILDIZER_DOCKER_USERNAME'] || begin
|
210
|
+
raise Error, error: :input_error, message: "BUILDIZER_DOCKER_USERNAME env variable required"
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
def docker_password
|
215
|
+
ENV['BUILDIZER_DOCKER_PASSWORD'] || begin
|
216
|
+
raise Error, error: :input_error, message: "BUILDIZER_DOCKER_PASSWORD env variable required"
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
def docker_email
|
221
|
+
ENV['BUILDIZER_DOCKER_EMAIL'] || begin
|
222
|
+
raise Error, error: :input_error, message: "BUILDIZER_DOCKER_EMAIL env variable required"
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
def builder
|
227
|
+
@builder ||= begin
|
228
|
+
build_type = buildizer_conf['build_type']
|
229
|
+
klass = {'fpm' => Builder::Fpm}[build_type]
|
230
|
+
raise Error, error: :input_error, message: "unknown build_type '#{build_type}'" unless klass
|
231
|
+
klass.new(self)
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
def buildizer_install_instructions(latest: nil)
|
236
|
+
if latest
|
237
|
+
['git clone https://github.com/flant/buildizer ~/buildizer',
|
238
|
+
'echo "export BUNDLE_GEMFILE=~/buildizer/Gemfile" | tee -a ~/.bashrc',
|
239
|
+
'export BUNDLE_GEMFILE=~/buildizer/Gemfile',
|
240
|
+
'gem install bundler',
|
241
|
+
'bundle install',
|
242
|
+
]
|
243
|
+
else
|
244
|
+
'gem install buildizer'
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
def command(*args, do_raise: false, **kwargs)
|
249
|
+
Shellfold.run(*args, live_log: debug, **kwargs).tap do |cmd|
|
250
|
+
if not cmd.status.success? and do_raise
|
251
|
+
raise Error.new(error: :error, message: "external command error")
|
252
|
+
end
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
def command!(*args, **kwargs)
|
257
|
+
command(*args, do_raise: true, log_failure: true, **kwargs)
|
258
|
+
end
|
259
|
+
end # Packager
|
260
|
+
end # Buildizer
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Buildizer
|
2
|
+
module Target
|
3
|
+
class Base
|
4
|
+
attr_reader :builder
|
5
|
+
attr_reader :image
|
6
|
+
|
7
|
+
attr_reader :name
|
8
|
+
attr_reader :package_name
|
9
|
+
attr_reader :package_version
|
10
|
+
attr_reader :package_cloud
|
11
|
+
attr_reader :prepare
|
12
|
+
attr_reader :build_dep
|
13
|
+
attr_reader :before_build
|
14
|
+
|
15
|
+
def initialize(builder, image,
|
16
|
+
name:, package_name:, package_version:, package_cloud:,
|
17
|
+
prepare: [], build_dep: [], before_build: [])
|
18
|
+
@builder = builder
|
19
|
+
@image = image
|
20
|
+
|
21
|
+
@name = name
|
22
|
+
@package_name = package_name
|
23
|
+
@package_version = package_version
|
24
|
+
@package_cloud = package_cloud
|
25
|
+
@prepare = prepare
|
26
|
+
@build_dep = build_dep
|
27
|
+
@before_build = before_build
|
28
|
+
end
|
29
|
+
|
30
|
+
def docker_image
|
31
|
+
"#{builder.packager.docker_image || "buildizer/#{package_name}"}:#{name}"
|
32
|
+
end
|
33
|
+
|
34
|
+
def package_cloud_path
|
35
|
+
"#{package_cloud}/#{image.os_package_cloud_name}/#{image.os_package_cloud_version}"
|
36
|
+
end
|
37
|
+
end # Base
|
38
|
+
end # Target
|
39
|
+
end # Buildizer
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Buildizer
|
2
|
+
module Target
|
3
|
+
class Fpm < Base
|
4
|
+
attr_reader :fpm_script
|
5
|
+
attr_reader :fpm_config_files
|
6
|
+
attr_reader :fpm_files
|
7
|
+
|
8
|
+
def initialize(builder, image, fpm_script: [], fpm_config_files: {}, fpm_files: {}, **kwargs)
|
9
|
+
super(builder, image, **kwargs)
|
10
|
+
|
11
|
+
@fpm_script = fpm_script
|
12
|
+
@fpm_config_files = fpm_config_files
|
13
|
+
@fpm_files = fpm_files
|
14
|
+
end
|
15
|
+
end # Fpm
|
16
|
+
end # Target
|
17
|
+
end # Buildizer
|
data/lib/buildizer/version.rb
CHANGED
data/lib/buildizer.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'yaml'
|
3
|
+
require 'net_status'
|
4
|
+
require 'pathname'
|
5
|
+
require 'shellfold'
|
6
|
+
|
7
|
+
require 'buildizer/version'
|
8
|
+
require 'buildizer/refine'
|
9
|
+
require 'buildizer/error'
|
10
|
+
require 'buildizer/docker'
|
11
|
+
require 'buildizer/cli'
|
12
|
+
require 'buildizer/packager'
|
13
|
+
require 'buildizer/target'
|
14
|
+
require 'buildizer/target/base'
|
15
|
+
require 'buildizer/target/fpm'
|
16
|
+
require 'buildizer/builder'
|
17
|
+
require 'buildizer/builder/base'
|
18
|
+
require 'buildizer/builder/fpm'
|
19
|
+
require 'buildizer/image'
|
20
|
+
require 'buildizer/image/base'
|
21
|
+
require 'buildizer/image/centos'
|
22
|
+
require 'buildizer/image/centos6'
|
23
|
+
require 'buildizer/image/centos7'
|
24
|
+
require 'buildizer/image/ubuntu'
|
25
|
+
require 'buildizer/image/ubuntu1204'
|
26
|
+
require 'buildizer/image/ubuntu1404'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: buildizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- flant
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -51,45 +51,25 @@ dependencies:
|
|
51
51
|
- !ruby/object:Gem::Version
|
52
52
|
version: '1.0'
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
|
-
name:
|
54
|
+
name: shellfold
|
55
55
|
requirement: !ruby/object:Gem::Requirement
|
56
56
|
requirements:
|
57
57
|
- - ! '>='
|
58
58
|
- !ruby/object:Gem::Version
|
59
|
-
version:
|
59
|
+
version: 0.0.1
|
60
60
|
- - <
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: '
|
62
|
+
version: '1.0'
|
63
63
|
type: :runtime
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
67
|
- - ! '>='
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version:
|
69
|
+
version: 0.0.1
|
70
70
|
- - <
|
71
71
|
- !ruby/object:Gem::Version
|
72
|
-
version: '
|
73
|
-
- !ruby/object:Gem::Dependency
|
74
|
-
name: travis
|
75
|
-
requirement: !ruby/object:Gem::Requirement
|
76
|
-
requirements:
|
77
|
-
- - ~>
|
78
|
-
- !ruby/object:Gem::Version
|
79
|
-
version: '1.8'
|
80
|
-
- - ! '>='
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: 1.8.2
|
83
|
-
type: :runtime
|
84
|
-
prerelease: false
|
85
|
-
version_requirements: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ~>
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '1.8'
|
90
|
-
- - ! '>='
|
91
|
-
- !ruby/object:Gem::Version
|
92
|
-
version: 1.8.2
|
72
|
+
version: '1.0'
|
93
73
|
- !ruby/object:Gem::Dependency
|
94
74
|
name: package_cloud
|
95
75
|
requirement: !ruby/object:Gem::Requirement
|
@@ -198,6 +178,26 @@ dependencies:
|
|
198
178
|
- - <
|
199
179
|
- !ruby/object:Gem::Version
|
200
180
|
version: '1.0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: travis
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ~>
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '1.8'
|
188
|
+
- - ! '>='
|
189
|
+
- !ruby/object:Gem::Version
|
190
|
+
version: 1.8.2
|
191
|
+
type: :development
|
192
|
+
prerelease: false
|
193
|
+
version_requirements: !ruby/object:Gem::Requirement
|
194
|
+
requirements:
|
195
|
+
- - ~>
|
196
|
+
- !ruby/object:Gem::Version
|
197
|
+
version: '1.8'
|
198
|
+
- - ! '>='
|
199
|
+
- !ruby/object:Gem::Version
|
200
|
+
version: 1.8.2
|
201
201
|
description: Packaging tool.
|
202
202
|
email: 256@flant.com
|
203
203
|
executables:
|
@@ -207,11 +207,11 @@ extra_rdoc_files: []
|
|
207
207
|
files:
|
208
208
|
- .gitignore
|
209
209
|
- .travis.yml
|
210
|
+
- Buildizer.example.1
|
211
|
+
- Buildizer.example.2
|
212
|
+
- Buildizer.example.3
|
210
213
|
- Gemfile
|
211
214
|
- Gemfile.lock
|
212
|
-
- Packagefile.example.1
|
213
|
-
- Packagefile.example.2
|
214
|
-
- Packagefile.example.3
|
215
215
|
- README.md
|
216
216
|
- Rakefile
|
217
217
|
- Vagrantfile
|
@@ -219,6 +219,25 @@ files:
|
|
219
219
|
- bootstrap.sh
|
220
220
|
- buildizer.gemspec
|
221
221
|
- lib/buildizer.rb
|
222
|
+
- lib/buildizer/builder.rb
|
223
|
+
- lib/buildizer/builder/base.rb
|
224
|
+
- lib/buildizer/builder/fpm.rb
|
225
|
+
- lib/buildizer/cli.rb
|
226
|
+
- lib/buildizer/docker.rb
|
227
|
+
- lib/buildizer/error.rb
|
228
|
+
- lib/buildizer/image.rb
|
229
|
+
- lib/buildizer/image/base.rb
|
230
|
+
- lib/buildizer/image/centos.rb
|
231
|
+
- lib/buildizer/image/centos6.rb
|
232
|
+
- lib/buildizer/image/centos7.rb
|
233
|
+
- lib/buildizer/image/ubuntu.rb
|
234
|
+
- lib/buildizer/image/ubuntu1204.rb
|
235
|
+
- lib/buildizer/image/ubuntu1404.rb
|
236
|
+
- lib/buildizer/packager.rb
|
237
|
+
- lib/buildizer/refine.rb
|
238
|
+
- lib/buildizer/target.rb
|
239
|
+
- lib/buildizer/target/base.rb
|
240
|
+
- lib/buildizer/target/fpm.rb
|
222
241
|
- lib/buildizer/version.rb
|
223
242
|
homepage: https://github.com/flant/buildizer
|
224
243
|
licenses:
|