soaring 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 334c777312a5924c3a86961818e299c3ade61414
4
- data.tar.gz: 4dacc30d2aa57112f3f8881b4fad28c8febfe8f0
3
+ metadata.gz: c92f7a6394523135d5eac0f85fd640670792229c
4
+ data.tar.gz: e1fefdb6535ba47777394b7213989c8173dc1a14
5
5
  SHA512:
6
- metadata.gz: 2582c5799ad54dbd94100b2c53695e8fecd4fc3d11d1bb9ed2abb4e03ace8c2917c6d5ecd01ad6933733068e0202a72738a1d9f836ccc4f7327382353f37adca
7
- data.tar.gz: ee563cb9d38c8b17b4093fcbf921990b01390a266222b4beb5e69f6161e777273df85fc827f5a653c01b97dbee1de101727687d32804bde4a2f62c64dff73fcd
6
+ metadata.gz: 539b505930db2610f2b496d4a8137b3f4ba048c597511bd99f45d74b9f1cfae5db50039ef9f3b1ecab01d867d8046e87f35daf8edf59c939c7f097b6bbc80974
7
+ data.tar.gz: 9a469dd997a9c667ac66a1df38bdf86fcbe93a025f6c915a0e4c94a3843225ef900b7ffec7a24b3cdcc1b34ab6791a7c575e10fc2fae93b52d4bf85d3c213e0e
data/README.md CHANGED
@@ -10,6 +10,17 @@ Add this line to your application's Gemfile:
10
10
  gem 'soaring'
