mogura 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
  SHA256:
3
- metadata.gz: f6bc5aa33e336d1e5be7f39cdad45b4bce529b57318c2f54e86b11c3b6860c41
4
- data.tar.gz: 52a22d938b4a4a15b8a3f87d991a504ae4c0bc977f6ced0760934a42faf951b3
3
+ metadata.gz: a7bc99ba170afdf2a79a4b395696a3c99feb49ed62e8bb3fdf452cc31d486e17
4
+ data.tar.gz: a1d5dcae347ed59d3ed3983985a46938888c909bdd6ec69297ca00cf2c6e8ebb
5
5
  SHA512:
6
- metadata.gz: 36ebc243e929de22263e22274ddef440502fedc3dd6916741d4da5ad0b38108ffaa418d44cb79cf6f2e4ce1976d1850059c2f209160862ed14e432240da8d4a3
7
- data.tar.gz: 5682cd2395b0fb2a8f392f70c7f706ccd2cc7bb292277ea86917f8a9c9a61464f75d6da5521350aab9f96858f2f0b58d0d8f7dba1cd78369b8244f1929dcfcee
6
+ metadata.gz: cecdedf6ddd4b39586e9f9bb6cd6529092f0f493a2bbd2bd324aad62aa0ce5203edad4f0da08411f1b8e5ef08464fd0a0867f4a81174020ee4db8f6b1613e49d
7
+ data.tar.gz: 62eccaeeb61cd60152798422f2891557487b32ed94c34300ee9a42609fc5bb98f14be29eaeca5ccb636bcef757d6891e2a57299625eb41b74b2358645ef81b4e
@@ -0,0 +1,38 @@
1
+ name: Apply
2
+ on:
3
+ push:
4
+ branches:
5
+ - main
6
+ env:
7
+ GIT_USER_NAME: ${{ secrets.GIT_USER_NAME }}
8
+ GIT_USER_EMAIL: ${{ secrets.GIT_USER_EMAIL }}
9
+ GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
10
+ jobs:
11
+ mogura:
12
+ permissions:
13
+ actions: write
14
+ checks: write
15
+ contents: write
16
+ deployments: write
17
+ issues: write
18
+ packages: write
19
+ pull-requests: write
20
+ repository-projects: write
21
+ security-events: write
22
+ statuses: write
23
+ runs-on: ubuntu-latest
24
+ defaults:
25
+ run:
26
+ shell: bash
27
+ steps:
28
+ - uses: actions/checkout@v3
29
+ - name: Set up Ruby
30
+ uses: ruby/setup-ruby@v1
31
+ with:
32
+ ruby-version: '3.0.3'
33
+ - name: Deploy
34
+ run: |
35
+ git config --global user.name "$GIT_USER_NAME"
36
+ git config --global user.name "$GIT_USER_EMAIL"
37
+ bundle install
38
+ bundle exec rake release
@@ -0,0 +1,24 @@
1
+ name: Plan
2
+ on:
3
+ pull_request:
4
+ branches:
5
+ - main
6
+ jobs:
7
+ mogura:
8
+ runs-on: ubuntu-latest
9
+ defaults:
10
+ run:
11
+ shell: bash
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+ - name: Set up Ruby
15
+ uses: ruby/setup-ruby@v1
16
+ with:
17
+ ruby-version: '3.0.3'
18
+ - name: Build
19
+ run: |
20
+ bundle install
21
+ - name: Test
22
+ run: |
23
+ bundle exec rspec
24
+ bundle exec rubocop
data/Gemfile CHANGED
@@ -5,4 +5,5 @@ gemspec
5
5
 
6
6
  gem "rake", "~> 12.0"
7
7
  gem "rspec", "~> 3.0"
8
- gem 'pry'
8
+ gem "rubocop", "~> 1.36.0"
9
+ gem 'pry'
data/Gemfile.lock CHANGED
@@ -1,90 +1,93 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mogura (0.1.0)
4
+ mogura (0.1.1)
5
+ fileutils
5
6
  rails
6
- thor
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- actioncable (7.0.2.4)
12
- actionpack (= 7.0.2.4)
13
- activesupport (= 7.0.2.4)
11
+ actioncable (7.0.4)
12
+ actionpack (= 7.0.4)
13
+ activesupport (= 7.0.4)
14
14
  nio4r (~> 2.0)
