openshifter 0.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.2
2
+
3
+ * remote installs
4
+ * configuration options
5
+
1
6
  ## 0.1
2
7
 
3
8
  * first version
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ## OpenShifter
2
2
 
3
- Simple CLI tool to siplify the deployment of Sinatra applications using JRuby to OpenShift
3
+ Simple CLI tool to siplify the deployment of Rack-based applications using JRuby to OpenShift
4
4
 
5
5
  ## How to
6
6
 
@@ -20,7 +20,25 @@ Now you setup your environment
20
20
 
21
21
  openshifter-setup
22
22
 
23
- The tools downloads JRuby and JRuby-Rack to create runtime environment. Then Bundler is instaled locally for the application. The whole environment is vendored for you application.
23
+ This step replaces .openshift folder contaning meta-data for your application.
24
+
25
+ ### Step 4
26
+
27
+ Now you may modify configuration of your deployment. It is stored in .openshift/openshifter. It is ordinary YAML file. Possible options are
28
+
29
+ jruby: 1.6.6 # JRuby version you want to use
30
+ jrack: 1.1.3 # JRuby-Rack version used
31
+ install: vendor # Instalation method vendor/remote
32
+
33
+ Vendor instalation method installs all libraries and gems in .openshift folder and are versioned with your application. Remote installation installed all libraries and gems on server in the time of deployment.
34
+
35
+ If you decide to use remote installation method. You are done. For vendor installation method, please continue.
36
+
37
+ ### Step 5
38
+
39
+ Downloads JRuby and JRuby-Rack to create runtime environment. Then Bundler is instaled locally for the application.
40
+
41
+ openshifter-download
24
42
 
25
43
  ### Step 4
26
44
 
@@ -28,18 +46,50 @@ At the setup time and whenever you add gems to your Gemfile, just run
28
46
 
29
47
  openshifter-bundle
30
48
 
31
- to vendor your gems locally.
49
+ gems will be venoder in .openshift folder and you have to add them to VCS.
32
50
 
33
51
  ### Step 5
34
52
 
35
53
  Add, commit and push to openshift.
36
54
 
55
+ ## Upgrading
56
+
57
+ ### OpenShifter
58
+
59
+ For remote install just run
60
+
61
+ openshifter-setup --upgrade
62
+
63
+ for vendored install it's more complicated
64
+
65
+ openshifter-setup --upgrade
66
+ openshifter-download
67
+ openshifter-bundle
68
+
69
+ **will be simplified in the future version**
70
+
71
+ ### JRuby
72
+
73
+ For remote install, just modify .openshift/openshifter configuration.
74
+
75
+ For vendor install modify .openshift/openshifter configuration and then run.
76
+
77
+ openshifter-download
78
+
37
79
  ## Interface
38
80
 
39
81
  Setup the environment
40
82
 
41
83
  openshifter-setup
42
84
 
85
+ To upgrade openshifter
86
+
87
+ openshifter-setup --upgrade
88
+
89
+ Download JRuby and environment libraries
90
+
91
+ openshifter-download
92
+
43
93
  Bundler wrapper
44
94
 
45
95
  openshifter-bundle
@@ -70,4 +120,4 @@ Unless required by applicable law or agreed to in writing, software
70
120
  distributed under the License is distributed on an "AS IS" BASIS,
71
121
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
72
122
  See the License for the specific language governing permissions and
73
- limitations under the License.
123
+ limitations under the License.
data/ROADMAP.md CHANGED
@@ -1,4 +1,4 @@
1
1
  ## Expected features
2
2
 
3
- * add possibilty to download JRuby on OpenShift instead of vendoring
3
+ * clean up the code
4
4
  * ensure compatibility with other frameworks (Rails)
@@ -1,4 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
2
  require File.expand_path('../../lib/openshifter/init', __FILE__)
3
3
 
4
- exec("java -jar .openshift/lib/jruby.jar -S bundle #{$*.join(' ')}")
4
+ if CONFIG['install'] == 'remote'
5
+ puts '-> Can not be used with remote install.'
6
+ exit(0)
7
+ end
8
+
9
+ exec("java -jar .openshift/lib/jruby-#{CONFIG['jruby']}.jar -S bundle #{$*.join(' ')}")
@@ -1,6 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
2
  require File.expand_path('../../lib/openshifter/init', __FILE__)
3
3
 
4
+ if CONFIG['install'] == 'remote'
5
+ puts '-> Can not be used with remote install.'
6
+ exit(0)
7
+ end
8
+
4
9
  puts '-> Removing jRuby'
