canzea 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 163c49d9ad9e8ee9760e3bc44c6910205b2b8228
4
+ data.tar.gz: 6c087ffe8c83bcc27281e5d4396e4b57ee4a5063
5
+ SHA512:
6
+ metadata.gz: b857fae076e56661459eb8bac4d00c7eadd1bf036ea9bb3730769503dbe15d861f94dba332d854b09e60540627dda8599c9d9002d91336e878ecfabfe138e8b9
7
+ data.tar.gz: d833b8f0557b7350ea19089a428d420597a4bffcd378f07cc4ee88271240ee1283a74433896ec87046bce57c76b39079f87a2d508e12490372b919a7c8e1b7d5
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
11
+ *.iml
12
+ .idea
13
+ config.json
@@ -0,0 +1,22 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="CompilerConfiguration">
4
+ <resourceExtensions />
5
+ <wildcardResourcePatterns>
6
+ <entry name="!?*.java" />
7
+ <entry name="!?*.form" />
8
+ <entry name="!?*.class" />
9
+ <entry name="!?*.groovy" />
10
+ <entry name="!?*.scala" />
11
+ <entry name="!?*.flex" />
12
+ <entry name="!?*.kt" />
13
+ <entry name="!?*.clj" />
14
+ <entry name="!?*.aj" />
15
+ </wildcardResourcePatterns>
16
+ <annotationProcessing>
17
+ <profile default="true" name="Default" enabled="false">
18
+ <processorPath useClasspath="true" />
19
+ </profile>
20
+ </annotationProcessing>
21
+ </component>
22
+ </project>
@@ -0,0 +1,3 @@
1
+ <component name="CopyrightManager">
2
+ <settings default="" />
3
+ </component>
data/.idea/misc.xml ADDED
@@ -0,0 +1,39 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="MavenImportPreferences">
4
+ <option name="generalSettings">
5
+ <MavenGeneralSettings>
6
+ <option name="mavenHome" value="Bundled (Maven 3)" />
7
+ </MavenGeneralSettings>
8
+ </option>
9
+ </component>
10
+ <component name="ProjectLevelVcsManager" settingsEditedManually="false">
11
+ <OptionsSetting value="true" id="Add" />
12
+ <OptionsSetting value="true" id="Remove" />
13
+ <OptionsSetting value="true" id="Checkout" />
14
+ <OptionsSetting value="true" id="Update" />
15
+ <OptionsSetting value="true" id="Status" />
16
+ <OptionsSetting value="true" id="Edit" />
17
+ <ConfirmationsSetting value="0" id="Add" />
18
+ <ConfirmationsSetting value="0" id="Remove" />
19
+ </component>
20
+ <component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" default="true" assert-keyword="true" jdk-15="true">
21
+ <output url="file://$PROJECT_DIR$/out" />
22
+ </component>
23
+ <component name="masterDetails">
24
+ <states>
25
+ <state key="ProjectJDKs.UI">
26
+ <settings>
27
+ <last-edited>1.8</last-edited>
28
+ <splitter-proportions>
29
+ <option name="proportions">
30
+ <list>
31
+ <option value="0.2" />
32
+ </list>
33
+ </option>
34
+ </splitter-proportions>
35
+ </settings>
36
+ </state>
37
+ </states>
38
+ </component>
39
+ </project>
data/.idea/modules.xml ADDED
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/cli.iml" filepath="$PROJECT_DIR$/cli.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
data/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="" vcs="Git" />
5
+ </component>
6
+ </project>
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.3
5
+ before_install: gem install bundler -v 1.13.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in canzea.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Canzea Technologies
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Canzea
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/canzea`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'canzea'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install canzea
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitLab at https://gitlab.com/canzea/cli.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/canzea ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "canzea"
5
+
6
+
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/canzea.gemspec ADDED
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'canzea/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "canzea"
8
+ spec.version = Canzea::VERSION
9
+ spec.authors = ["Canzea Technologies"]
10
+ spec.email = ["ikethecoder@canzea.com"]
11
+
12
+ spec.summary = %q{Canzea command line interface for orchestrating builds.}
13
+ spec.description = %q{Orchestrate the building of images based on defined ecosystem blueprints.}
14
+ spec.homepage = "http://www.canzea.com"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "bin"
21
+ #spec.executables = ["canzea"]
22
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.13"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "minitest", "~> 5.0"
28
+
29
+ spec.add_runtime_dependency "patron", "~> 0.8"
30
+ spec.add_runtime_dependency "net-ssh", "~> 3.0"
31
+ spec.add_runtime_dependency "net-sftp", "~> 2.1"
32
+ spec.add_runtime_dependency "mustache", "~> 1.0"
33
+ spec.add_runtime_dependency "cri", "~> 2.7"
34
+ spec.add_runtime_dependency "git", "~> 1.3"
35
+ end
data/cli.iml ADDED
@@ -0,0 +1,9 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="WEB_MODULE" version="4">
3
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
4
+ <exclude-output />
5
+ <content url="file://$MODULE_DIR$" />
6
+ <orderEntry type="inheritedJdk" />
7
+ <orderEntry type="sourceFolder" forTests="false" />
8
+ </component>
9
+ </module>
@@ -0,0 +1,23 @@
1
+ module Canzea
2
+
3
+ # Configuration defaults
4
+ @config = {
5
+ :log_level => "verbose",
6
+ :catalog_location => "/opt/canzea-catalog",
7
+ :catalog_git => "git@gitlab.com:canzea/ecosystem-catalog.git",
8
+ :catalog_branch => "develop",
9
+ :git_repo => "/opt/canzea-profile",
10
+ :logging_root => Dir.home()
11
+ }
12
+ @valid_config_keys = @config.keys
13
+
14
+ # Configure through hash
15
+ def self.configure(opts = {})
16
+ opts.each {|k,v| @config[k.to_sym] = v if @valid_config_keys.include? k.to_sym}
17
+ end
18
+
19
+ def self.config
20
+ @config
21
+ end
22
+
23
+ end
@@ -0,0 +1,3 @@
1
+ module Canzea
2
+ VERSION = "0.1.0"
3
+ end
data/lib/canzea.rb ADDED
@@ -0,0 +1,123 @@
1
+ require 'cri'
2
+ require 'fileutils'
3
+ require 'pathname'
4
+ require 'git'
5
+ require "canzea/config"
6
+ require "canzea/version"
7
+ require "helper-run-class"
8
+ require "plan-step-class"
9
+ require "ssh-base-cmd-class"
10
+ require "template-runner"
11
+ require "commands/config-git-commit"
12
+ require "commands/get-catalog"
13
+ require "commands/remote-run"
14
+
15
+ module Canzea
16
+
17
+ command = Cri::Command.define do
18
+ name 'canzea'
19
+ usage 'canzea [options]'
20
+ aliases :ds, :stuff
21
+ summary 'canzea cli'
22
+ description 'Canzea command line interface.'
23
+
24
+ flag :h, :help, 'show help for this command' do |value, cmd|
25
+ puts cmd.help
26
+ exit 0
27
+ end
28
+
29
+ flag nil, :pwd, 'PWD'
30
+
31
+ flag nil, :run, 'Run a step'
32
+ flag nil, :helper, 'Execute a helper'
33
+ flag nil, :remote, 'Remote execution'
34
+ flag nil, :init, 'Remote init execution'
35
+ flag nil, :enable, 'Enable the service'
36
+ flag nil, :config_git_commit, 'Manage configuration files in git'
37
+
38
+ option :s, :stuff, 'specify stuff to do', argument: :required
39
+
40
+ option nil, :config, 'Config', argument: :required
41
+
42
+ option nil, :lifecycle, 'Lifecycle action [install, configure, upgrade, uninstall]', argument: :required
43
+
44
+ option nil, :catalogTag, 'Specific tag of the catalog', argument: :required
45
+ option nil, :gitRoot, 'Git root', argument: :required
46
+ option nil, :role, 'Role', argument: :required
47
+ option nil, :solution, 'Solution', argument: :required
48
+ option nil, :test, 'Test', argument: :required
49
+ option nil, :task, 'Task', argument: :required
50
+ option nil, :serverBase, 'Server Base', argument: :required
51
+ option nil, :serverNumber, 'Server Number', argument: :required
52
+ option nil, :privateKey, 'Task', argument: :required
53
+ option nil, :template, 'Template', argument: :required
54
+
55
+ option nil, :action, 'Helper Action', argument: :required
56
+ option nil, :args, 'Arguments (JSON format)', argument: :required
57
+
58
+ run do |opts, args, cmd|
59
+
60
+ if opts[:config]
61
+ file = File.read(opts[:config])
62
+ Canzea::configure JSON.parse(file)
63
+ end
64
+
65
+ if opts[:pwd]
66
+ puts Dir.pwd
67
+ GetCatalog.new.do(opts.fetch(:catalogTag, nil));
68
+ end
69
+
70
+ if (opts[:lifecycle])
71
+ GetCatalog.new.do(opts.fetch(:catalogTag, nil));
72
+
73
+ lifecycle = opts[:lifecycle]
74
+
75
+ if lifecycle == 'install'
76
+ puts "Running install step #{opts[:role]} #{opts[:solution]}"
77
+ ps = PlanStep.new
78
+ ps.runPhaseInstall opts[:role], opts[:solution], opts.fetch(:test,"false") == "true", Integer(opts.fetch(:task, 1))
79
+
80
+ gitRoot = opts.fetch(:gitRoot, "/opt/cloud-profile")
81
+
82
+ # write to configure the registration of the service
83
+ if (File.exists?("#{gitRoot}/configure.sh") == false)
84
+ File.open("#{gitRoot}/configure.sh", 'a') { |file| file.puts("#!/bin/bash") }
85
+ end
86
+
87
+ File.open("#{gitRoot}/configure.sh", 'a') { |file| file.puts("canzea --enable #{ARGV.join(' ')}") }
88
+ end
89
+
90
+ if lifecycle == 'configure'
91
+ puts "Running configure step #{opts[:role]} #{opts[:solution]}"
92
+ ps = PlanStep.new
93
+ ps.runPhaseConfigure opts[:role], opts[:solution], opts.fetch(:test,"false") == "true", Integer(opts.fetch(:task, 1))
94
+ end
95
+
96
+ if lifecycle == 'wire'
97
+ puts "Running helper #{opts[:solution]} #{opts[:action]}"
98
+ ps = HelperRun.new
99
+ ps.run opts[:solution], opts[:action], opts[:args]
100
+ end
101
+ end
102
+
103
+ if opts[:init]
104
+ publicIp = File.read("vps-#{opts[:serverBase]}-#{opts[:serverNumber]}.json")
105
+ remote = RemoteCall.new
106
+ remote.init publicIp, opts[:privateKey]
107
+ end
108
+
109
+ if opts[:remote]
110
+ RemoteRun.new.do opts[:serverBase], opts[:serverNumber], opts[:privateKey], opts[:role], opts[:solution]
111
+ end
112
+
113
+ if opts[:config_git_commit]
114
+ gitRoot = opts.fetch(:gitRoot, Canzea::config[:git_repo])
115
+ cg = ConfigGitCommit.new
116
+ cg.do gitRoot, args[0], opts[:template], (args.length == 1 ? {}:JSON.parse(args[1]))
117
+ end
118
+ end
119
+ end
120
+
121
+ command.run(ARGV)
122
+
123
+ end
@@ -0,0 +1,38 @@
1
+ require "git"
2
+ require "fileutils"
3
+ require "pathname"
4
+
5
+ class ConfigGitCommit
6
+ def do(gitRoot, sourcePath, template, parameters = {})
7
+ # if file exists on file system and does not exist in gitRoot, then commit the "oem" file
8
+
9
+ dest = "#{gitRoot}/config#{Pathname.new(sourcePath).realpath}"
10
+ puts "Writing to #{dest}"
11
+
12
+ if (File.exist?(dest) == false and File.exist?(sourcePath))
13
+ FileUtils.mkdir_p Pathname.new(dest).dirname
14
+ FileUtils.cp sourcePath, dest
15
+
16
+ puts "Recording in repo the default file first: #{sourcePath}"
17
+ g = Git.init(gitRoot)
18
+ g.add(:all=>true)
19
+ g.commit("Original default #{sourcePath}")
20
+ end
21
+
22
+ if template
23
+ puts "Processing template #{template}"
24
+ FileUtils.mkdir_p Pathname.new(sourcePath).dirname
25
+ t = Template.new
26
+ t.processAndWriteToFile template, sourcePath, JSON.parse(parameters)
27
+ end
28
+ FileUtils.mkdir_p Pathname.new(dest).dirname
29
+ FileUtils.cp sourcePath, dest
30
+
31
+ g = Git.init(gitRoot)
32
+ g.add(:all=>true)
33
+ puts g.status.changed.size() + g.status.added.size()
34
+ if (g.status.changed.size() > 0 or g.status.added.size() > 0)
35
+ g.commit("Config update #{sourcePath}")
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,17 @@
1
+ require "git"
2
+ require "fileutils"
3
+ require "pathname"
4
+
5
+
6
+ class GetCatalog
7
+ def do(tag = nil)
8
+ FileUtils.rm_rf Canzea::config[:catalog_location]
9
+ g = Git.clone(Canzea::config[:catalog_git], "", :path => Canzea::config[:catalog_location])
10
+ g.branch Canzea::config[:catalog_branch]
11
+ if (tag != nil)
12
+ puts "For tag #{tag}"
13
+ g.tag tag
14
+ end
15
+ puts "Branch '#{g.branch}' Commit #{g.log[0]}"
16
+ end
17
+ end
@@ -0,0 +1,12 @@
1
+ require "git"
2
+ require "fileutils"
3
+ require "pathname"
4
+ require "ssh-base-cmd-class"
5
+
6
+ class RemoteRun
7
+ def do(serverBase, serverNumber, privateKey, role, solution)
8
+ publicIp = File.read("vps-#{serverBase}-#{serverNumber}.json")
9
+ remote = RemoteCall.new
10
+ remote.run publicIp, privateKey, "canzea --run --role=#{role} --solution=#{solution}"
11
+ end
12
+ end
@@ -0,0 +1,53 @@
1
+ require 'json'
2
+ require 'logger'
3
+ require "base64"
4
+
5
+ require "prepare-environment"
6
+ require "trace-runner"
7
+
8
+ class HelperRun
9
+ def run (solution, action, parameters)
10
+
11
+ log = Logger.new(Canzea::config[:logging_root] + '/helpers.log')
12
+
13
+ # Type can be either: ruby or shell
14
+ # type = ARGV[0]
15
+ type = "ruby"
16
+
17
+ params = JSON.parse(parameters);
18
+ # If there is context information, then merge them into the parameters before calling the helper
19
+ if (ENV.has_key?('WORK_DIR') and File.exists?ENV['WORK_DIR'] + "/context.json")
20
+ context = JSON.parse(File.read(ENV['WORK_DIR'] + "/context.json"))
21
+ context.keys.each do |key|
22
+ params[key] = context[key]
23
+ end
24
+ end
25
+
26
+ # Make sure the parameters are valid JSON
27
+ parameters = JSON.generate(params)
28
+
29
+ envPush = PrepareEnvironment.new
30
+
31
+ begin
32
+ envScript = ENV['CANZEA_PLUGINS'] + "ike-environments/environment/production/helpers/#{solution}/environment.json"
33
+ if File.exist?(envScript)
34
+ log.info("Adding environment variables...")
35
+ envPush.addToEnv "#{envScript}"
36
+ end
37
+
38
+ r = RunnerWorker.new
39
+
40
+ if (type == "ruby")
41
+ cmd = "ruby #{ENV['CANZEA_PLUGINS']}ike-environments/environment/production/helpers/#{solution}/#{action}.rb '#{parameters}'"
42
+ else
43
+ cmd = "#{ENV['CANZEA_PLUGINS']}ike-environments/environment/production/helpers/#{solution}/#{action}.sh \"#{parameters}\""
44
+ end
45
+ r.run cmd, 1, 1, false
46
+
47
+ rescue => error
48
+ log.error(error.backtrace)
49
+ log.error("Error processing #{error.message}")
50
+ abort("Problem running plan #{error.message}")
51
+ end
52
+ end
53
+ end