15
15
  websocket-driver (>= 0.6.1)
16
- actionmailbox (7.0.2.4)
17
- actionpack (= 7.0.2.4)
18
- activejob (= 7.0.2.4)
19
- activerecord (= 7.0.2.4)
20
- activestorage (= 7.0.2.4)
21
- activesupport (= 7.0.2.4)
16
+ actionmailbox (7.0.4)
17
+ actionpack (= 7.0.4)
18
+ activejob (= 7.0.4)
19
+ activerecord (= 7.0.4)
20
+ activestorage (= 7.0.4)
21
+ activesupport (= 7.0.4)
22
22
  mail (>= 2.7.1)
23
23
  net-imap
24
24
  net-pop
25
25
  net-smtp
26
- actionmailer (7.0.2.4)
27
- actionpack (= 7.0.2.4)
28
- actionview (= 7.0.2.4)
29
- activejob (= 7.0.2.4)
30
- activesupport (= 7.0.2.4)
26
+ actionmailer (7.0.4)
27
+ actionpack (= 7.0.4)
28
+ actionview (= 7.0.4)
29
+ activejob (= 7.0.4)
30
+ activesupport (= 7.0.4)
31
31
  mail (~> 2.5, >= 2.5.4)
32
32
  net-imap
33
33
  net-pop
34
34
  net-smtp
35
35
  rails-dom-testing (~> 2.0)
36
- actionpack (7.0.2.4)
37
- actionview (= 7.0.2.4)
38
- activesupport (= 7.0.2.4)
36
+ actionpack (7.0.4)
37
+ actionview (= 7.0.4)
38
+ activesupport (= 7.0.4)
39
39
  rack (~> 2.0, >= 2.2.0)
40
40
  rack-test (>= 0.6.3)
41
41
  rails-dom-testing (~> 2.0)
42
42
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
43
- actiontext (7.0.2.4)
44
- actionpack (= 7.0.2.4)
45
- activerecord (= 7.0.2.4)
46
- activestorage (= 7.0.2.4)
47
- activesupport (= 7.0.2.4)
43
+ actiontext (7.0.4)
44
+ actionpack (= 7.0.4)
45
+ activerecord (= 7.0.4)
46
+ activestorage (= 7.0.4)
47
+ activesupport (= 7.0.4)
48
48
  globalid (>= 0.6.0)
49
49
  nokogiri (>= 1.8.5)
50
- actionview (7.0.2.4)
51
- activesupport (= 7.0.2.4)
50
+ actionview (7.0.4)
51
+ activesupport (= 7.0.4)
52
52
  builder (~> 3.1)
53
53
  erubi (~> 1.4)
54
54
  rails-dom-testing (~> 2.0)
55
55
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
56
- activejob (7.0.2.4)
57
- activesupport (= 7.0.2.4)
56
+ activejob (7.0.4)
57
+ activesupport (= 7.0.4)
58
58
  globalid (>= 0.3.6)
59
- activemodel (7.0.2.4)
60
- activesupport (= 7.0.2.4)
61
- activerecord (7.0.2.4)
62
- activemodel (= 7.0.2.4)
63
- activesupport (= 7.0.2.4)
64
- activestorage (7.0.2.4)
65
- actionpack (= 7.0.2.4)
66
- activejob (= 7.0.2.4)
67
- activerecord (= 7.0.2.4)
68
- activesupport (= 7.0.2.4)
59
+ activemodel (7.0.4)
60
+ activesupport (= 7.0.4)
61
+ activerecord (7.0.4)
62
+ activemodel (= 7.0.4)
63
+ activesupport (= 7.0.4)
64
+ activestorage (7.0.4)
65
+ actionpack (= 7.0.4)
66
+ activejob (= 7.0.4)
67
+ activerecord (= 7.0.4)
68
+ activesupport (= 7.0.4)
69
69
  marcel (~> 1.0)
70
70
  mini_mime (>= 1.1.0)
71
- activesupport (7.0.2.4)
71
+ activesupport (7.0.4)
72
72
  concurrent-ruby (~> 1.0, >= 1.0.2)