5
10
  `rm -rf .openshift/lib`
6
11
 
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ require File.expand_path('../../lib/openshifter/init', __FILE__)
3
+
4
+ if CONFIG['install'] == 'remote'
5
+ puts '-> Can not be used with remote install.'
6
+ exit(0)
7
+ end
8
+
9
+ puts "-> Downloading jRuby #{CONFIG['jruby']}"
10
+ `curl -o .openshift/lib/jruby-#{CONFIG['jruby']}.jar "http://jruby.org.s3.amazonaws.com/downloads/#{CONFIG['jruby']}/jruby-complete-#{CONFIG['jruby']}.jar"`
11
+
12
+ puts "-> Downloading jRuby-Rack #{CONFIG['jrack']}"
13
+ `curl -o .openshift/lib/jruby-rack.jar "http://repository.codehaus.org/org/jruby/rack/jruby-rack/#{CONFIG['jrack']}/jruby-rack-#{CONFIG['jrack']}.jar"`
14
+
15
+ puts '-> Installing Bundler'
16
+ puts `java -jar .openshift/lib/jruby-#{CONFIG['jruby']}.jar -S gem install bundler --no-ri --no-rdoc`
data/bin/openshifter-gem CHANGED
@@ -1,4 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
2
  require File.expand_path('../../lib/openshifter/init', __FILE__)
3
3
 
4
- exec("java -jar .openshift/lib/jruby.jar -S gem #{$*.join(' ')}")
4
+ if CONFIG['install'] == 'remote'
5
+ puts '-> Can not be used with remote install.'
6
+ exit(0)
7
+ end
8
+
9
+ exec("java -jar .openshift/lib/jruby-#{CONFIG['jruby']}.jar -S gem #{$*.join(' ')}")
data/bin/openshifter-ruby CHANGED
@@ -1,4 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
2
  require File.expand_path('../../lib/openshifter/init', __FILE__)
3
3
 
4
- exec("java -jar .openshift/lib/jruby.jar #{$*.join(' ')}")
4
+ if CONFIG['install'] == 'remote'
5
+ puts '-> Can not be used with remote install.'
6
+ exit(0)
7
+ end
8
+
9
+ exec("java -jar .openshift/lib/jruby-#{CONFIG['jruby']}.jar #{$*.join(' ')}")
@@ -1,28 +1,29 @@
1
1
  #!/usr/bin/env ruby
2
2
  require File.expand_path('../../lib/openshifter/init', __FILE__)
3
3
 
4
+ if File.exists?('.openshift/openshifter') and !ARGV.include?('--upgrade')
5
+ puts '-> You are already set up.'
6
+ exit(0)
7
+ end
8
+
4
9
  unless File.exists?('.openshift/openshifter')
5
- puts '-> Removing default .openshift directory'
6
- FileUtils.rm_rf('.openshift')
7
-
8
- puts '-> Copying openshifter .openshift direcotry'
9
- FileUtils.cp_r(File.expand_path('../../templates/openshift', __FILE__), '.openshift')
10
-
11
- puts '-> Cleaning other default mess'
12
- FileUtils.rm_rf('src')
13
- FileUtils.rm_rf('pom.xml')
14
- FileUtils.rm_rf('README')
10
+ puts '-> Cleaning default mess'
11
+ FileUtils.rm_rf('src')
12
+ FileUtils.rm_rf('pom.xml')
13
+ FileUtils.rm_rf('README')
14
+ FileUtils.rm_rf('deployments')
15
+ else
16
+ config = File.read('.openshift/openshifter')
15
17
  end
16
18
 
17
- unless File.exists?('.openshift/lib/jruby.jar')
18
- puts "-> Downloading jRuby"
19
- `curl -o .openshift/lib/jruby.jar "http://jruby.org.s3.amazonaws.com/downloads/1.6.6/jruby-complete-1.6.6.jar"`
20
- end
19
+ puts '-> Removing .openshift directory'
20
+ FileUtils.rm_rf('.openshift')
21
+
22
+ puts '-> Copying .openshift directory'
23
+ FileUtils.cp_r(File.expand_path('../../templates/openshift', __FILE__), '.openshift')
21
24
 
22
- unless File.exists?('.openshift/lib/jruby-rack.jar')
23
- puts "-> Downloading jRuby-Rack"
24
- `curl -o .openshift/lib/jruby-rack.jar "http://repository.codehaus.org/org/jruby/rack/jruby-rack/1.1.3/jruby-rack-1.1.3.jar"`
25
+ File.open('.openshift/openshifter', 'w') do |file|
26
+ file.print(config)
25
27
  end
