shuttl 0.3.2 → 0.4.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2c943490fc4be7bb013e3d0a2a64bd088f8d3f24
4
- data.tar.gz: 58036ff0a9c6e2deb3778aa2a1d41820f9d82459
3
+ metadata.gz: b3a44e2acfa4fe0c9838957467204492817ebbea
4
+ data.tar.gz: 840f8d2ce636a8ac992eb6da647ca155409598a8
5
5
  SHA512:
6
- metadata.gz: d0d06d01e13fe953f01789ed75a6e7fde6c80031c10440cf36048a7bab7c9a52266ce2e7350449b3fb82c93763bd2dedab50623cfd1706b6be890d4360a8c3ea
7
- data.tar.gz: 775b289b68e3d59055a5c7cc7f942a8fe692445ca56b6212f8676739929c4bfc4597e5241a50ba25f08915cc092208987493a65963f98387cb01879289c4316d
6
+ metadata.gz: 76286e0fe12caeccc15725facc40b1fafb69fa944f0a1bd92eee6550cf69850112eb0a95b1fbff317f40914909717058de4870c103d0e06862e038b7a26701a5
7
+ data.tar.gz: d19194484e50c531704f3b6d0dff5e78bf521160ac1ae758ca05bf9ffa75a7b30b157be4e11b71d6506ce4c6008937692313a66399b5da3aa9ab098bc4247b75
data/bin/shuttl CHANGED
@@ -11,6 +11,8 @@ require_relative '../src/commands/run'
11
11
  require_relative '../src/commands/ssh'
12
12
  require_relative '../src/commands/deploy'
13
13
  require_relative '../src/commands/install'
14
+ require_relative '../src/commands/login'
15
+ require_relative '../src/commands/launch'
14
16
  require_relative '../src/settings'
15
17
 
16
18
  Docker.validate_version!
@@ -120,6 +122,29 @@ subcommands = Hash[
120
122
  end
121
123
  end,
122
124
  :runner => Install.new
125
+ },
126
+ 'login' => {
127
+ :opts => OptionParser.new do |opts|
128
+ end,
129
+ :runner => Login.new
130
+ },
131
+ 'launch' => {
132
+ :opts => OptionParser.new do |opts|
133
+ opts.banner = "Launch a new service using a given image"
134
+ opts.on('-i IMAGENAME', '--image IMAGENAME', 'The image for the service') do |imageName|
135
+ options[:imageName] = imageName
136
+ end
137
+ opts.on('-n SERVICENAME', '--name SERVICENAME', 'The name for the service') do |serviceName|
138
+ options[:serviceName] = serviceName
139
+ end
140
+ opts.on('-h HOST', '--host HOST', 'the host the service will be under') do |host|
141
+ options[:host] = host
142
+ end
143
+ opts.on('-s SCHEME', '--scheme SCHEME', 'the scheme for the host') do |scheme|
144
+ options[:scheme] = scheme
145
+ end
146
+ end,
147
+ :runner => Launch.new
123
148
  }
124
149
  ]
125
150
 
data/src/api/Api.rb ADDED
@@ -0,0 +1,17 @@
1
+ require_relative 'HTTPAdapter'
2
+
3
+ class ShuttlAPI < HTTPAdapter
4
+ def login(username, password)
5
+ post('/api/login', {"username": username, "password": password})
6
+ end
7
+
8
+ def launch(imageName, serviceName, host, scheme)
9
+ post('/api/launch', {
10
+ :imageName => imageName,
11
+ :serviceName => serviceName,
12
+ :routeRules => {
13
+ :host => host,
14
+ }
15
+ })
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ class APIError < StandardError
2
+ attr_accessor :response
3
+ def initialize (resp)
4
+ @response = resp
5
+ end
6
+ end
7
+
8
+ class NotFound < APIError
9
+ end
@@ -0,0 +1,43 @@
1
+ require 'net/http'
2
+ require 'json'
3
+
4
+ require_relative "./Exceptions"
5
+
6
+ class HTTPAdapter
7
+ def initialize (url, headers=Hash[])
8
+ @url = URI(url)
9
+ @headers = headers
10
+ @http = Net::HTTP.new(@url.host, @url.port)
11
+ end
12
+
13
+ def get(url, params=nil, headers=Hash[])
14
+ headers = @headers.merge headers
15
+ url = URI("#{@url}#{url}")
16
+ if !params.nil?
17
+ url.query = URI.encode_www_form(params)
18
+ end
19
+ res = Net::HTTP::Get.new(url.request_uri)
20
+ headers.map do |headerName, headerValue|
21
+ res[headerName] = headerValue
22
+ end
23
+ res = @http.request(res)
24
+ raise NotFound.new(res) if res.is_a?(Net::HTTPNotFound)
25
+ raise APIError.new(res) if !res.is_a?(Net::HTTPSuccess)
26
+ JSON.parse(res.body)
27
+ end
28
+
29
+ def post(url, body=Hash[], headers=Hash[])
30
+ headers = @headers.merge headers
31
+ puts headers
32
+ url = URI("#{@url}#{url}")
33
+ res = Net::HTTP::Post.new(url.request_uri, 'Content-Type' => 'application/json')
34
+ res.body = body.to_json
35
+ headers.map do |headerName, headerValue|
36
+ res[headerName] = headerValue
37
+ end
38
+ res = @http.request(res)
39
+ raise NotFound.new(res) if res.is_a?(Net::HTTPNotFound)
40
+ raise APIError.new(res) if !res.is_a?(Net::HTTPSuccess)
41
+ JSON.parse(res.body)
42
+ end
43
+ end
data/src/commands/base.rb CHANGED
@@ -7,6 +7,11 @@ class CommandBase
7
7
  @info = JSON.parse(fi.read)
