oo-cartridge-tools 0.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,4 +1,9 @@
1
- # OpenShift Cartridge Lint
1
+ # OpenShift Cartridge Tools
2
+
3
+ This is a set of tools that makes the OpenShift cartridge/quickstart developers
4
+ life easier.
5
+
6
+ ## oo-cartridge-lint
2
7
 
3
8
  The OpenShift Cartridge Lint is an utility which helps developers to test
4
9
  the validity and syntax of the cartridge metadata.
@@ -9,23 +14,6 @@ you haven't missed some required attribute or you not made the syntax error.
9
14
 
10
15
  ## Using oo-cartridge-lint
11
16
 
12
- ### Dependencies:
13
-
14
- * [kwalify](http://www.kuwata-lab.com/kwalify)
15
- * [commander](http://visionmedia.github.io/commander)
16
-
17
- (Don't worry, these dependencies are installed automatically for you)
18
-
19
- ### Installation:
20
-
21
- ```
22
- $ gem install oo-cartridge-lint
23
- ```
24
-
25
- (the Fedora/RHEL packages are TBD)
26
-
27
- ### Usage:
28
-
29
17
  To check your current cartridge, you can run the following command:
30
18
 
31
19
  ```
@@ -44,3 +32,33 @@ sample output might look like this:
44
32
  ```
45
33
 
46
34
  (Note: The --file option is optional, by default the command will check the `metadata/manifest.yml` path.
35
+
36
+ ## oo-cartridge-create
37
+
38
+ This command will create and prepare directory with DIY cartridge. It is
39
+ basically a bootstrap script for the new cartridge.
40
+
41
+ ## Using oo-cartridge-create
42
+
43
+ ```
44
+ $ oo-cartridge-create diy --name openshift-sidekiq-cartridge
45
+ Cartridge-Short-Name (eg. "redis"): sidekiq
46
+ Version: 1.0
47
+ The './openshift-sidekiq-cartridge/' cartridge was succesfully created...
48
+ ```
49
+
50
+ The 'openshift-sidekiq-cartridge' directory will then contain a DIY cartridge
51
+ bootstrap and you could start adding your code into it.
52
+
53
+ ### Dependencies:
54
+
55
+ * [kwalify](http://www.kuwata-lab.com/kwalify)
56
+ * [commander](http://visionmedia.github.io/commander)
57
+
58
+ (Don't worry, these dependencies are installed automatically for you)
59
+
60
+ ### Installation:
61
+
62
+ ```
63
+ $ gem install oo-cartridge-tools
64
+ ```
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'commander/import'
5
+
6
+ require_relative '../lib/openshift/cartridge_tools'
7
+
8
+ program :name, 'OpenShift DIY cartridge creator'
9
+ program :version, '1.0.0'
10
+ program :description, 'Bootstrap a new DIY cartridge'
11
+
12
+ command :diy do |c|
13
+ c.syntax = 'diy'
14
+ c.description = 'Create new cartridge based on the official OpenShift DIY cartridge'
15
+ c.option '--name NAME', String, 'Name of the new cartridge (eg. openshift-redis-cartridge)'
16
+
17
+ c.action do |_, options|
18
+ unless options.name
19
+ say "ERROR: Please specify the cartridge name using --name option."
20
+ exit(255)
21
+ end
22
+ OpenShift::CartridgeTools::Diy.init_cartridge_dir(options.name)
23
+ opts = {}
24
+ opts[:short_name] = ask('Cartridge-Short-Name (eg. "redis"): ')
25
+ opts[:version] = ask('Version: ')
26
+ OpenShift::CartridgeTools::Diy.parse_bin(options.name, opts)
27
+ OpenShift::CartridgeTools::Diy.parse_docs(options.name, opts)
28
+ OpenShift::CartridgeTools::Diy.parse_spec(options.name, opts)
29
+ OpenShift::CartridgeTools::Diy.parse_manifest(options.name, opts)
30
+ OpenShift::CartridgeTools::Diy.git_keep(options.name)
31
+ say "The './#{options.name}/' cartridge was succesfully created..."
32
+ end
33
+
34
+ end
@@ -3,7 +3,7 @@
3
3
  require 'rubygems'
4
4
  require 'commander/import'
5
5
 
6
- require_relative '../lib/openshift/cartridge_utils'
6
+ require_relative '../lib/openshift/cartridge_tools'
7
7
 
8
8
  program :name, 'OpenShift cartridge lint'
9
9
  program :version, '1.0.0'
@@ -16,9 +16,9 @@ command :manifest do |c|
16
16
  c.option '--schema STRING', String, 'Override the manifest.yaml kwalify schema'
17
17
 
18
18
  c.action do |_, options|
19
- manifest_file = OpenShift::CartridgeUtils::Lint.guess_manifest_path(options.file)
20
- schema_file = OpenShift::CartridgeUtils::Lint.guess_schema_path(options.schema)
21
- result = OpenShift::CartridgeUtils::Lint.parse(manifest_file, schema_file)
19
+ manifest_file = OpenShift::CartridgeTools::Lint.guess_manifest_path(options.file)
20
+ schema_file = OpenShift::CartridgeTools::Lint.guess_schema_path(options.schema)
21
+ result = OpenShift::CartridgeTools::Lint.parse(manifest_file, schema_file)
22
22
  if result.errors?
23
23
  say "[#{manifest_file}] INVALID"
24
24
  result.errors.each { |e| say " [#{e.path}] - #{e.message}" }
@@ -1,5 +1,6 @@
1
1
  module OpenShift
2
2
  module CartridgeTools
3
3
  require_relative './cartridge_tools/lint'
4
+ require_relative './cartridge_tools/diy'
4
5
  end
5
6
  end
@@ -0,0 +1,73 @@
1
+ require 'fileutils'
2
+ require 'erb'
3
+
4
+ module OpenShift
5
+ module CartridgeTools
6
+ class Diy
7
+
8
+ TEMPLATE_DIR = File.join(File.dirname(__FILE__), '..', '..', '..', 'schema', 'templates', 'diy')
9
+
10
+ def self.init_cartridge_dir(directory_name)
11
+ FileUtils.mkdir_p(directory_name)
12
+ Dir.chdir(directory_name) do
13
+ ['bin', 'configuration/etc/conf.d', 'env', 'hooks', 'metadata', 'usr'].each do |f|
14
+ FileUtils.mkdir_p(f)
15
+ end
16
+ end
17
+ end
18
+
19
+ def self.parse_bin(directory_name, options={})
20
+ Dir.chdir(directory_name) do
21
+ control_template = ERB.new(File.read(File.join(TEMPLATE_DIR, 'bin/control.erb')))
22
+ File.open('bin/control', 'w') { |f| f.write(control_template.result(binding)) }
23
+ FileUtils.chmod(0755, 'bin/control')
24
+ setup_template = ERB.new(File.read(File.join(TEMPLATE_DIR, 'bin/setup.erb')))
25
+ File.open('bin/setup', 'w') { |f| f.write(setup_template.result(binding)) }
26
+ FileUtils.chmod(0755, 'bin/setup')
27
+ end
28
+ end
29
+
30
+ def self.parse_docs(directory_name, options={})
31
+ Dir.chdir(directory_name) do
32
+ FileUtils.cp(File.join(TEMPLATE_DIR, 'COPYRIGHT'), '.')
33
+ FileUtils.cp(File.join(TEMPLATE_DIR, 'LICENSE'), '.')
34
+ File.open('README.md', 'w') { |f| f.write("#{options[:short_name].capitalize} OpenShift Cartridge") }
35
+ end
36
+ end
37
+
38
+ def self.parse_spec(directory_name, options={})
39
+ Dir.chdir(directory_name) do
40
+ spec_template = ERB.new(File.read(File.join(TEMPLATE_DIR, 'openshift-diy-cartridge.spec.erb')))
41
+ File.open("#{directory_name}.spec", 'w') { |f| f.write(spec_template.result(binding)) }
42
+ end
43
+ end
44
+
45
+ def self.parse_manifest(directory_name, options={})
46
+ Dir.chdir(directory_name) do
47
+ manifest = YAML::load_file(File.join(TEMPLATE_DIR, 'metadata', 'manifest.yml'))
48
+ manifest.merge!({
49
+ 'Name' => options[:short_name],
50
+ 'Cartridge-Short-Name' => options[:short_name].upcase,
51
+ 'Version' => options[:version],
52
+ 'Cartridge-Version' => '0.0.1',
53
+ 'Compatible-Versions' => [],
54
+ 'Cart-Data' => [],
55
+ 'Provides' => [ options[:short_name], "#{options[:short_name]}-#{options[:version]}"]
56
+ })
57
+ File.write('metadata/manifest.yml', YAML::dump(manifest))
58
+ FileUtils.cp(File.join(TEMPLATE_DIR, 'metadata/managed_files.yml'), 'metadata/')
59
+ end
60
+ end
61
+
62
+ def self.git_keep(directory_name)
63
+ Dir.chdir(directory_name) do
64
+ FileUtils.touch('env/.gitkeep')
65
+ FileUtils.touch('configuration/etc/conf.d/.gitkeep')
66
+ FileUtils.touch('hooks/.gitkeep')
67
+ FileUtils.touch('usr/.gitkeep')
68
+ end
69
+ end
70
+
71
+ end
72
+ end
73
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oo-cartridge-tools
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:
@@ -48,12 +48,15 @@ email:
48
48
  - mfojtik@redhat.com
49
49
  executables:
50
50
  - oo-cartridge-lint
51
+ - oo-cartridge-create
51
52
  extensions: []
52
53
  extra_rdoc_files: []
53
54
  files:
54
55
  - lib/openshift/cartridge_tools.rb
55
56
  - lib/openshift/cartridge_tools/lint.rb
57
+ - lib/openshift/cartridge_tools/diy.rb
56
58
  - bin/oo-cartridge-lint
59
+ - bin/oo-cartridge-create
57
60
  - schema/manifest_schema_20130929.yml
58
61
  - README.md
59
62
  homepage: https://github.com/mfojtik/oo-cartridge-tools