Skip to content

Commit d6fe681

Browse files
committed
Add deployment packaging task
1 parent 660122c commit d6fe681

15 files changed

+392
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@
1212
*.o
1313
*.a
1414
mkmf.log
15+
/distro

.ruby-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2.1.5

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
language: ruby
2+
env:
3+
- CI=true
24
sudo: true
35
before_install:
46
- gem update --system

Rakefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
Dir[File.join(Dir.pwd, 'tasks', '**', '*.rb')].each { |f| require f }
2+
Dir[File.join(Dir.pwd, 'tasks', '*.rake')].each { |f| load f }
3+
14
require 'bundler/gem_tasks'
25
require 'open-uri'
36
require 'fileutils'
@@ -11,6 +14,13 @@ RSpec::Core::RakeTask.new :spec do |task|
1114
task.rspec_opts = '--format documentation'
1215
end
1316

17+
Distrubution.configure do |config|
18+
config.package_name = 'octodown'
19+
config.version = Octodown::VERSION
20+
config.rb_version = '20141215-2.1.5'
21+
config.packaging_dir = "#{Octodown.root}/packaging"
22+
end
23+
1424
task :default => [:spec, :rubocop]
1525

1626
task :styles do

octodown.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ Gem::Specification.new do |spec|
2929
spec.add_development_dependency 'rubocop', '~> 0.28.0'
3030
spec.add_development_dependency 'bundler', '~> 1.7'
3131
spec.add_development_dependency 'rake', '~> 10.0'
32+
spec.add_development_dependency 'octokit'
3233
end

packaging/wrapper.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# Figure out where this script is located.
5+
SELFDIR="`dirname \"$0\"`"
6+
SELFDIR="`cd \"$SELFDIR\" && pwd`"
7+
8+
# Tell Bundler where the Gemfile and gems are.
9+
export BUNDLE_GEMFILE="$SELFDIR/lib/app/Gemfile"
10+
unset BUNDLE_IGNORE_CONFIG
11+
12+
# Run the actual app using the bundled Ruby interpreter.
13+
exec "$SELFDIR/lib/ruby/bin/ruby" -rbundler/setup "$SELFDIR/lib/app/bin/octodown" "$@"

tasks/distrubution/configuration.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module Distrubution
2+
class << self
3+
attr_accessor :configuration
4+
end
5+
6+
def self.configure
7+
self.configuration ||= Configuration.new
8+
yield configuration
9+
end
10+
11+
class Configuration
12+
attr_accessor :package_name, :packaging_dir, :version, :rb_version
13+
end
14+
end

tasks/distrubution/executable.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Dir[File.join(Dir.pwd, 'tasks', '**', '*.rb')].each { |f| require f }
2+
3+
module Distrubution
4+
class Executable
5+
attr_reader :package
6+
7+
include PackageHelpers
8+
9+
def initialize(package)
10+
@package = package
11+
end
12+
13+
def self.create(dir)
14+
executable = new(dir)
15+
executable.copy_wrapper
16+
executable
17+
end
18+
19+
def copy_wrapper
20+
print_to_console 'Creating exexutable...'
21+
22+
FileUtils.cp(
23+
'packaging/wrapper.sh',
24+
"#{package.dir}/#{Distrubution.configuration.package_name}"
25+
)
26+
end
27+
end
28+
end

tasks/distrubution/package.rb

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
require 'fileutils'
2+
require 'octodown'
3+
4+
Dir[File.join(Dir.pwd, 'tasks', '**', '*.rb')].each { |f| require f }
5+
6+
module Distrubution
7+
class Package
8+
include PackageHelpers
9+
10+
attr_reader :arch, :dir, :tarball, :version, :rb_version, :package
11+
12+
def initialize(arch)
13+
abort 'Ruby 2.1.x required' if RUBY_VERSION !~ /^2\.1\./
14+
15+
@arch = arch
16+
@version = Distrubution.configuration.version
17+
@rb_version = Distrubution.configuration.rb_version
18+
@dir = "#{Distrubution.configuration.package_name}-" \
19+
"#{version}-#{arch}"
20+
@package = self
21+
end
22+
23+
def self.create(args)
24+
new(*args).build
25+
end
26+
27+
def build
28+
initialize_install_dir
29+
download_octodown
30+
remove_unneccesary_files
31+
install_ruby_and_gems
32+
create_executable
33+
post_cleanup
34+
@tarball = create_tarball
35+
end
36+
37+
private
38+
39+
def post_cleanup
40+
print_to_console 'Cleaning up...'
41+
42+
files = [
43+
"#{Distrubution.configuration.packaging_dir}/" \
44+
"traveling-ruby-#{rb_version}-#{arch}.tar.gz"
45+
]
46+
47+
files.each { |file| FileUtils.rm file if File.exist? file }
48+
end
49+
50+
def create_tarball
51+
Tarball.create self
52+
end
53+
54+
def create_executable
55+
Executable.create self
56+
end
57+
58+
def install_ruby_and_gems
59+
TravellingRuby.install self
60+
end
61+
62+
def remove_unneccesary_files
63+
FileUtils.cd "#{dir}/lib/app" do
64+
FileUtils.remove_dir '.git', true
65+
FileUtils.remove_dir 'spec', true
66+
end
67+
end
68+
69+
def initialize_install_dir
70+
FileUtils.cd Octodown.root do
71+
FileUtils.remove_dir(dir, true) if File.exist? dir
72+
FileUtils.mkdir_p "#{dir}/lib/app"
73+
end
74+
end
75+
76+
def download_octodown
77+
print_to_console 'Downloading octodown...'
78+
tar = "v#{version}.tar.gz"
79+
80+
FileUtils.cd "#{dir}/lib/app" do
81+
curl "https://github.com/ianks/octodown/archive/#{tar}"
82+
system "tar --strip-components=1 -xzf #{tar} " \
83+
'&> /dev/null'
84+
FileUtils.rm tar if File.exist? tar
85+
end
86+
end
87+
end
88+
end

tasks/distrubution/package_helpers.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module Distrubution
2+
module PackageHelpers
3+
def curl(file)
4+
system "curl -L -O --fail --silent #{file}"
5+
end
6+
7+
def print_to_console(msg)
8+
arch = package.arch
9+
puts "[#{arch}]:" + ' ' * (16 - arch.size) + '=>' + ' ' + msg
10+
end
11+
end
12+
end

0 commit comments

Comments
 (0)