73
73
  i18n (>= 1.6, < 2)
74
74
  minitest (>= 5.1)
75
75
  tzinfo (~> 2.0)
76
+ ast (2.4.2)
76
77
  builder (3.2.4)
77
78
  coderay (1.1.3)
78
79
  concurrent-ruby (1.1.10)
79
80
  crass (1.0.6)
80
81
  diff-lcs (1.5.0)
81
82
  digest (3.1.0)
82
- erubi (1.10.0)
83
+ erubi (1.11.0)
84
+ fileutils (1.6.0)
83
85
  globalid (1.0.0)
84
86
  activesupport (>= 5.0)
85
- i18n (1.10.0)
87
+ i18n (1.12.0)
86
88
  concurrent-ruby (~> 1.0)
87
- loofah (2.17.0)
89
+ json (2.6.2)
90
+ loofah (2.19.0)
88
91
  crass (~> 1.0.2)
89
92
  nokogiri (>= 1.5.9)
90
93
  mail (2.7.1)
@@ -92,7 +95,7 @@ GEM
92
95
  marcel (1.0.2)
93
96
  method_source (1.0.0)
94
97
  mini_mime (1.1.2)
95
- minitest (5.15.0)
98
+ minitest (5.16.3)
96
99
  net-imap (0.2.3)
97
100
  digest
98
101
  net-protocol
@@ -108,44 +111,50 @@ GEM
108
111
  net-protocol
109
112
  timeout
110
113
  nio4r (2.5.8)
111
- nokogiri (1.13.4-x86_64-darwin)
114
+ nokogiri (1.13.8-x86_64-darwin)
112
115
  racc (~> 1.4)
113
- nokogiri (1.13.4-x86_64-linux)
116
+ nokogiri (1.13.8-x86_64-linux)
114
117
  racc (~> 1.4)
118
+ parallel (1.22.1)
119
+ parser (3.1.2.1)
120
+ ast (~> 2.4.1)
115
121
  pry (0.14.1)
116
122
  coderay (~> 1.1)
117
123
  method_source (~> 1.0)
118
124
  racc (1.6.0)
119
- rack (2.2.3)
120
- rack-test (1.1.0)
121
- rack (>= 1.0, < 3)
122
- rails (7.0.2.4)
123
- actioncable (= 7.0.2.4)
124
- actionmailbox (= 7.0.2.4)
125
- actionmailer (= 7.0.2.4)
126
- actionpack (= 7.0.2.4)
127
- actiontext (= 7.0.2.4)
128
- actionview (= 7.0.2.4)
129
- activejob (= 7.0.2.4)
130
- activemodel (= 7.0.2.4)
131
- activerecord (= 7.0.2.4)
132
- activestorage (= 7.0.2.4)
133
- activesupport (= 7.0.2.4)
125
+ rack (2.2.4)
126
+ rack-test (2.0.2)
127
+ rack (>= 1.3)
128
+ rails (7.0.4)
129
+ actioncable (= 7.0.4)
130
+ actionmailbox (= 7.0.4)
131
+ actionmailer (= 7.0.4)
132
+ actionpack (= 7.0.4)
133
+ actiontext (= 7.0.4)
134
+ actionview (= 7.0.4)
135
+ activejob (= 7.0.4)
136
+ activemodel (= 7.0.4)
137
+ activerecord (= 7.0.4)
138
+ activestorage (= 7.0.4)
139
+ activesupport (= 7.0.4)
134
140
  bundler (>= 1.15.0)
135
- railties (= 7.0.2.4)
141
+ railties (= 7.0.4)
136
142
  rails-dom-testing (2.0.3)
137
143
  activesupport (>= 4.2.0)
138
144
  nokogiri (>= 1.6)
139
- rails-html-sanitizer (1.4.2)
145
+ rails-html-sanitizer (1.4.3)
140
146
  loofah (~> 2.3)
141
- railties (7.0.2.4)
142
- actionpack (= 7.0.2.4)
143
- activesupport (= 7.0.2.4)
147
+ railties (7.0.4)
148
+ actionpack (= 7.0.4)
149
+ activesupport (= 7.0.4)
144
150
  method_source