26
28
 
27
- puts '-> Installing Bundler'
28
- puts `java -jar .openshift/lib/jruby.jar -S gem install bundler --no-ri --no-rdoc`
29
+ puts '-> You may change the configuration in .openshift/openshifter file.'
@@ -1,8 +1,27 @@
1
1
  require 'fileutils'
2
+ require 'yaml'
3
+
4
+ $: << File.expand_path('../..', __FILE__)
2
5
 
3
6
  unless File.exists?('.openshift')
4
7
  puts '--> Invalid direcotry - no .openshift directory'
5
8
  exit(1)
9
+ else
10
+ data = File.exists?('.openshift/openshifter') ? YAML.load_file('.openshift/openshifter') : nil
11
+ data = {} unless data
12
+ CONFIG = data
6
13
  end
7
14
 
8
- ENV['GEM_PATH'] = ENV['GEM_HOME'] = File.expand_path('.openshift/gems')
15
+ CONFIG['jruby'] ||= '1.6.6'
16
+ CONFIG['jrack'] ||= '1.1.3'
17
+ CONFIG['install'] ||= 'vendor'
18
+
19
+ ENV['GEM_PATH'] = ENV['GEM_HOME'] = File.expand_path('.openshift/gems')
20
+
21
+ def run(cmd)
22
+ io = IO.popen(cmd)
23
+ io.each do |line|
24
+ puts "*> #{line}"
25
+ end
26
+ Process.wait(io.pid)
27
+ end
@@ -1,3 +1,3 @@
1
1
  module OpenShifter
2
- VERSION = '0.1' unless const_defined?(:VERSION)
2
+ VERSION = '0.2' unless const_defined?(:VERSION)
3
3
  end
@@ -1,16 +1,39 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ $stdout.sync = true
4
+
3
5
  require 'fileutils'
6
+ require 'yaml'
7
+ require 'digest'
4
8
 
5
9
  FileUtils.cd(ENV['OPENSHIFT_REPO_DIR'])
6
10
 
11
+ data = YAML.load_file('.openshift/openshifter')
12
+ data = {} unless data
13
+ CONFIG = data
14
+
15
+ CONFIG['jruby'] ||= '1.6.6'
16
+ CONFIG['install'] ||= 'vendor'
17
+ CONFIG['jrack'] ||= '1.1.3'
18
+
7
19
  ROOT=File.join(ENV['OPENSHIFT_REPO_DIR'], 'deployments')
8
20
  TARGET = File.join(ROOT, 'application.war')
9
21
  TARGET_META = File.join(TARGET, 'META-INF')
10
22
  TARGET_WEB = File.join(TARGET, 'WEB-INF')
11
23
 
12
- puts '-> Cleaning target'
24
+ libs = File.join(ENV['OPENSHIFT_DATA_DIR'], 'jruby', 'libs')
25
+ gems = case CONFIG['install']
26
+ when 'vendor'
27
+ File.expand_path('.openshift/gems')
28
+ when 'remote'
29
+ File.join(ENV['OPENSHIFT_DATA_DIR'], 'jruby', 'gems')
30
+ end
31
+ jruby = File.join(libs, "jruby-#{CONFIG['jruby']}.jar")
32
+ jrack = File.join(libs, "jruby-rack-#{CONFIG['jrack']}.jar")
33
+ gemfile_hash = File.join(ENV['OPENSHIFT_DATA_DIR'], 'jruby', 'Gemfile.hash')
34
+ ENV['GEM_PATH'] = ENV['GEM_HOME'] = gems
13
35
 
36
+ puts '-> Cleaning target'
14
37
  FileUtils.rm_rf(ROOT)
15
38
 
16
39
  puts '-> Creating target'
@@ -34,7 +57,7 @@ end
34
57
  puts '--> init.rb'
35
58
  File.open(File.join(TARGET_META, 'init.rb'), 'w') do |file|
36
59
  data = <<EOF
37
- ENV['GEM_HOME'] ||= $servlet_context.getRealPath('/WEB-INF/gems')
60
+ ENV['GEM_HOME'] ||= '#{gems}'
38
61
  ENV['BUNDLE_GEMFILE'] = 'Gemfile'
39
62
  ENV['RACK_ENV'] = 'production'
40
63
  require 'psych.rb' # Hack for Ruby 1.6.6