11
11
  ```
12
12
 
13
+ ## Creating a new project
14
+
15
+ Create the fresh project skeleton:
16
+ $ soaring init
17
+
18
+ Create an environment.yml file by copying the example:
19
+ $ cp config/environment.yml.example config/environment.yml
20
+
21
+ Start up a local instance of the service component to check that all is well
22
+ $ soaring run
23
+
13
24
  ## Contributing
14
25
 
15
26
  Bug reports and feature requests are welcome by email to barney dot de dot villiers at hetzner dot co dot za. This gem is sponsored by Hetzner (Pty) Ltd (http://hetzner.co.za)
data/lib/soaring/cli.rb CHANGED
@@ -1,7 +1,84 @@
1
+ require 'optparse'
2
+
1
3
  module Soaring
2
4
  class CLI
3
5
  def self.start(argv)
4
- puts "Started with the following args <#{argv}>"
6
+ @project_folder = Dir.pwd
7
+ command, options = self.parse
8
+
9
+ puts "executing #{command} with #{options}" if options[:verbose]
10
+
11
+ self.send("execute_#{command}",options)
12
+ end
13
+
14
+ private
15
+
16
+ def self.execute_init(options)
17
+ initializer = Initializer.new(options)
18
+ initializer.initialize_project(@project_folder)
19
+ end
20
+
21
+ def self.execute_update(options)
22
+ initializer = Initializer.new(options)
23
+ initializer.initialize_project(@project_folder)
24
+ end
25
+
26
+ def self.execute_run(options)
27
+ runner = Runner.new(options)
28
+ runner.run(@project_folder)
29
+ end
30
+
31
+ def self.execute_package(options)
32
+ packager = Packager.new(options)
33
+ packager.package(@project_folder)
34
+ end
35
+
36
+ def self.parse
37
+ options = {}
38
+
39
+ opt_parser = OptionParser.new do |opt|
40
+ opt.banner = "Usage: soaring COMMAND [OPTIONS]"
41
+ opt.separator ""
42
+ opt.separator "Commands"
43
+ opt.separator " init: create a new soar service component in the current folder"
44
+ opt.separator " update: update the soar service component in the current folder"
45
+ opt.separator " run: run soar service locally"
46
+ opt.separator " package: package the service component for deployment"
47
+ opt.separator ""
48
+ opt.separator "Options"
49
+
50
+ opt.on("-v","--verbose","more verbose output of the process") do
51
+ options[:verbose] = true
52
+ end
53
+
54
+ opt.on("-e","--environment ENVIRONMENT","environment you want the service to run in") do |environment|
55
+ options[:environment] = environment
56
+ end
57
+
58
+ opt.on("-r","--soar_sc_refspec REF_SPEC","git reference spec for the soar_sc to base your init on") do |soar_sc_refspec|
59
+ options[:soar_sc_refspec] = soar_sc_refspec
60
+ end
61
+
62
+ opt.on("-i","--ignore_git_checks","ignore checks ensuring your repo is up to date") do
63
+ options[:ignore_git_checks] = true
64
+ puts "Warning: Ignoring git repo checks"
65
+ end
66
+
67
+ opt.on("-h","--help","help") do
68
+ puts opt_parser
69
+ exit 0
70
+ end
71
+ end
72
+ opt_parser.parse!
73
+
74
+ command = ARGV[0]
75
+ valid_commands = ['init', 'update', 'run', 'package']
76
+ if not valid_commands.include?(command)
77
+ puts 'Invalid command'
78
+ puts opt_parser
79
+ exit 1
80
+ end
81
+ [command, options]
5
82
  end
6
83
  end
7
84
  end
@@ -0,0 +1,35 @@
1
+ module Soaring
2
+ class Initializer
3
+ def initialize(options)
4
+ @options = options
5
+ end
6
+
7
+ def initialize_project(project_folder)
8
+ @project_folder = project_folder
9
+ git_refspec = 'STABLE' #default to STABLE if not specified
10
+ git_refspec = @options[:soar_sc_refspec] if @options[:soar_sc_refspec]
11
+
12
+ Dir.mktmpdir { |dir|
13
+ temporary_folder = dir
14
+ temporary_soar_sc_folder = "#{temporary_folder}/soar_sc"
15
+ `git --git-dir=/dev/null clone --quiet --progress --branch #{git_refspec} --depth=1 git@gitlab.host-h.net:hetznerZA/soar_sc.git #{temporary_soar_sc_folder}`
16
+
17
+ `yes | cp -rf #{temporary_soar_sc_folder}/config #{@project_folder}`
18
+ `yes | cp -rf #{temporary_soar_sc_folder}/docker #{@project_folder}`
19
+ `yes | cp -rf #{temporary_soar_sc_folder}/lib #{@project_folder}`
20
+ `yes | cp -rf #{temporary_soar_sc_folder}/smaak #{@project_folder}`
21
+ `yes | cp -rf #{temporary_soar_sc_folder}/config.ru #{@project_folder}`
22
+ `yes | cp -rf #{temporary_soar_sc_folder}/Gemfile #{@project_folder}`
23
+ `yes | cp -rf #{temporary_soar_sc_folder}/.ruby-gemset #{@project_folder}`
24
+ `yes | cp -rf #{temporary_soar_sc_folder}/.ruby-version #{@project_folder}`
25
+
26
+ # Dir.glob("#{temporary_soar_sc_folder}/*.sh") { | template_file |
27
+ # `yes | cp -rf #{template_file} #{@project_folder}`
28
+ # }
29
+ }
30
+
31
+ #restore the soaring gem for development purposes of soaring
32
+ `echo "gem 'soaring', path: '../soaring'" >> #{@project_folder}/Gemfile`
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,32 @@
1
+ module Soaring
2
+ class Packager
3
+ def initialize(options)
4
+ @options = options
5
+ end
6
+
7
+ def package(project_folder)
8
+ exit 1 if (not is_git_repo_up_to_date?) and (not @options[:ignore_git_checks])
9
+ puts 'Git repo up to date.' if @options[:verbose]
10
+
11
+ service_name = File.split(project_folder)[-1]
12
+ service_revision = get_service_component_revision
13
+ revision_hash = `git rev-parse --short HEAD`.chomp
14
+ timestamp = Time.now.strftime("%F-%H%M%S")
15
+ build_output_location = "build/build-#{service_name}-#{service_revision}-#{revision_hash}-#{timestamp}.zip"
16
+ `zip -r #{build_output_location} * .ebextensions -x build -x config/environment.yml`
17
+ puts "Build packaged at #{project_folder}/#{build_output_location}"
18
+ end
19
+
20
+ private
21
+
22
+ def get_service_component_revision
23
+ end
24
+
25
+ def is_git_repo_up_to_date?
26
+ git_response = `git status --porcelain`.chomp
27
+ return true if '' == git_response
28
+ puts "Git repo is dirty and should not be packaged"
29
+ false
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,16 @@
1
+ module Soaring
2
+ class Runner
3
+ def initialize(options)
4
+ @options = options
5
+ end
6
+
7
+ def run(project_folder)
8
+ environment = 'development'
9
+ port = 9393
10
+ binding_address = '0.0.0.0'
11
+ # exec("export SOAR_TECH=debug; export RACK_ENV=development; ./run.sh")
12
+ `bundle exec rackup -E #{environment} ./config.ru -p #{port} --host #{binding_address}`
13
+ end
14
+
15
+ end
16
+ end
@@ -1,3 +1,3 @@
1
1
  module Soaring
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/soaring.rb CHANGED
@@ -1,4 +1,7 @@
1
1
  require 'soaring/version'
2
+ require 'soaring/initializer'
3
+ require 'soaring/runner'
4
+ require 'soaring/packager'
2
5
  require 'soaring/cli'
3
6
 
4
7
  module Soaring
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soaring
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Barney de Villiers
@@ -82,6 +82,9 @@ files:
82
82
  - bin/soaring
83
83
  - lib/soaring.rb
84
84
  - lib/soaring/cli.rb
85
+ - lib/soaring/initializer.rb
86
+ - lib/soaring/packager.rb
87
+ - lib/soaring/runner.rb
85
88
  - lib/soaring/version.rb
86
89
  - soaring.gemspec
87
90
  homepage: https://github.com/hetznerZA/soaring