sweatshop_gears 1.0.2 → 1.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: ec1658e35ceb4fdbb0d685556ca88295e9208b80
4
- data.tar.gz: 4590751c9868f8f5a07cc2fe5f67bbf774128fa4
3
+ metadata.gz: c674ba7dbd21928d11433b49f7ba0ff722a5d976
4
+ data.tar.gz: c3fafd46ef7a1f223fdf58ec6cc40a0e7d681e89
5
5
  SHA512:
6
- metadata.gz: c173f6f391b05e44e52004def9774b23caf2d839466de65ef8c83bc49bf7c6a86afe75cff8309d92f0b6647265408e4699a53e3042b6ddbf0f58fe84bc806148
7
- data.tar.gz: 1ec9db87baf3c994e5109599ecd7d7ff18c9f51b33b7f9198530918d5e6d29ea7932a2eec15fda9e0082b2f17605182e2af6ad50ec7fd7558d813a08d5317462
6
+ metadata.gz: 8ec3981a117a1229536b823f2f25766a274e21d54f5a3432a87a551bcf646563103d91d12438f4d517de4b28ebef627a8a60c5dc87a50c5c867e43086d319d15
7
+ data.tar.gz: 21aaf7fcab481a610792499c29bd3799a2a214def189ce688a813389d0bfeb87a5606dce0c08e100cfa6e30bda0dce4514ce6ef6f45fd79e85b280d6c513ccfc
data/.gitignore CHANGED
@@ -6,4 +6,4 @@ vendor
6
6
  coverage
7
7
 
8
8
  .robot_sweatshop
9
- .test
9
+ .test_download_path
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sweatshop_gears (1.0.1)
4
+ sweatshop_gears (1.0.2)
5
5
  bundler
6
6
  commander
7
7
  contracts
@@ -18,7 +18,6 @@ GEM
18
18
  celluloid-io (0.15.0)
19
19
  celluloid (>= 0.15.0)
20
20
  nio4r (>= 0.5.0)
21
- colorize (0.7.7)
22
21
  commander (4.3.4)
23
22
  highline (~> 1.7.2)
24
23
  configatron (4.5.0)
@@ -49,7 +48,7 @@ GEM
49
48
  moneta (0.8.0)
50
49
  nio4r (1.1.0)
51
50
  oj (2.12.9)
52
- rack (1.6.1)
51
+ rack (1.6.2)
53
52
  rack-protection (1.5.3)
54
53
  rack
55
54
  rainbow (2.0.0)
@@ -58,9 +57,8 @@ GEM
58
57
  moneta (~> 0.8)
59
58
  riot (0.12.7)
60
59
  rr
61
- robot_sweatshop (0.4.3)
60
+ robot_sweatshop (0.4.7)
62
61
  bundler
63
- colorize
64
62
  commander
65
63
  configatron
66
64
  contracts
@@ -72,6 +70,7 @@ GEM
72
70
  sinatra
73
71
  sinatra-cross_origin
74
72
  stubborn_queue
73
+ terminal-announce
75
74
  rr (1.1.2)
76
75
  sigar (0.7.3)
77
76
  simplecov (0.10.0)
data/README.md CHANGED
@@ -2,10 +2,18 @@
2
2
 