145
151
  rake (>= 12.2)
146
152
  thor (~> 1.0)
147
153
  zeitwerk (~> 2.5)
154
+ rainbow (3.1.1)
148
155
  rake (12.3.3)
156
+ regexp_parser (2.5.0)
157
+ rexml (3.2.5)
149
158
  rspec (3.11.0)
150
159
  rspec-core (~> 3.11.0)
151
160
  rspec-expectations (~> 3.11.0)
@@ -159,15 +168,29 @@ GEM
159
168
  diff-lcs (>= 1.2.0, < 2.0)
160
169
  rspec-support (~> 3.11.0)
161
170
  rspec-support (3.11.0)
162
- strscan (3.0.1)
171
+ rubocop (1.36.0)
172
+ json (~> 2.3)
173
+ parallel (~> 1.10)
174
+ parser (>= 3.1.2.1)
175
+ rainbow (>= 2.2.2, < 4.0)
176
+ regexp_parser (>= 1.8, < 3.0)
177
+ rexml (>= 3.2.5, < 4.0)
178
+ rubocop-ast (>= 1.20.1, < 2.0)
179
+ ruby-progressbar (~> 1.7)
180
+ unicode-display_width (>= 1.4.0, < 3.0)
181
+ rubocop-ast (1.21.0)
182
+ parser (>= 3.1.1.0)
183
+ ruby-progressbar (1.11.0)
184
+ strscan (3.0.4)
163
185
  thor (1.2.1)
164
- timeout (0.2.0)
165
- tzinfo (2.0.4)
186
+ timeout (0.3.0)
187
+ tzinfo (2.0.5)
166
188
  concurrent-ruby (~> 1.0)
189
+ unicode-display_width (2.3.0)
167
190
  websocket-driver (0.7.5)
168
191
  websocket-extensions (>= 0.1.0)
169
192
  websocket-extensions (0.1.5)
170
- zeitwerk (2.5.4)
193
+ zeitwerk (2.6.0)
171
194
 
172
195
  PLATFORMS
173
196
  x86_64-darwin-19
@@ -178,6 +201,7 @@ DEPENDENCIES
178
201
  pry
179
202
  rake (~> 12.0)
180
203
  rspec (~> 3.0)
204
+ rubocop (~> 1.36.0)
181
205
 
182
206
  BUNDLED WITH
183
- 2.3.12
207
+ 2.3.22
data/README.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  Digdag REST API and Ruby language API bridge for Rails.
4
4
 
5
+ ## Project Focus
6
+
7
+ https://dev.to/kentfujii/ive-created-a-tiny-library-connecting-rails-and-digdag-42d2
8
+
5
9
  ## Installation
6
10
 
7
11
  Add this line to your Rails application's Gemfile:
@@ -18,15 +22,39 @@ $ bundle install
18
22
 
19
23
  ## Usage
20
24
 
