maril 0.1.0 → 0.1.1

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: bbd5b74859d53f7614acf869a13a3bdd965134b7
4
- data.tar.gz: 81cc3128b3bdfb40b57c485b5cea88ea7ef60c91
3
+ metadata.gz: 93388dd3ee1c7ee421e13f3385ce3da8ce159185
4
+ data.tar.gz: c5dc7f08a4487f18db14e9f543d2bd6d6ba44d17
5
5
  SHA512:
6
- metadata.gz: dce412827bcfcf0e28636469b6184ac47be4d4ad62572a34d933e3c2335175ec4ec62078e87c6fec491a9a1eb6667f351dc0088bab98c5c45512b602e9d0d57f
7
- data.tar.gz: 8ea45337cb9d73dad9ec9ead7eb37dc74f6b0bc3874d8f0ecd605a2c14103a850f04033e8ed0fbbda2a19ed367b766bef6b636b65c083e663d2c9cafc957381d
6
+ metadata.gz: 62b4232a83180f2c0a266fddc80083efc7c86e4404c4e62495264ea0aaa6459b66fd10be0394574f8ab514c701597d211f5c2e85e15624f23305848378db4af0
7
+ data.tar.gz: f94e7b19042302b76efb99a9059f18152a4ea1daa3b4c9338d8ff8b139f0ec6450a74b1b22ddf42398f7784666afc91f1f1c11db48581b649710e8385ada1ddd
data/README.md CHANGED
@@ -6,14 +6,24 @@ Maril is abbreviation of "Marathon Application Run In Local". Which is a command
6
6
 
7
7
  Open your terminal and execute:
8
8
 
