tara 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tara/archive.rb +67 -9
- data/lib/tara/archiver.rb +60 -5
- data/lib/tara/cli.rb +1 -0
- data/lib/tara/executable.rb +6 -4
- data/lib/tara/fetcher.rb +1 -0
- data/lib/tara/installer.rb +12 -11
- data/lib/tara/shell.rb +1 -0
- data/lib/tara/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6ef9fe204be70664e2bbbfe3233e05e90a7f937
|
4
|
+
data.tar.gz: 843fe69f1d2c59112dd1c727ee9e5e0aa4ac8bf6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82977fc6aacec266f7ce3a4a525cbe42029a1bdc3ec6c2533aa26406c3e3e27a668b55cb2f1dd4333b425b7d9d62dd8be68c85896d9863c1b09f800efbf8f7bb
|
7
|
+
data.tar.gz: ec39e9ef990d76d91b252db3cfa8186f6a38e3108fe9db65896b9c1c28bd43a028e2f0d645edc370930bdd9a81cd3429fad531365fe1d78ccfbe00392e71bb25
|
data/lib/tara/archive.rb
CHANGED
@@ -1,13 +1,61 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
module Tara
|
4
|
+
# Packs an application along with a Ruby runtime and dependencies into a TAR archive.
|
5
|
+
#
|
6
|
+
# The archive will include the source code of your project (which is assumed to
|
7
|
+
# be in the `lib` directory), wrapper scripts for each executable (assumed to be
|
8
|
+
# in the `bin` directory), and all gems that aren't in the `test` or `development`
|
9
|
+
# groups in your project's Gemfile.
|
10
|
+
#
|
11
|
+
# @example Creating an archive from a Rake task
|
12
|
+
# task :archive do
|
13
|
+
# Tara::Archive.new.create
|
14
|
+
# end
|
15
|
+
#
|
16
|
+
# @example Configuring the archive to be created
|
17
|
+
# task :archive do
|
18
|
+
# archive = Tara::Archive.new(
|
19
|
+
# target: 'osx',
|
20
|
+
# traveling_ruby_version: '20150204',
|
21
|
+
# without_groups: %w[test],
|
22
|
+
# )
|
23
|
+
# archive.create
|
24
|
+
# end
|
25
|
+
#
|
4
26
|
class Archive
|
27
|
+
# Create a new instance of `Archive` with the specified configuration.
|
28
|
+
#
|
29
|
+
# Tara attempts to use sane defaults in most of all cases, for example like
|
30
|
+
# assuming that the source code is in the `lib` directory of your project,
|
31
|
+
# that the name of the application is the same as the project directory.
|
32
|
+
#
|
33
|
+
# @param [Hash] config
|
34
|
+
# @option config [String] :app_dir (Dir.pwd) absolute path to the application
|
35
|
+
# directory.
|
36
|
+
# @option config [String] :app_name (File.basename(@config[:app_dir])) name of
|
37
|
+
# the application.
|
38
|
+
# @option config [String] :build_dir (File.join(@config[:app_dir], 'build'))
|
39
|
+
# the directory where the archive will be created.
|
40
|
+
# @option config [String] :download_dir (File.join(@config[:build_dir], 'downloads'))
|
41
|
+
# the directory where Traveling Ruby artifacts will be downloaded.
|
42
|
+
# @option config [String] :archive_name (@config[:app_name] + '.tgz') name of the archive
|
43
|
+
# @option config [Array<String>] :files (%w[lib/**/*.rb]) list of globs that will be
|
44
|
+
# expanded when including source files in archive. Should be relative from :app_dir.
|
45
|
+
# @option config [Array<String>] :executables (%w[bin/*]) list of globs that will be
|
46
|
+
# expanded when including executables in archive. Should be relative from :app_dir.
|
47
|
+
# @option config [String] :target (linux-x86_64) target platform that the archive will
|
48
|
+
# be created for. Should be one of "linux-x86", "linux-x86_64", or "osx".
|
49
|
+
# @option config [String] :traveling_ruby_version (20150210) release of Traveling Ruby
|
50
|
+
# that should be used.
|
51
|
+
# @option config [Array<String>] :without_groups (%w[development test]) list of gem
|
52
|
+
# groups to exclude from the archive.
|
53
|
+
#
|
5
54
|
def initialize(config={})
|
6
55
|
@config = config
|
7
56
|
@config[:app_dir] ||= Dir.pwd
|
8
57
|
@config[:app_name] ||= File.basename(@config[:app_dir])
|
9
58
|
@config[:build_dir] ||= File.join(@config[:app_dir], 'build')
|
10
|
-
@config[:target_dir] ||= @config[:build_dir]
|
11
59
|
@config[:download_dir] ||= File.join(@config[:build_dir], 'downloads')
|
12
60
|
@config[:archive_name] ||= @config[:app_name] + '.tgz'
|
13
61
|
@config[:files] ||= %w[lib/**/*.rb]
|
@@ -17,22 +65,31 @@ module Tara
|
|
17
65
|
@config[:without_groups] ||= %w[development test]
|
18
66
|
end
|
19
67
|
|
68
|
+
# Short for `Archive.new(config).create`
|
69
|
+
#
|
70
|
+
# @return [String] Path to the archive
|
71
|
+
#
|
20
72
|
def self.create(config={})
|
21
73
|
new(config).create
|
22
74
|
end
|
23
75
|
|
76
|
+
|
77
|
+
# Create an archive using the instance's configuration.
|
78
|
+
#
|
79
|
+
# @return [String] Path to the archive
|
80
|
+
#
|
24
81
|
def create
|
25
82
|
Dir.mktmpdir do |tmp_dir|
|
26
83
|
project_dir = Pathname.new(@config[:app_dir])
|
27
84
|
package_dir = Pathname.new(tmp_dir)
|
28
|
-
|
85
|
+
build_dir = Pathname.new(@config[:build_dir])
|
29
86
|
install_dependencies(package_dir, fetcher)
|
30
87
|
copy_source(project_dir, package_dir)
|
31
88
|
copy_executables(project_dir, package_dir)
|
32
89
|
Dir.chdir(tmp_dir) do
|
33
|
-
create_archive(
|
90
|
+
create_archive(build_dir)
|
34
91
|
end
|
35
|
-
File.join(
|
92
|
+
File.join(build_dir, @config[:archive_name])
|
36
93
|
end
|
37
94
|
end
|
38
95
|
|
@@ -53,15 +110,16 @@ module Tara
|
|
53
110
|
Pathname.glob(project_dir.join(executable_glob)).each do |executable|
|
54
111
|
copy_file(project_dir, package_dir, executable)
|
55
112
|
FileUtils.chmod(0755, package_dir.join(executable))
|
56
|
-
|
113
|
+
relative_executable = executable.relative_path_from(project_dir)
|
114
|
+
create_exec_wrapper(package_dir, relative_executable)
|
57
115
|
end
|
58
116
|
end
|
59
117
|
end
|
60
118
|
|
61
|
-
def create_archive(
|
119
|
+
def create_archive(build_dir)
|
62
120
|
Shell.exec('tar -czf %s %s' % [@config[:archive_name], Dir['*'].join(' ')])
|
63
|
-
FileUtils.mkdir_p(
|
64
|
-
FileUtils.cp(@config[:archive_name],
|
121
|
+
FileUtils.mkdir_p(build_dir)
|
122
|
+
FileUtils.cp(@config[:archive_name], build_dir)
|
65
123
|
end
|
66
124
|
|
67
125
|
def fetcher
|
@@ -82,7 +140,7 @@ module Tara
|
|
82
140
|
|
83
141
|
def create_exec_wrapper(package_dir, executable)
|
84
142
|
wrapper_path = package_dir.join(executable.basename)
|
85
|
-
ex = Executable.new(executable.
|
143
|
+
ex = Executable.new(*executable.split)
|
86
144
|
File.open(wrapper_path, 'w') { |f| ex.write(f) }
|
87
145
|
FileUtils.chmod(0755, wrapper_path)
|
88
146
|
end
|
data/lib/tara/archiver.rb
CHANGED
@@ -1,25 +1,80 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
module Tara
|
4
|
+
# Jara compatible Archiver class that makes it easy to release artiftacts using
|
5
|
+
# Tara and Jara.
|
6
|
+
#
|
7
|
+
# @example Release an artifact from a Rake task
|
8
|
+
# task :release do
|
9
|
+
# archiver = Tara::Archiver.new
|
10
|
+
# releaser = Jara::Releaser.new('production', 'artifact-bucket', archiver: archiver)
|
11
|
+
# releaser.release
|
12
|
+
# end
|
13
|
+
#
|
4
14
|
class Archiver
|
5
|
-
|
6
|
-
|
15
|
+
# Create a new instance of `Archiver` with the specified configuration.
|
16
|
+
#
|
17
|
+
# The `Archiver` class supports the same configuration as {Archive#initialize}
|
18
|
+
# does, with the addition of a `:metadata` option.
|
19
|
+
#
|
20
|
+
# @param [Hash] config
|
21
|
+
# @option config [String] :app_dir (Dir.pwd) absolute path to the application
|
22
|
+
# directory.
|
23
|
+
# @option config [String] :app_name (File.basename(@config[:app_dir])) name of
|
24
|
+
# the application.
|
25
|
+
# @option config [String] :build_dir (File.join(@config[:app_dir], 'build'))
|
26
|
+
# the directory where the archive will be created.
|
27
|
+
# @option config [String] :download_dir (File.join(@config[:build_dir], 'downloads'))
|
28
|
+
# the directory where Traveling Ruby artifacts will be downloaded.
|
29
|
+
# @option config [String] :archive_name (@config[:app_name] + '.tgz') name of the archive
|
30
|
+
# @option config [Array<String>] :files (%w[lib/**/*.rb]) list of globs that will be
|
31
|
+
# expanded when including source files in archive. Should be relative from `:app_dir`.
|
32
|
+
# @option config [Array<String>] :executables (%w[bin/*]) list of globs that will be
|
33
|
+
# expanded when including executables in archive. Should be relative from `:app_dir`.
|
34
|
+
# @option config [String] :target (linux-x86_64) target platform that the archive will
|
35
|
+
# be created for. Should be one of "linux-x86", "linux-x86_64", or "osx".
|
36
|
+
# @option config [String] :traveling_ruby_version (20150210) release of Traveling Ruby
|
37
|
+
# that should be used.
|
38
|
+
# @option config [Array<String>] :without_groups (%w[development test]) list of gem
|
39
|
+
# groups to exclude from the archive.
|
40
|
+
# @option config [Hash] :metadata ({}) addidtional metadata that the
|
41
|
+
# published artifact will be tagged with.
|
42
|
+
#
|
43
|
+
def initialize(config={})
|
44
|
+
@config = config
|
45
|
+
@config[:metadata] ||= {}
|
7
46
|
end
|
8
47
|
|
48
|
+
# Create a new archive
|
49
|
+
#
|
50
|
+
# @return [String] Path to the created archive
|
51
|
+
#
|
9
52
|
def create(options={})
|
10
|
-
Archive.create(@
|
53
|
+
Archive.create(@config.merge(options))
|
11
54
|
end
|
12
55
|
|
56
|
+
# Extension used by this archiver
|
57
|
+
#
|
58
|
+
# @return [String] 'tgz'
|
59
|
+
#
|
13
60
|
def extension
|
14
|
-
|
61
|
+
'tgz'
|
15
62
|
end
|
16
63
|
|
64
|
+
# Content type used by this archiver
|
65
|
+
#
|
66
|
+
# @return [String] 'application/x-gzip'
|
67
|
+
#
|
17
68
|
def content_type
|
18
69
|
'application/x-gzip'
|
19
70
|
end
|
20
71
|
|
72
|
+
# Metadata that the published artifact will be tagged with.
|
73
|
+
#
|
74
|
+
# @return [Hash] Hash of key-value pairs that will be used as tags.
|
75
|
+
#
|
21
76
|
def metadata
|
22
|
-
@
|
77
|
+
@config[:metadata]
|
23
78
|
end
|
24
79
|
end
|
25
80
|
end
|
data/lib/tara/cli.rb
CHANGED
data/lib/tara/executable.rb
CHANGED
@@ -1,25 +1,27 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
module Tara
|
4
|
+
# @private
|
4
5
|
class Executable
|
5
|
-
def initialize(name)
|
6
|
+
def initialize(dirpath, name)
|
7
|
+
@dirpath = dirpath
|
6
8
|
@name = name
|
7
9
|
end
|
8
10
|
|
9
11
|
def write(io)
|
10
|
-
io.puts(
|
12
|
+
io.puts(script_template)
|
11
13
|
end
|
12
14
|
|
13
15
|
private
|
14
16
|
|
15
|
-
def
|
17
|
+
def script_template
|
16
18
|
<<-EOH.gsub(/^\s+/, '')
|
17
19
|
#!/bin/bash
|
18
20
|
set -e
|
19
21
|
SELF_DIR=$(dirname "$0")
|
20
22
|
export BUNDLE_GEMFILE="$SELF_DIR/lib/vendor/Gemfile"
|
21
23
|
unset BUNDLE_IGNORE_CONFIG
|
22
|
-
exec "$SELF_DIR/lib/ruby/bin/ruby" -rbundler/setup "$SELF_DIR
|
24
|
+
exec "$SELF_DIR/lib/ruby/bin/ruby" -rbundler/setup "$SELF_DIR/#{@dirpath}/#{@name}" "$@"
|
23
25
|
EOH
|
24
26
|
end
|
25
27
|
end
|
data/lib/tara/fetcher.rb
CHANGED
data/lib/tara/installer.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
3
|
module Tara
|
4
|
+
# @private
|
4
5
|
class Installer
|
5
6
|
def initialize(package_dir, fetcher, options={})
|
6
7
|
@package_dir = package_dir
|
@@ -46,9 +47,9 @@ module Tara
|
|
46
47
|
Dir['vendor/ruby/*/extensions/*'].each do |ext_file|
|
47
48
|
FileUtils.rm_rf(ext_file)
|
48
49
|
end
|
49
|
-
@shell.exec('find vendor/ruby/*/gems -name "*.o" -exec rm {} \; 2
|
50
|
-
@shell.exec('find vendor/ruby/*/gems -name "*.so" -exec rm {} \; 2
|
51
|
-
@shell.exec('find vendor/ruby/*/gems -name "*.bundle" -exec rm {} \; 2
|
50
|
+
@shell.exec('find vendor/ruby/*/gems -name "*.o" -exec rm {} \; 2> /dev/null || true')
|
51
|
+
@shell.exec('find vendor/ruby/*/gems -name "*.so" -exec rm {} \; 2> /dev/null || true')
|
52
|
+
@shell.exec('find vendor/ruby/*/gems -name "*.bundle" -exec rm {} \; 2> /dev/null || true')
|
52
53
|
FileUtils.cp_r('vendor', lib_path, preserve: true)
|
53
54
|
end
|
54
55
|
end
|
@@ -65,7 +66,7 @@ module Tara
|
|
65
66
|
native_gems = find_native_gems
|
66
67
|
native_gems.each do |name, version|
|
67
68
|
gem_archive_path = @fetcher.fetch_native_gem(name, version)
|
68
|
-
@shell.exec
|
69
|
+
@shell.exec(%(tar -xzf #{gem_archive_path} -C #{ruby_vendor_path}))
|
69
70
|
end
|
70
71
|
end
|
71
72
|
|
@@ -106,20 +107,20 @@ module Tara
|
|
106
107
|
|
107
108
|
def strip_leftovers
|
108
109
|
%w[c cpp h rl].each do |ext|
|
109
|
-
@shell.exec(%(find #{ruby_vendor_path} -name "*.#{ext}" -exec rm {} \\; 2
|
110
|
+
@shell.exec(%(find #{ruby_vendor_path} -name "*.#{ext}" -exec rm {} \\; 2> /dev/null))
|
110
111
|
end
|
111
|
-
@shell.exec(%(find #{ruby_vendor_path} -name "extconf.rb" -exec rm {} \\;))
|
112
|
-
@shell.exec(%(find #{vendor_gems_glob.join('*', 'ext')} -name "Makefile" -exec rm {} \\; 2
|
113
|
-
@shell.exec(%(find #{vendor_gems_glob.join('*', 'ext')} -name "tmp" -type d 2
|
112
|
+
@shell.exec(%(find #{ruby_vendor_path} -name "extconf.rb" -exec rm {} \\; 2> /dev/null))
|
113
|
+
@shell.exec(%(find #{vendor_gems_glob.join('*', 'ext')} -name "Makefile" -exec rm {} \\; 2> /dev/null))
|
114
|
+
@shell.exec(%(find #{vendor_gems_glob.join('*', 'ext')} -name "tmp" -type d 2> /dev/null | xargs rm -rf))
|
114
115
|
end
|
115
116
|
|
116
117
|
def strip_java_files
|
117
|
-
@shell.exec(%(find #{vendor_gems_glob} -name "*.java" -exec rm {} \\;))
|
118
|
+
@shell.exec(%(find #{vendor_gems_glob} -name "*.java" -exec rm {} \\; 2> /dev/null))
|
118
119
|
end
|
119
120
|
|
120
121
|
def strip_git_files
|
121
|
-
@shell.exec(%(find #{vendor_gems_glob} -name ".git" -type d | xargs rm -rf))
|
122
|
-
@shell.exec(%(find #{bundler_gems_glob} -name ".git" -type d | xargs rm -rf))
|
122
|
+
@shell.exec(%(find #{vendor_gems_glob} -name ".git" -type d 2> /dev/null | xargs rm -rf))
|
123
|
+
@shell.exec(%(find #{bundler_gems_glob} -name ".git" -type d 2> /dev/null | xargs rm -rf))
|
123
124
|
end
|
124
125
|
|
125
126
|
def strip_from_gems(things)
|
data/lib/tara/shell.rb
CHANGED
data/lib/tara/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tara
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mathias Söderberg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-24 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Tara packs your Ruby app into a standalone archive with gems and a Ruby
|
14
14
|
runtime
|