singularity-cli 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +5 -0
- data/bin/singularity +32 -0
- data/lib/singularity.rb +88 -0
- metadata +90 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b2807ae40e9a6da9acf5a9cebc0a51bd1b1e99de
|
4
|
+
data.tar.gz: e861474952886a8329d62d3822b9952fe8b9040f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5da94a88e37bc66846d21e1e54d183ac4e6d3d834e64857371e3aaea9936d646298d590b19abe59a3644cf62073efa67a424a70f9214bf7cc8fef06b320715ff
|
7
|
+
data.tar.gz: 522694d56ea4d7018c31ce0bedddf4a8b0e558f4b7501dabff9424f2327e07741f287463f4668bfa90b77aad51e8d3b1a14e8cc6018369e022cb4d4f31ba7488
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Offers.com
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
data/bin/singularity
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'singularity'
|
3
|
+
|
4
|
+
# passes "--help" if no arguments given which will result in the "else" case statement being executed, printing proper usage
|
5
|
+
ARGV << '--help' if ARGV.empty?
|
6
|
+
|
7
|
+
def print_usage
|
8
|
+
puts "Usage:\n\tsingularity delete <uri> <file>\n\tsingularity deploy <uri> <file> <release>"
|
9
|
+
exit
|
10
|
+
end
|
11
|
+
|
12
|
+
action = ARGV[0]
|
13
|
+
uri = ARGV[1]
|
14
|
+
file = ARGV[2]
|
15
|
+
|
16
|
+
case action
|
17
|
+
|
18
|
+
when "delete"
|
19
|
+
print_usage unless ARGV.size == 3
|
20
|
+
Singularity::Deleter.new(uri,file).delete
|
21
|
+
|
22
|
+
when "deploy"
|
23
|
+
print_usage unless ARGV.size == 4
|
24
|
+
release = ARGV[3]
|
25
|
+
Singularity::Deployer.new(uri,file,release).deploy
|
26
|
+
|
27
|
+
else
|
28
|
+
print_usage
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
|
data/lib/singularity.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'json'
|
3
|
+
require 'rest-client'
|
4
|
+
require 'colorize'
|
5
|
+
|
6
|
+
module Singularity
|
7
|
+
class Request
|
8
|
+
attr_accessor :release, :cpus, :mem, :envs, :schedule, :cmd, :arguments, :request_id, :repo, :release_string, :release_id_string
|
9
|
+
|
10
|
+
def get_binding
|
11
|
+
binding()
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class Deployer
|
16
|
+
|
17
|
+
def initialize(uri, file, release)
|
18
|
+
@uri = uri
|
19
|
+
@file = file
|
20
|
+
@release = release
|
21
|
+
@config = ERB.new(open(file).read)
|
22
|
+
@r = Request.new
|
23
|
+
@r.release = @release
|
24
|
+
@data = JSON.parse(@config.result(@r.get_binding))
|
25
|
+
print @data['id']
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
def is_paused
|
30
|
+
begin
|
31
|
+
resp = RestClient.get "#{@uri}/api/requests/request/#{@data['id']}"
|
32
|
+
JSON.parse(resp)['state'] == 'PAUSED'
|
33
|
+
rescue
|
34
|
+
print " CREATING...".blue
|
35
|
+
false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# Deployer.deploy -- arguments are <uri>, <release>
|
40
|
+
def deploy
|
41
|
+
begin
|
42
|
+
if is_paused()
|
43
|
+
puts " PAUSED, SKIPPING".yellow
|
44
|
+
exit
|
45
|
+
else
|
46
|
+
# create or update the request
|
47
|
+
resp = RestClient.post "#{@uri}/api/requests", @data.to_json, :content_type => :json
|
48
|
+
end
|
49
|
+
|
50
|
+
# deploy the request
|
51
|
+
@data['requestId'] = @data['id']
|
52
|
+
@data['id'] = "#{@release}.#{Time.now.to_i}"
|
53
|
+
deploy = {
|
54
|
+
'deploy' => @data,
|
55
|
+
'user' => `whoami`.chomp,
|
56
|
+
'unpauseOnSuccessfulDeploy' => false
|
57
|
+
}
|
58
|
+
|
59
|
+
resp = RestClient.post "#{@uri}/api/deploys", deploy.to_json, :content_type => :json
|
60
|
+
|
61
|
+
puts " DEPLOYED".green
|
62
|
+
rescue Exception => e
|
63
|
+
puts " #{e.response}".red
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
class Deleter
|
69
|
+
|
70
|
+
def initialize(uri, file)
|
71
|
+
@uri = uri
|
72
|
+
@file = file
|
73
|
+
end
|
74
|
+
|
75
|
+
# Deleter.delete -- arguments are <uri>, <file>
|
76
|
+
def delete
|
77
|
+
begin
|
78
|
+
task_id = "#{@file}".gsub(/\.\/singularity\//, "").gsub(/\.json/, "")
|
79
|
+
# delete the request
|
80
|
+
RestClient.delete "#{@uri}/api/requests/request/#{task_id}"
|
81
|
+
puts "#{task_id} DELETED"
|
82
|
+
rescue
|
83
|
+
puts "#{task_id} #{$!.response}"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: singularity-cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Travis Webb
|
8
|
+
- Chris Kite
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2016-03-08 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rest-client
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.8'
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.8.0
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
requirements:
|
28
|
+
- - "~>"
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '1.8'
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.8.0
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: colorize
|
36
|
+
requirement: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.7.7
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 0.7.7
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - "~>"
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 0.7.7
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.7.7
|
54
|
+
description: 'Usage: [singularity delete <uri> <file>] or [singularity deploy <uri>
|
55
|
+
<file> <release>]'
|
56
|
+
email:
|
57
|
+
executables:
|
58
|
+
- singularity
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- LICENSE
|
63
|
+
- README.md
|
64
|
+
- bin/singularity
|
65
|
+
- lib/singularity.rb
|
66
|
+
homepage: https://github.com/offers/singularity-cli
|
67
|
+
licenses:
|
68
|
+
- MIT
|
69
|
+
metadata: {}
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubyforge_project:
|
86
|
+
rubygems_version: 2.5.1
|
87
|
+
signing_key:
|
88
|
+
specification_version: 4
|
89
|
+
summary: singularity deploy and delete command line tools
|
90
|
+
test_files: []
|