3
3
  Package management for [Robot Sweatshop](https://github.com/JScott/robot_sweatshop) scripts.
4
4
 
5
- `sweatshop gears <package-name>`
5
+ `sweatshop gears install <package-name>`
6
+
7
+ If you can't create `/usr/local/gears`, use the `--path` flag to install everything to somewhere you can.
6
8
 
7
9
  ## Future
8
10
 
9
11
  - Figure out something sane for finding ports for services
10
- - More metadata (author, description)
11
12
  - Source from custom repo
13
+ - More commands:
14
+ - show <package>
15
+ - list [--all]
16
+ - uninstall
17
+ - update
18
+ - Package versioning
19
+ - Scaffolding scripts?
data/Rakefile CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'rake'
2
+ require 'rake/testtask'
2
3
 
3
- task :test do
4
+ task :bats do
4
5
  `sweatshop stop`
5
6
  $stdout.sync = true
6
7
  puts 'sweatshop-gears'
@@ -11,6 +12,12 @@ task :test do
11
12
  end
12
13
  end
13
14
 
15
+ task :riot do
16
+ Dir.glob('test/*_test.rb').each do |path|
17
+ require_relative path
18
+ end
19
+ end
20
+
14
21
  task :build do
15
22
  print 'Building and installing local gem..'
16
23
  `gem build sweatshop_gears.gemspec --force`
@@ -20,4 +27,4 @@ task :build do
20
27
  end
21
28
 
22
29
  task default: :test
23
- task test: :build
30
+ task test: [:build, :riot]
data/bin/sweatshop-gears CHANGED
@@ -1,10 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'yaml'
3
+ require 'fileutils'
3
4
  require 'commander/import'
4
5
  require 'robot_sweatshop/gears'
5
6
 
6
7
  program :name, 'Sweatshop Gears'
7
- program :version, '1.0.2'
8
+ program :version, '1.0.3'
8
9
  program :description, 'Package management for Robot Sweatshop'
9
10
  program :help, 'Author', 'Justin Scott <jvscott@gmail.com>'
10
11
 
@@ -12,14 +13,24 @@ default_command :help
12
13
 
13
14
  command :init do |c|
14
15
  c.syntax = 'sweatshop-gears init'
15
- c.description = 'Makes the Gears packages available to Robot Sweatshop'
16
+ c.description = 'Downloads the Sweatshop Gears metadata'
16
17
  c.option '--path STRING', String, 'The working path for downloading packages'
17
18
  c.action do |_args, options|
18
- options.default path: '/opt/gears'
19
- Gears.download to_path: options.path
20
- Gears.create_runtime_paths
21
- Gears::Dependencies.install from_path: options.path
22
- Gears::Binaries.expose from_path: options.path
23
- Gears::Services.load from_path: options.path
19
+ options.default path: '/usr/local/gears'
20
+ FileUtils.mkpath options.path
21
+ Gears::Metadata.download to_path: options.path
22
+ Gears::Metadata.create_runtime_paths # TODO: ensure robot_sweatshop ran and the compiled config exists? Only errors in Services
23
+ end
24
+ end
25
+
26
+ command :install do |c|
27
+ c.syntax = 'sweatshop-gears install <package-name>'
28
+ c.description = 'Makes a Gears package available to Robot Sweatshop'
29
+ c.option '--path STRING', String, 'The working path for downloading packages'
30
+ c.action do |args, options|
31
+ options.default path: '/usr/local/gears'
32
+ system "sweatshop-gears init --path #{options.path}" unless Dir.exist? options.path
33
+ fail "#{args.first} already installed" if Dir.exist? "#{options.path}/#{args.first}"
34
+ Gears::Packages.install args.first, from_path: options.path
24
35
  end
25
36
  end
@@ -1,4 +1,5 @@
1
- require_relative 'gears/base'
1
+ require_relative 'gears/metadata'
2
+ require_relative 'gears/packages'
2
3
  require_relative 'gears/dependencies'
3
4
  require_relative 'gears/binaries'
4
5
  require_relative 'gears/services'
@@ -5,20 +5,9 @@ module Gears
5
5
  # Installs binary Gears packages
6
6
  module Binaries
7
7
  def self.expose(from_path:)
8
- Gears.packages(from_path).each do |package|
9
- link package if contains_binary? package
10
- end
11
- end
12
-
13
- def self.contains_binary?(package_path)
14
- metadata = Gears.metadata package_path
15
- metadata['type'] == 'binary'
16
- end
17
-
18
- def self.link(package_path)
19
- binary_name = File.basename package_path
20
- original_binary = "#{package_path}/#{binary_name}"
21
- binary_link = "#{scripts_path}/#{binary_name}"
8
+ binary_name = File.basename from_path
9
+ original_binary = File.expand_path "#{from_path}/#{binary_name}"
10
+ binary_link = File.expand_path "#{scripts_path}/#{binary_name}"
22
11
  begin
23
12
  FileUtils.symlink original_binary, binary_link
24
13
  Announce.success "Symlinked #{binary_name}"
@@ -29,7 +18,7 @@ module Gears
29
18
 
30
19
  def self.scripts_path
31
20
  config = File.expand_path '~/.robot_sweatshop/compiled_config.yaml'
32
- Announce.failure 'Please run `sweatshop start` again' unless File.exist? config
21
+ fail 'Please run `sweatshop start` again' unless File.exist? config
33
22
  config = YAML.load File.read(config)
34
23
  config[:scripts_path]
35
24
  end
@@ -5,7 +5,7 @@ module Gears
5
5
  # Deals with the dependencies from Gears packages
6
6
  module Dependencies
7
7
  def self.install(from_path:)
8
- Gears.packages(from_path).each { |path| install_gems path }
8
+ install_gems from_path
9
9
  end
10
10
 
11
11
  def self.install_gems(package_path)
@@ -0,0 +1,41 @@
1
+ require 'git'
2
+ require 'yaml'
3
+ require 'terminal-announce'
4
+ require 'fileutils'
5
+
6
+ # Provides information and downloading of Gears metadata
7
+ module Gears
8
+ module Metadata
9
+ def self.clone(path)
10
+ Git.clone git_repo, File.basename(path), path: File.dirname(path)
11
+ end
12
+
13
+ def self.git_repo
14
+ 'https://github.com/JScott/sweatshop-gears-packages.git'
15
+ end
16
+
17
+ def self.download(to_path:)
18
+ puts "Downloading metadata from '#{git_repo}'"
19
+ clone to_path
20
+ Announce.success 'Metadata downloaded'
21
+ end
22
+
23
+ def self.metadata(package_path)
24
+ YAML.load File.read("#{package_path}/metadata.yaml")
25
+ end
26
+
27
+ def self.create_runtime_paths
28
+ config_path = File.expand_path '~/.robot_sweatshop/compiled_config.yaml'
29
+ config = YAML.load_file config_path
30
+ FileUtils.mkpath config[:logfile_path]
31
+ FileUtils.mkpath config[:pidfile_path]
32
+ end
33
+
34
+ def self.download_and_install(package_name, from_path:)
35
+ metadata_path = "#{from_path}/#{package_name}.yaml"
36
+ fail "#{package_name} not found" unless File.exist? metadata_path
37
+ metadata = YAML.load_file metadata_path
38
+ Gears::Package.install_from metadata
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,34 @@
1
+ require 'terminal-announce'
2
+
3
+ # Provides information and downloading of Gears packages
4
+ module Gears
5
+ module Packages
6
+ def self.clone(git_repo, to_path:)
7
+ Git.clone git_repo, File.basename(to_path), path: File.dirname(to_path)
8
+ end
9
+
10
+ def self.packages(gears_path)
11
+ paths = Dir["#{gears_path}/*"].select { |path| File.directory? path }
12
+ paths.map { |path| File.expand_path path }
13
+ end
14
+
15
+ def self.data_for(package_name, path)
16
+ install_path = "#{path}/#{package_name}"
17
+ metadata_path = "#{path}/#{package_name}.yaml"
18
+ fail "Metadata for '#{package_name}' not found" unless File.exist? metadata_path
19
+ [install_path, YAML.load_file(metadata_path)]
20
+ end
21
+
22
+ def self.install(package_name, from_path:)
23
+ install_path, metadata = data_for package_name, from_path
24
+ clone metadata['repo'], to_path: install_path
25
+ Announce.success "#{package_name} downloaded"
26
+ Gears::Dependencies.install from_path: install_path
27
+ Gears::Binaries.expose from_path: install_path if metadata['type'] == 'binary'
28
+ Gears::Services.load from_path: install_path if metadata['type'] == 'service'
29
+ rescue
30
+ Announce.failure 'Error occurred, rolling back installation'
31
+ FileUtils.rm_rf "#{from_path}/#{package_name}"
32
+ end
33
+ end
34
+ end
@@ -6,29 +6,24 @@ module Gears
6
6
  # Installs service Gears packages
7
7
  module Services
8
8
  def self.load(from_path:)
9
- packages = Gears.packages(from_path).select { |package| contains_service? package }
10
- services = packages.map { |package| File.basename package }
11
- dynamically_load_eye services, from_path
12
- services.each { |service| Announce.success "Loaded #{service} into Eye" }
13
- end
14
-
15
- def self.contains_service?(package_path)
16
- metadata = Gears.metadata package_path
17
- metadata['type'] == 'service'
9
+ service = File.basename from_path
10
+ dynamically_load_eye service, from_path
11
+ Announce.success "Loaded #{service} into Eye"
18
12
  end
19
13
 
20
14
  def self.write_and_load(eye_config)
21
15
  eye_file = '/tmp/.sweatshop_gears.eye'
22
16
  File.write eye_file, eye_config
17
+ puts eye_config
23
18
  puts `eye load #{eye_file}`
24
19
  puts `eye stop sweatshop_gears`
25
20
  File.delete eye_file
26
21
  end
27
22
 
28
- def self.dynamically_load_eye(service_list, gears_path)
23
+ def self.dynamically_load_eye(service, gears_path)
29
24
  input = File.read "#{__dir__}/sweatshop_gears.eye.eruby"
30
25
  eruby = Erubis::Eruby.new input
31
- context = { services: service_list, gears_path: File.expand_path(gears_path) }
26
+ context = { service: service, gears_path: File.expand_path(gears_path) }
32
27
  write_and_load eruby.result(context)
33
28
  end
34
29
  end
@@ -15,12 +15,10 @@ Eye.application :sweatshop_gears do
15
15
  check :cpu, every: 10.seconds, below: 100, times: 3
16
16
  working_dir CONFIG[:working_path]
17
17
 
18
- <% for service in services %>
19
18
  process :'<%= service %>' do
20
19
  pid_file "#{PID_PATH}/gears/<%= service %>.pid"
21
20
  stdall "#{LOG_PATH}/gears/<%= service %>.log"
22
- start_command "<%= gears_path %>/<%= service %>/<%= service %>"
21
+ start_command "<%= gears_path %>/<%= service %>"
23
22
  daemonize true
24
23
  end
25
- <% end %>
26
24
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = 'sweatshop_gears'
3
- gem.version = '1.0.2'
3
+ gem.version = '1.0.3'
4
4
  gem.licenses = 'MIT'
5
5
  gem.authors = ['Justin Scott']
6
6
  gem.email = 'jvscott@gmail.com'
data/test/help_test.rb ADDED
@@ -0,0 +1,7 @@
1
+ require_relative 'teststrap'
2
+
3
+ context 'sweatshop-gears help' do
4
+ teardown { clean_up_paths }
5
+ setup { `bin/sweatshop-gears help` }
6
+ denies_topic('the output').empty
7
+ end
data/test/init.bats CHANGED
@@ -5,31 +5,9 @@
5
5
  [ -f .test_download_path/README.md ]
6
6
  }