21
- ```
22
- $ bundle exec mogura help
23
- Commands:
24
- mogura help [COMMAND] # Describe available commands or one specific command
25
- mogura init # Initialize Digdag files
26
- mogura push # Push Digdag workflows
27
- mogura version # Prints version
25
+ ```ruby
26
+ # config/initializers/mogura.rb
27
+ Mogura.configure do |config|
28
+ config.endpoint = 'http://digdag:65432'
29
+ end
28
30
  ```
29
31
 
32
+ ```ruby
33
+ # lib/taksks/mogura.rake
34
+ namespace :mogura do
35
+ desc "create or update project"
36
+ task :push, [:project] => :environment do |_, args|
37
+ sample_dag = Mogura::Builder::Dag.build(
38
+ name: 'sample_dag',
39
+ tasks: {
40
+ "timezone": "Asia/Tokyo",
41
+ "schedule": {
42
+ "minutes_interval>": "1"
43
+ },
44
+ "+say_hello": {
45
+ "echo>": "Hello world!!!!"
46
+ }
47
+ }
48
+ )
49
+ Mogura::Project::Put.project(project: args.project, dags: [sample_dag])
50
+ end
51
+
52
+ desc "delete project"
53
+ task :delete, [:project_id] => :environment do |_, args|
54
+ Mogura::Project::Delete.project(id: args.project_id)
55
+ end
56
+ end
57
+ ```
30
58
 
31
59
  ## Development
32
60
 
data/docker-compose.yml CHANGED
@@ -1,8 +1,4 @@
1
1
  version: "3"
2
- networks:
3
- default:
4
- external: true
5
- name: katana
6
2
  services:
7
3
  mogura:
8
4
  build:
@@ -20,4 +16,4 @@ services:
20
16
  environment:
21
17
  POSTGRES_USER: mogura
22
18
  POSTGRES_PASSWORD: password
23
- POSTGRES_DB: mogura
19
+ POSTGRES_DB: mogura
@@ -0,0 +1,24 @@
1
+ module Mogura
2
+ module Builder
3
+ class Dag
4
+ class << self
5
+ def build(name: '', tasks: {})
6
+
7
+ dag = Struct.new("Dag", :name, :tasks) do
8
+ def content
9
+ export = {
10
+ "_export": {
11
+ "rb": {
12
+ "require": Rails.root.join('config/environment').to_s
13
+ }
14
+ }
15
+ }.freeze
16
+ JSON.pretty_generate(export.merge(tasks))
17
+ end
18
+ end
19
+ dag.new(name, tasks)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,9 @@
1
+ module Mogura
2
+ class Configuration
3
+ attr_accessor :endpoint
4
+
5
+ def initialize
6
+ @endpoint = "http://localhost:65432".freeze
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,97 @@
1
+ require 'rails'
2
+ require 'rubygems'
3
+ require 'rubygems/package'
4
+ require 'zlib'
5
+ require 'fileutils'
6
+ require 'net/http'
7
+ require 'uri'
8
+
9
+ module Mogura
10
+ module Project
11
+ class Get
12
+ class << self
13
+ def projects
14
+ uri = URI.parse("#{Mogura.config.endpoint}/api/projects")
15
+ response = Net::HTTP.get_response(uri)
16
+ JSON.parse(response.body)
17
+ end
18
+
19
+ def project
20
+ # https://docs.digdag.io/api/
21
+ raise NotImplementedError, "You must implement #{self.name}##{__method__}"
22
+ end
23
+ end
24
+ end
25
+
26
+ class Put
27
+ class << self
28
+ FILE_MODE = 33188
29
+ DIG_EXT = '.dig'.freeze
30
+
31
+ def project(project: Rails.application.class.module_parent_name, dags: [])
32
+ upload(gzip(tar(dags)), Mogura.config.endpoint, project, revision)
33
+ end
34
+
35
+ def secret
36
+ # https://docs.digdag.io/api/
37
+ raise NotImplementedError, "You must implement #{self.name}##{__method__}"
38
+ end
39
+
40
+ private
41
+
42
+ def tar(dags)
43
+ tarfile = StringIO.new("")
44
+ Gem::Package::TarWriter.new(tarfile) do |tar|
45
+ dags.each do |dag|
46
+ tar.add_file "#{dag.name}#{DIG_EXT}", FILE_MODE do |tf|
47
+ tf.write dag.content
48
+ end
49
+ end
50
+ end
51
+ tarfile
52
+ end
53
+
54
+ def gzip(tarfile)
55
+ gz = StringIO.new("")
56
+ z = Zlib::GzipWriter.new(gz)
57
+ z.write tarfile.string
58
+ z.close
59
+ StringIO.new(gz.string, binmode: true)
60
+ end
61
+
62
+ def revision
63
+ SecureRandom.hex(10)
64
+ end
65
+
66
+ def upload(gzip, endpoint, project, revision)
67
+ uri = URI.parse("#{endpoint}/api/projects?project=#{project}&revision=#{revision}")
68
+ request = Net::HTTP::Put.new(uri)
69
+ request.content_type = "application/gzip"
70
+ request.body = gzip.read
71
+ req_options = {
72
+ use_ssl: uri.scheme == "https",
73
+ }
74
+ Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
75
+ http.request(request)
76
+ end
77
+ end
78
+ end
79
+ end
80
+
81
+ class Delete
82
+ class << self
83
+ def project(id:)
84
+ uri = URI.parse("#{Mogura.config.endpoint}/api/projects/#{id}")
85
+ request = Net::HTTP::Delete.new(uri)
86
+ req_options = {
87
+ use_ssl: uri.scheme == "https",
88
+ }
89
+ Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
90
+ http.request(request)
91
+ end
92
+
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
@@ -1,3 +1,3 @@
1
1
  module Mogura
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/mogura.rb CHANGED
@@ -1,4 +1,16 @@
1
- require "mogura/init"
2
- require "mogura/push"
3
1
  require "mogura/version"
2
+ require "mogura/builder"
3
+ require "mogura/configuration"
4
+ require "mogura/project"
4
5
 
6
+ module Mogura
7
+ class << self
8
+ def config
9
+ @config ||= Configuration.new
10
+ end
11
+
12
+ def configure
13
+ yield config
14
+ end
15
+ end
16
+ end
data/mogura.gemspec CHANGED
@@ -22,9 +22,8 @@ Gem::Specification.new do |spec|
22
22
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
23
  end
24
24
  spec.bindir = "bin"
25
- spec.executables = ["mogura"]
26
25
  spec.require_paths = ["lib"]
27
26
 
28
27
  spec.add_dependency "rails"
29
- spec.add_dependency 'thor'
28
+ spec.add_dependency 'fileutils'
30
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mogura
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
  - KentFujii
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-02 00:00:00.000000000 Z
11
+ date: 2022-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: thor
28
+ name: fileutils
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -41,11 +41,12 @@ dependencies:
41
41
  description: Digdag REST API and Ruby language API bridge for Rails
42
42
  email:
43
43
  - kent.where.the.light.is@gmail.com
44
- executables:
45
- - mogura
44
+ executables: []
46
45
  extensions: []
47
46
  extra_rdoc_files: []
48
47
  files:
48
+ - ".github/workflows/apply.yml"
49
+ - ".github/workflows/plan.yml"
49
50
  - ".gitignore"
50
51
  - ".rspec"
51
52
  - CODE_OF_CONDUCT.md
@@ -56,13 +57,13 @@ files:
56
57
  - README.md
57
58
  - Rakefile
58
59
  - bin/console
59
- - bin/mogura
60
60
  - bin/setup
61
61
  - digdag.properties
62
62
  - docker-compose.yml
63
63
  - lib/mogura.rb
64
- - lib/mogura/init.rb
65
- - lib/mogura/push.rb
64
+ - lib/mogura/builder.rb
65
+ - lib/mogura/configuration.rb
66
+ - lib/mogura/project.rb
66
67
  - lib/mogura/version.rb
67
68
  - mogura.gemspec
68
69
  homepage: https://github.com/KentFujii/mogura
@@ -71,8 +72,8 @@ licenses:
71
72
  metadata:
72
73
  homepage_uri: https://github.com/KentFujii/mogura
73
74
  source_code_uri: https://github.com/KentFujii/mogura
74
- changelog_uri: https://github.com/KentFujii/mogura/blob/v0.1.0/CHANGELOG.md
75
- post_install_message:
75
+ changelog_uri: https://github.com/KentFujii/mogura/blob/v0.1.1/CHANGELOG.md
76
+ post_install_message:
76
77
  rdoc_options: []
77
78
  require_paths:
78
79
  - lib
@@ -87,8 +88,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
88
  - !ruby/object:Gem::Version
88
89
  version: '0'
89
90
  requirements: []
90
- rubygems_version: 3.2.33
91
- signing_key:
91
+ rubygems_version: 3.2.32
92
+ signing_key:
92
93
  specification_version: 4
93
94
  summary: Digdag bridge for Rails
94
95
  test_files: []
data/bin/mogura DELETED
@@ -1,29 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require 'mogura'
5
- require 'thor'
6
- module Mogura
7
- module CLI
8
- class Runner < Thor
9
- desc 'version', 'Prints version'
10
- def version
11
- say "Mogura #{Mogura::VERSION}"
12
- end
13
-
14
- desc 'init', 'Initialize Digdag files'
15
- def init
16
- Mogura::Init.init
17
- end
18
-
19
- desc 'push', 'Push Digdag workflows'
20
- method_option :endpoint, aliases: '-e', type: :string, desc: 'Endpoint of Digdag'
21
- def push
22
- opts = options.to_h.symbolize_keys
23
- Mogura::Push.push(**opts.freeze)
24
- end
25
- end
26
- end
27
- end
28
-
29
- Mogura::CLI::Runner.start
data/lib/mogura/init.rb DELETED
@@ -1,52 +0,0 @@
1
- require 'rails'
2
-
3
- module Mogura
4
- class Init
5
- CONFIG_PATH = 'config/digdag'.freeze
6
- APP_PATH = 'app/dags'.freeze
7
-
8
- class << self
9
- def init
10
- require File.expand_path('config/environment') unless ENV['environment'] == 'test'
11
- init_dig
12
- init_dag
13
- end
14
-
15
- private
16
-
17
- def init_dig
18
- Dir.mkdir(Rails.root.join('config/digdag').to_s)
19
- out_file = File.new(Rails.root.join("#{CONFIG_PATH}/sample.dig").to_s, "w")
20
- out_file.puts(dig_sample_content)
21
- out_file.close
22
- end
23
-
24
- def init_dag
25
- Dir.mkdir(Rails.root.join('app/dags').to_s)
26
- out_sample_file = File.new(Rails.root.join("#{APP_PATH}/sample_dag.rb").to_s, "w")
27
- out_sample_file.puts(dag_sample_content)
28
- out_sample_file.close
29
- end
30
-
31
- def dig_sample_content
32
- <<~TEXT
33
- _export:
34
- rb:
35
- require: #{Rails.root.join('config/environment').to_s}
36
- +run:
37
- rb>: SampleDag.run
38
- TEXT
39
- end
40
-
41
- def dag_sample_content
42
- <<~TEXT
43
- class SampleDag
44
- def run
45
- puts "Hello Rails \#{Rails.env}"
46
- end
47
- end
48
- TEXT
49
- end
50
- end
51
- end
52
- end
data/lib/mogura/push.rb DELETED
@@ -1,74 +0,0 @@
1
- require 'rails'
2
- require 'rubygems'
3
- require 'rubygems/package'
4
- require 'zlib'
5
- require 'fileutils'
6
- require 'net/http'
7
- require 'uri'
8
-
9
- module Mogura
10
- class Push
11
- DEFAULT_ENDPOINT = 'http://localhost:65432'.freeze
12
-
13
- class << self
14
- def push(endpoint: DEFAULT_ENDPOINT)
15
- require File.expand_path('config/environment') unless ENV['environment'] == 'test'
16
- upload(gzip(tar(path)), endpoint, project, revision)
17
- end
18
-
19
- private
20
-
21
- def path
22
- Rails.root.join('config/digdag').to_s
23
- end
24
-
25
- def tar(path)
26
- tarfile = StringIO.new("")
27
- Gem::Package::TarWriter.new(tarfile) do |tar|
28
- Dir[File.join(path, "**/*")].each do |file|
29
- mode = File.stat(file).mode
30
- relative_file = file.sub /^#{Regexp::escape path}\/?/, ''
31
-
32
- if File.directory?(file)
33
- tar.mkdir relative_file, mode
34
- else
35
- tar.add_file relative_file, mode do |tf|
36
- File.open(file, "rb") { |f| tf.write f.read }
37
- end
38
- end
39
- end
40
- end
41
- tarfile
42
- end
43
-
44
- def gzip(tarfile)
45
- gz = StringIO.new("")
46
- z = Zlib::GzipWriter.new(gz)
47
- z.write tarfile.string
48
- z.close
49
- StringIO.new(gz.string, binmode: true)
50
- end
51
-
52
- def project
53
- Rails.application.class.module_parent_name
54
- end
55
-
56
- def revision
57
- SecureRandom.hex(10)
58
- end
59
-
60
- def upload(gzip, endpoint, project, revision)
61
- uri = URI.parse("#{endpoint}/api/projects?project=#{project}&revision=#{revision}")
62
- request = Net::HTTP::Put.new(uri)
63
- request.content_type = "application/gzip"
64
- request.body = gzip.read
65
- req_options = {
66
- use_ssl: uri.scheme == "https",
67
- }
68
- Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
69
- http.request(request)
70
- end
71
- end
72
- end
73
- end
74
- end