@@ -52,14 +75,59 @@ app.delete('public')
52
75
  app.delete('deployments')
53
76
  FileUtils.cp_r(app, TARGET_WEB)
54
77
 
55
- puts '--> Gems'
56
- FileUtils.cp_r('.openshift/gems', File.join(TARGET_WEB, 'gems'))
57
-
58
78
  puts '--> Lib'
59
79
  FileUtils.mkdir_p(File.join(TARGET_WEB, 'lib'))
60
80
 
61
81
  puts '--> Copy runtime'
62
- FileUtils.cp(Dir.glob('.openshift/lib/*.jar'), File.join(TARGET_WEB, 'lib'))
82
+ case CONFIG['install']
83
+ when 'vendor'
84
+ FileUtils.cp(Dir.glob('.openshift/lib/*.jar'), File.join(TARGET_WEB, 'lib'))
85
+ when 'remote'
86
+ FileUtils.mkdir_p(libs)
87
+ FileUtils.mkdir_p(gems)
88
+ unless File.exists?(jruby)
89
+ Dir.glob(File.join(libs, "jruby-*")) do |file|
90
+ FileUtils.rm(file)
91
+ end
92
+ puts "---> Downloading jRuby #{CONFIG['jruby']}"
93
+ puts `curl -o #{jruby} "http://jruby.org.s3.amazonaws.com/downloads/#{CONFIG['jruby']}/jruby-complete-#{CONFIG['jruby']}.jar"`
94
+ end
95
+ unless File.exists?(jrack)
96
+ Dir.glob(File.join(libs, "jruby-rack-*")) do |file|
97
+ FileUtils.rm(file)
98
+ end
99
+ puts "---> Downloading jRuby-Rack #{CONFIG['jrack']}"
100
+ puts `curl -o #{jrack} "http://repository.codehaus.org/org/jruby/rack/jruby-rack/#{CONFIG['jrack']}/jruby-rack-#{CONFIG['jrack']}.jar"`
101
+ end
102
+ puts '---> Copying libraries'
103
+ FileUtils.cp(Dir.glob(File.join(libs, '*.jar')), File.join(TARGET_WEB, 'lib'))
104
+ else
105
+ puts '---> Unsupported installation.'
106
+ end
107
+
108
+ puts '--> Gems'
109
+ case CONFIG['install']
110
+ when 'vendor'
111
+ # No actions needed
112
+ when 'remote'
113
+ gemfile = Digest::SHA256.file('Gemfile').hexdigest
114
+ oldhash = File.exists?(gemfile_hash) ? File.read(gemfile_hash) : ''
115
+ unless gemfile == oldhash
116
+ puts '---> Cleaning gems'
117
+ FileUtils.rm_rf(gems)
118
+ puts '---> Installing Bundler'
119
+ io = IO.popen("java -jar #{jruby} -S gem install bundler --no-ri --no-rdoc")
120
+ io.each_line { |line| puts "----> #{line}"}
121
+ Process.wait(io.pid)
122
+ puts "---> Bundling gems"
123
+ io = IO.popen("java -Xmx384m -Xss512k -XX:+UseCompressedOops -jar #{jruby} -S bundle install")
124
+ io.each_line { |line| puts "----> #{line}"}
125
+ Process.wait(io.pid)
126
+ File.open(gemfile_hash, 'w') { |file| file.print(gemfile) }
127
+ end
128
+ else
129
+ puts '---> Unsupported installation.'
130
+ end
63
131
 
64
132
  puts '--> jboss-web.xml'
65
133
  File.open(File.join(TARGET_WEB, 'jboss-web.xml'), 'w') do |file|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openshifter
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.2'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-17 00:00:00.000000000 Z
12
+ date: 2012-02-19 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Simplify deployments of Sinatra applications using JRuby to OpenShift
15
15
  email:
@@ -17,6 +17,7 @@ email:
17
17
  executables:
18
18
  - openshifter-bundle
19
19
  - openshifter-clean
20
+ - openshifter-download
20
21
  - openshifter-gem
21
22
  - openshifter-ruby
22
23
  - openshifter-setup
@@ -25,6 +26,7 @@ extra_rdoc_files: []
25
26
  files:
26
27
  - bin/openshifter-bundle
27
28
  - bin/openshifter-clean
29
+ - bin/openshifter-download
28
30
  - bin/openshifter-gem
29
31
  - bin/openshifter-ruby
30
32
  - bin/openshifter-setup