8
8
  end
9
9
  @cwd = Dir.getwd
10
+ auth = {}
11
+ if @info.key?('token')
12
+ auth = {'Authorization': "Token #{@info['token']}"}
13
+ end
14
+ @api = ShuttlAPI.new ShuttlSettings::APIURL, auth
10
15
  end
11
16
 
12
17
  def handle (options, args)
@@ -0,0 +1,20 @@
1
+ require 'colorize'
2
+ require 'io/console'
3
+
4
+ require_relative '../api/Api'
5
+ require_relative '../settings'
6
+ require_relative "../api/Exceptions"
7
+ require_relative 'base'
8
+
9
+ class Launch < CommandBase
10
+
11
+ def run (options)
12
+ begin
13
+ @api.launch(options[:imageName], options[:serviceName], options[:host], options[:scheme])
14
+ rescue APIError => e
15
+ puts e.response.body
16
+ end
17
+
18
+ end
19
+
20
+ end
@@ -0,0 +1,26 @@
1
+ require 'colorize'
2
+ require 'io/console'
3
+
4
+ require_relative '../api/Api'
5
+ require_relative '../settings'
6
+ require_relative "../api/Exceptions"
7
+ require_relative 'base'
8
+
9
+ class Login < CommandBase
10
+
11
+ def run (options)
12
+ print "Username: "
13
+ userName = gets.chomp
14
+ print "Password (You won't see any typing):"
15
+ password = STDIN.noecho(&:gets).chomp
16
+ puts ""
17
+ begin
18
+ resp = @api.login(userName, password)
19
+ @info['token'] = resp["token"]
20
+ puts "Login successful!".green
21
+ rescue NotFound
22
+ $stderr.puts "username or password is incorrect".red
23
+ end
24
+ end
25
+
26
+ end
data/src/dsl/Shuttl.rb CHANGED
@@ -48,6 +48,7 @@ class Shuttl
48
48
 
49
49
  def ENTRYPOINT (entrypoint)
50
50
  @builder.entrypoint = entrypoint
51
+ self.add "ENTRYPOINT #{entrypoint}"
51
52
  end
52
53
 
53
54
  def ONSTART (cmd)
@@ -97,4 +98,8 @@ class Shuttl
97
98
  def CMD (cmd)
98
99
  @builder.cmd cmd
99
100
  end
101
+
102
+ def USER (user)
103
+ self.add "USER #{user}"
104
+ end
100
105
  end
@@ -94,9 +94,9 @@ class Builder
94
94
  end
95
95
  definition = @buildSettings[:docker]
96
96
  definition = [definition[0], ] + settingsArr + definition[1..definition.count]
97
- if @entrypoint
98
- definition << "ENTRYPOINT #{@entrypoint}"
99
- end
97
+ # if @entrypoint
98
+ # definition << "ENTRYPOINT #{@entrypoint}"
99
+ # end
100
100
  volumes = gatherVolume stage
101
101
  definition << "RUN echo 'echo SHUTTL IMAGE BOOTED' >> /.shuttl/run"
102
102
  definition << "RUN echo 'bash /.shuttl/start' >> /.shuttl/run"
data/src/settings.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  module ShuttlSettings
2
- VERSION = "0.3.2"
2
+ VERSION = "0.4.3"
3
3
  BUILD = 1
4
+ APIURL='http://172.17.0.4/'
4
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shuttl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yoseph Radding
@@ -74,11 +74,16 @@ files:
74
74
  - bin/shuttl
75
75
  - src/Shuttl/Loader.rb
76
76
  - src/Shuttl/Shuttl.rb
77
+ - src/api/Api.rb
78
+ - src/api/Exceptions.rb
79
+ - src/api/HTTPAdapter.rb
77
80
  - src/commands/base.rb
78
81
  - src/commands/build.rb
79
82
  - src/commands/deploy.rb
80
83
  - src/commands/info.rb
81
84
  - src/commands/install.rb
85
+ - src/commands/launch.rb
86
+ - src/commands/login.rb
82
87
  - src/commands/run.rb
83
88
  - src/commands/ssh.rb
84
89
  - src/commands/start.rb