7
7
 
8
- @test "Exposes package binaries" {
8
+ @test "Doesn't download any packages" {
9
9
  run sweatshop-gears init --path .test_download_path
10
- scripts_path=.robot_sweatshop/scripts
11
- [ -f $scripts_path/git-sync ]
12
- }
13
-
14
- @test "Doesn't expose services" {
15
- run sweatshop-gears init --path .test_download_path
16
- scripts_path=.robot_sweatshop/scripts
17
- [ ! -f $scripts_path/big-green-button ]
18
- }
19
-
20
- @test "Loads services into Eye" {
21
- eye stop big-green-button
22
- run sweatshop-gears init --path .test_download_path
23
- eye start big-green-button
24
- sleep 3
25
- [[ $(eye info | grep big-green-button) =~ up ]]
26
- }
27
-
28
- @test "Installs dependencies" {
29
- skip "I need a gem to be installed that isn't used by Sweatshop or Gears"
30
- yes | gem uninstall SOME_GEM --all
31
- sweatshop-gears init --path .test_download_path
32
- [[ $(gem list) =~ "SOME_GEM " ]]
10
+ [ ! -f .test_download_path/packages/big-green-button/README.md ]
33
11
  }
34
12
 
35
13
  teardown() {
data/test/init_test.rb ADDED
@@ -0,0 +1,11 @@
1
+ require_relative 'teststrap'
2
+ require 'fileutils'
3
+
4
+
5
+ context 'sweatshop-gears init' do
6
+ teardown { clean_up_paths }
7
+ setup { `bin/sweatshop-gears init --path #{PACKAGES_PATH}` }
8
+ denies_topic('the output').empty
9
+ asserts('metadata is downloaded') { File.exist? "#{PACKAGES_PATH}/git-sync.yaml" }
10
+ denies('packages are downloaded') { File.exist? "#{SWEATSHOP_SCRIPTS_PATH}/git-sync" }
11
+ end
data/test/install.bats ADDED
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env bats
2
+
3
+ @test "Exposes package binaries" {
4
+ run sweatshop-gears install git-sync --path .test_download_path
5
+ scripts_path=.robot_sweatshop/scripts
6
+ [ -f $scripts_path/git-sync ]
7
+ }
8
+
9
+ @test "Doesn't expose services" {
10
+ run sweatshop-gears install big-green-button --path .test_download_path
11
+ scripts_path=.robot_sweatshop/scripts
12
+ [ ! -f $scripts_path/big-green-button ]
13
+ }
14
+
15
+ @test "Loads services into Eye" {
16
+ eye stop big-green-button
17
+ run sweatshop-gears install big-green-button --path .test_download_path
18
+ eye start big-green-button
19
+ sleep 3
20
+ [[ $(eye info | grep big-green-button) =~ up ]]
21
+ }
22
+
23
+ @test "Installs dependencies" {
24
+ skip "I need a gem to be installed that isn't used by Sweatshop or Gears"
25
+ yes | gem uninstall SOME_GEM --all
26
+ sweatshop-gears install git-sync --path .test_download_path
27
+ [[ $(gem list) =~ "SOME_GEM " ]]
28
+ }
29
+
30
+ teardown() {
31
+ rm -rf .test_download_path
32
+ }
@@ -0,0 +1,16 @@
1
+ require_relative 'teststrap'
2
+
3
+ context 'sweatshop-gears install' do
4
+ setup do
5
+ clean_up_paths
6
+ %w(git-sync big-green-button).each do |package|
7
+ `sweatshop-gears install #{package} --path #{PACKAGES_PATH}`
8
+ end
9
+ end
10
+ denies_topic('the output').empty
11
+ asserts('packages are downloaded') { File.exist? "#{PACKAGES_PATH}/git-sync" }
12
+ asserts('binaries are symlinked') { File.exist? "#{SWEATSHOP_SCRIPTS_PATH}/git-sync" }
13
+ denies('services are symlinked') { File.exist? "#{SWEATSHOP_SCRIPTS_PATH}/big-green-button" }
14
+ asserts('services are loaded into Eye') { not `eye info | grep big-green-button`.empty? }
15
+ # asserts('dependencies are installed') { ??? }
16
+ end
data/test/teststrap.rb ADDED
@@ -0,0 +1,14 @@
1
+ require 'bundler/setup'
2
+ require 'riot'
3
+ require 'yaml'
4
+ require 'robot_sweatshop/config'
5
+
6
+ `sweatshop start`
7
+ `sweatshop stop`
8
+
9
+ PACKAGES_PATH = '.test_download_path'
10
+ SWEATSHOP_SCRIPTS_PATH = '.robot_sweatshop/scripts'
11
+
12
+ def clean_up_paths
13
+ FileUtils.rm_rf PACKAGES_PATH
14
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sweatshop_gears
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Scott
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-15 00:00:00.000000000 Z
11
+ date: 2015-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -166,14 +166,20 @@ files:
166
166
  - Rakefile
167
167
  - bin/sweatshop-gears
168
168
  - lib/robot_sweatshop/gears.rb
169
- - lib/robot_sweatshop/gears/base.rb
170
169
  - lib/robot_sweatshop/gears/binaries.rb
171
170
  - lib/robot_sweatshop/gears/dependencies.rb
171
+ - lib/robot_sweatshop/gears/metadata.rb
172
+ - lib/robot_sweatshop/gears/packages.rb
172
173
  - lib/robot_sweatshop/gears/services.rb
173
174
  - lib/robot_sweatshop/gears/sweatshop_gears.eye.eruby
174
175
  - sweatshop_gears.gemspec
175
176
  - test/cli.bats
177
+ - test/help_test.rb
176
178
  - test/init.bats
179
+ - test/init_test.rb
180
+ - test/install.bats
181
+ - test/install_test.rb
182
+ - test/teststrap.rb
177
183
  homepage: http://www.github.com/jscott/sweatshop-gears-cli/
178
184
  licenses:
179
185
  - MIT
@@ -1,35 +0,0 @@
1
- require 'git'
2
- require 'yaml'
3
-
4
- # Provides information and downloading of Gears packages
5
- module Gears
6
- def self.clone_packages(path)
7
- Git.clone git_repo, File.basename(path), path: File.dirname(path)
8
- end
9
-
10
- def self.git_repo
11
- 'https://github.com/JScott/sweatshop-gears-packages.git'
12
- end
13
-
14
- def self.download(to_path:)
15
- puts "Downloading packages from '#{git_repo}'"
16
- clone_packages to_path
17
- Announce.success 'Packages downloaded'
18
- end
19
-
20
- def self.packages(gears_path)
21
- paths = Dir["#{gears_path}/*"].select { |path| File.directory? path }
22
- paths.map { |path| File.expand_path path }
23
- end
24
-
25
- def self.metadata(package_path)
26
- YAML.load File.read("#{package_path}/metadata.yaml")
27
- end
28
-
29
- def self.create_runtime_paths
30
- config_path = File.expand_path '~/.robot_sweatshop/compiled_config.yaml'
31
- config = YAML.load_file config_path
32
- FileUtils.mkpath config[:logfile_path]
33
- FileUtils.mkpath config[:pidfile_path]
34
- end
35
- end