9
- $ gem install maril
9
+ ```
10
+ $ gem install maril
11
+ ```
12
+
13
+ I also provide a greasemonkey userscript. It will add a button on your marathon application page. You just need to click it and the `docker run` command will be saved into your clipboard.
14
+
15
+ ![image](https://user-images.githubusercontent.com/21731/28947741-3bc76082-7877-11e7-8564-fed827369626.png)
16
+
17
+ You can click [here](https://raw.githubusercontent.com/agate/maril/master/userscript/maril.user.js) to install it.
18
+
19
+ > Remember: You have to either change `@match` or add new `@match` in this userscript to match your marathon site. So that this button can show up.
10
20
 
11
21
  ## Usage
12
22
 
13
23
  Open your terminal and run:
14
24
 
15
25
  ```
16
- $ maril http://your.marathon.domain /your/application/id
26
+ $ maril --host http://your.marathon.domain --id /your/application/id
17
27
  ```
18
28
 
19
29
  ## Development
data/Rakefile CHANGED
@@ -1,6 +1,19 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rspec/core/rake_task"
3
+ require "erb"
3
4
 
4
5
  RSpec::Core::RakeTask.new(:spec)
5
6
 
6
7
  task :default => :spec
8
+
9
+ desc "Build maril.user.js"
10
+ task "build_userscript" do
11
+ gemspec = Gem::Specification::load("maril.gemspec")
12
+ src_path = "userscript/maril.user.js.erb"
13
+ dis_path = "userscript/maril.user.js"
14
+ content = ERB.new(File.read(src_path)).result(binding)
15
+ File.write(dis_path, content)
16
+ puts "Compiled #{src_path} => #{dis_path}"
17
+ end
18
+
19
+ task "build" => "build_userscript"
@@ -7,7 +7,7 @@ module Maril
7
7
 
8
8
  def generate
9
9
  app = fetch_app
10
- cmd = [ 'docker run' ]
10
+ cmd = [ 'docker run --rm -it' ]
11
11
  app['env'].each do |k, v|
12
12
  cmd << "-e #{k}=#{v}"
13
13
  end
@@ -19,7 +19,7 @@ module Maril
19
19
  end
20
20
  cmd << app['container']['docker']['image']
21
21
  cmd << app['cmd'] if app['cmd']
22
- cmd.join(" \\\n")
22
+ cmd.join(" ")
23
23
  end
24
24
 
25
25
  private
data/lib/maril/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Maril
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -0,0 +1,66 @@
1
+ // ==UserScript==
2
+ // @name Maril
3
+ // @namespace https://github.com/agate/maril
4
+ // @version 0.1.1
5
+ // @description Marathon Application Run In Local
6
+ // @author agate<agate.hao@gmail.com>
7
+ // @match http://PUT.YOUR.MARATHON.DOMAIN.HERE/*
8
+ // @grant GM_xmlhttpRequest
9
+ // @grant GM_setClipboard
10
+ // ==/UserScript==
11
+
12
+ (function() {
13
+ 'use strict';
14
+
15
+ let currentAppId = null;
16
+
17
+ const generateDockerCmd = () => {
18
+ let url = `${location.origin}/v2/apps${currentAppId}`;
19
+ GM_xmlhttpRequest({
20
+ method: "GET",
21
+ url: url,
22
+ onload: function(response) {
23
+ let app = JSON.parse(response.responseText).app;
24
+ let cmd = [ "docker run --rm -it" ];
25
+
26
+ for (var key in app.env) {
27
+ cmd.push(`-e ${key}=${app.env[key]}`);
28
+ }
29
+ app.container.docker.parameters.forEach((parameter) => {
30
+ cmd.push(`--${parameter.key} ${parameter.value}`);
31
+ });
32
+ app.container.docker.portMappings.forEach((mapping) => {
33
+ cmd.push(`-p ${mapping.containerPort}:${mapping.containerPort}`);
34
+ });
35
+ cmd.push(app.container.docker.image);
36
+
37
+ GM_setClipboard(cmd.join(" "));
38
+ alert("Already saved the docker run command into your clipboard.");
39
+ },
40
+ onerror: (response) => {
41
+ alert("error");
42
+ }
43
+ });
44
+ };
45
+
46
+ const attachButton = () => {
47
+ let hash = window.location.hash.slice(1);
48
+ if (hash.match(/^\/apps\/[^/]+$/)) {
49
+ let appId = decodeURIComponent(hash.slice(6));
50
+ if (currentAppId != appId) {
51
+ currentAppId = appId;
52
+ let parentEle = document.querySelector('.header-btn');
53
+ let btn = document.createElement('a');
54
+ let btnTxt = document.createTextNode("Generate Docker CMD");
55
+ btn.setAttribute("class", "btn btn-lg btn-default");
56
+ btn.style["margin-left"] = "5px";
57
+ btn.appendChild(btnTxt);
58
+ btn.addEventListener("click", generateDockerCmd, false);
59
+ parentEle.appendChild(btn);
60
+ }
61
+ }
62
+ };
63
+
64
+ window.addEventListener("hashchange", attachButton, false);
65
+ attachButton();
66
+ })();
@@ -0,0 +1,66 @@
1
+ // ==UserScript==
2
+ // @name Maril
3
+ // @namespace https://github.com/agate/maril
4
+ // @version <%= gemspec.version %>
5
+ // @description <%= gemspec.summary %>
6
+ // @author <%= gemspec.authors.map.with_index{ |a, i| "#{a}<#{gemspec.email[i]}>" }.join(", ") %>
7
+ // @match http://PUT.YOUR.MARATHON.DOMAIN.HERE/*
8
+ // @grant GM_xmlhttpRequest
9
+ // @grant GM_setClipboard
10
+ // ==/UserScript==
11
+
12
+ (function() {
13
+ 'use strict';
14
+
15
+ let currentAppId = null;
16
+
17
+ const generateDockerCmd = () => {
18
+ let url = `${location.origin}/v2/apps${currentAppId}`;
19
+ GM_xmlhttpRequest({
20
+ method: "GET",
21
+ url: url,
22
+ onload: function(response) {
23
+ let app = JSON.parse(response.responseText).app;
24
+ let cmd = [ "docker run --rm -it" ];
25
+
26
+ for (var key in app.env) {
27
+ cmd.push(`-e ${key}=${app.env[key]}`);
28
+ }
29
+ app.container.docker.parameters.forEach((parameter) => {
30
+ cmd.push(`--${parameter.key} ${parameter.value}`);
31
+ });
32
+ app.container.docker.portMappings.forEach((mapping) => {
33
+ cmd.push(`-p ${mapping.containerPort}:${mapping.containerPort}`);
34
+ });
35
+ cmd.push(app.container.docker.image);
36
+
37
+ GM_setClipboard(cmd.join(" "));
38
+ alert("Already saved the docker run command into your clipboard.");
39
+ },
40
+ onerror: (response) => {
41
+ alert("error");
42
+ }
43
+ });
44
+ };
45
+
46
+ const attachButton = () => {
47
+ let hash = window.location.hash.slice(1);
48
+ if (hash.match(/^\/apps\/[^/]+$/)) {
49
+ let appId = decodeURIComponent(hash.slice(6));
50
+ if (currentAppId != appId) {
51
+ currentAppId = appId;
52
+ let parentEle = document.querySelector('.header-btn');
53
+ let btn = document.createElement('a');
54
+ let btnTxt = document.createTextNode("Generate Docker CMD");
55
+ btn.setAttribute("class", "btn btn-lg btn-default");
56
+ btn.style["margin-left"] = "5px";
57
+ btn.appendChild(btnTxt);
58
+ btn.addEventListener("click", generateDockerCmd, false);
59
+ parentEle.appendChild(btn);
60
+ }
61
+ }
62
+ };
63
+
64
+ window.addEventListener("hashchange", attachButton, false);
65
+ attachButton();
66
+ })();
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maril
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - agate
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-08-03 00:00:00.000000000 Z
11
+ date: 2017-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -104,6 +104,8 @@ files:
104
104
  - lib/maril/generator.rb
105
105
  - lib/maril/version.rb
106
106
  - maril.gemspec
107
+ - userscript/maril.user.js
108
+ - userscript/maril.user.js.erb
107
109
  homepage: https://github.com/agate/maril
108
110
  licenses:
109
111
  - MIT