ish_models 3.1.0.14 → 3.1.0.16

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: 1aab599eebe7e7fcb66958056c67d337fc71feddc43f98f562fe28a796e29e69
4
- data.tar.gz: 045e67c9ab3c47f4ec686655e02cad051e908b209081c0e88d6d0e59cb0a3309
3
+ metadata.gz: 9979bc99e29824d443826f24d71e64f31bc868419515883b43574b4a3754e6c9
4
+ data.tar.gz: d467751ef81aaf1572fe8f510be942f2355b1d20b7964769145c319d912fdb94
5
5
  SHA512:
6
- metadata.gz: 372ba4f962dfdfaad225c65d2480442f88687b9dbcec47e140a3091fe3a10c3a0a6d0b075a0f7820f5ab13538ce981ddc1def307bb52009121118d3c38227e40
7
- data.tar.gz: b00cc88b5c384d4fc683d59529bc3363c0e340387d27407af96162e8f0c53d0de780d250154e3ebaa4d99d6d73dd7d5115d632b93b684c909e240d6b633d37a8
6
+ metadata.gz: 3cf5af678f0b416eee707ecfe4b539523b6628b4bdd6566b089ea319a925cc3742c117f91a11539ad5661d2cfad22535e28e1424e58a5ea7471ed7da99d5e1fb
7
+ data.tar.gz: df8e575d99195b7a8fff8d41ab7647fbddc1cadfef51dfa27885d5f95fcfb0e29c997ce074cce0e5d5daac9d59d26c95120b513f87489f93277b55a15ec994e9
data/README.txt ADDED
@@ -0,0 +1,2 @@
1
+
2
+ IshModels, soon to be WcoModels
@@ -13,8 +13,8 @@ class Wco::Leadset
13
13
  index({ email: 1 }, { name: 'email' })
14
14
  validates :email, presence: true, uniqueness: true
15
15
 
16
- has_many :profiles, class_name: 'Wco::Profile', inverse_of: :leadset
17
- has_many :appliances, class_name: 'WcoHosting::Appliance', inverse_of: :leadset
16
+ has_many :profiles, class_name: 'Wco::Profile', inverse_of: :leadset
17
+ has_many :appliances, class_name: 'WcoHosting::Appliance', inverse_of: :leadset
18
18
 
19
19
  has_many :serverhosts, class_name: 'WcoHosting::Serverhost', inverse_of: :leadset
20
20
  def next_serverhost
@@ -4,21 +4,14 @@ class WcoHosting::Appliance
4
4
  include Mongoid::Timestamps
5
5
  store_in collection: 'wco_appliances'
6
6
 
7
- field :name
8
- validates :name, uniqueness: { scope: :leadset }, presence: true
9
- before_validation :set_name, on: :create, unless: ->{ name }
10
- def set_name
11
- name = "#{Time.now.strftime('%Y%m%d')}-#{(0...8).map { (65 + rand(26)).chr }.join}"
12
- end
13
-
14
7
  belongs_to :leadset, class_name: 'Wco::Leadset', inverse_of: :appliances
15
8
 
16
-
17
-
18
-
19
- field :kind
20
-
21
9
  field :service_name
10
+ before_validation :set_service_name, on: :create, unless: ->{ service_name }
11
+ def set_service_name
12
+ self[:service_name] = host.gsub(".", "_")
13
+ end
14
+
22
15
  field :environment
23
16
 
24
17
  field :subdomain
@@ -27,13 +20,15 @@ class WcoHosting::Appliance
27
20
  "#{subdomain}.#{domain}"
28
21
  end
29
22
 
30
- belongs_to :appliance_tmpl, class_name: 'Wco::ApplianceTmpl'
23
+ belongs_to :appliance_tmpl, class_name: 'WcoHosting::ApplianceTmpl'
31
24
  def tmpl
32
25
  appliance_tmpl
33
26
  end
27
+ def kind
28
+ tmpl.kind
29
+ end
34
30
 
35
- belongs_to :serverhost, class_name: 'Wco::Serverhost'
36
- belongs_to :wco_leadset, class_name: 'Wco::Leadset', inverse_of: :appliances
31
+ belongs_to :serverhost, class_name: 'WcoHosting::Serverhost'
37
32
 
38
33
  # field :ip
39
34
  field :port
@@ -47,7 +47,7 @@ class WcoHosting::ApplianceTmpl
47
47
  KIND_JENKINS, KIND_MATOMO, KIND_MOODLE, KIND_PRESTASHOP, KIND_SMT,
48
48
  KIND_WORDPRESS ]
49
49
 
50
- has_many :appliances, class_name: 'Wco::Appliance'
50
+ has_many :appliances, class_name: 'WcoHosting::Appliance'
51
51
 
52
52
  def self.latest_of kind
53
53
  where({ kind: kind }).order_by({ version: :desc }).first
@@ -1,5 +1,6 @@
1
1
 
2
2
  require 'net/scp'
3
+ require 'open3'
3
4
 
4
5
  class WcoHosting::Serverhost
5
6
  include Mongoid::Document
@@ -7,13 +8,12 @@ class WcoHosting::Serverhost
7
8
  # include Mongoid::Autoinc
8
9
  store_in collection: 'wco_serverhosts'
9
10
 
10
- field :name, type: :string
11
- # validates :name, uniqueness: { scope: :leadset_id }, presence: true
12
- validates :name, uniqueness: { scope: :wco_leadset }, presence: true
11
+ WORKDIR = "/opt/projects/docker"
12
+
13
+ field :name, type: :string
14
+ validates :name, uniqueness: { scope: :leadset }, presence: true
13
15
 
14
- # field :leadset_id, type: :integer
15
- # has_and_belongs_to_many :leadsets, class_name: 'Wco::Leadset', inverse_of: :serverhosts
16
- belongs_to :wco_leadset, class_name: 'Wco::Leadset'
16
+ belongs_to :leadset, class_name: 'Wco::Leadset'
17
17
 
18
18
  field :next_port, type: :integer, default: 8000
19
19
 
@@ -27,10 +27,39 @@ class WcoHosting::Serverhost
27
27
 
28
28
  has_many :appliances, class_name: 'WcoHosting::Appliance'
29
29
 
30
+ def create_appliance app
31
+ # puts! app, 'Serverhost#create_appliance'
32
+
33
+ create_volume( app )
34
+ add_docker_service( app )
35
+ add_nginx_site( app )
36
+ # load_database( app )
37
+
38
+ ##
39
+ ## DNS add_subdomain
40
+ ##
41
+ # ac = ActionController::Base.new
42
+ # ac.instance_variable_set( :@app, app )
43
+ # rendered_str = ac.render_to_string("wco_hosting/scripts/create_subdomain.json")
44
+ # # puts '+++ add_subdomain rendered_str:'; print rendered_str
45
+
46
+ # file = Tempfile.new('prefix')
47
+ # file.write rendered_str
48
+ # file.close
49
+
50
+ # cmd = "aws route53 change-resource-record-sets \
51
+ # --hosted-zone-id <%= app.route53_zone %> \
52
+ # --change-batch file://<%= file.path %> "
53
+ # puts! cmd, 'cmd'
54
+ # `#{cmd}`
55
+
56
+ update({ next_port: app.serverhost.next_port + 1 })
57
+ end
58
+
30
59
  def add_nginx_site app
31
60
  ac = ActionController::Base.new
32
61
  ac.instance_variable_set( :@app, app )
33
- rendered_str = ac.render_to_string("scripts/nginx_site.conf")
62
+ rendered_str = ac.render_to_string("wco_hosting/scripts/nginx_site.conf")
34
63
  puts '+++ add_nginx_site rendered_str:'
35
64
  print rendered_str
36
65
 
@@ -50,21 +79,18 @@ class WcoHosting::Serverhost
50
79
  puts! cmd, 'cmd'
51
80
  `#{cmd}`
52
81
 
53
- cmd = "ssh #{ssh_host} 'certbot run -d #{app.origin} --nginx -n ' "
82
+ cmd = "ssh #{ssh_host} 'certbot run -d #{app.host} --nginx -n ' "
54
83
  puts! cmd, 'cmd'
55
84
  `#{cmd}`
56
-
57
85
  end
58
86
 
59
- WORKDIR = "/opt/projects/docker"
60
-
61
87
  def add_docker_service app
62
88
  puts! app, '#add_docker_service'
63
89
 
64
90
  ac = ActionController::Base.new
65
91
  ac.instance_variable_set( :@app, app )
66
92
  ac.instance_variable_set( :@workdir, WORKDIR )
67
- rendered_str = ac.render_to_string("docker-compose/dc-#{app.kind}")
93
+ rendered_str = ac.render_to_string("wco_hosting/docker-compose/dc-#{app.tmpl.kind}")
68
94
  puts '+++ add_docker_service rendered_str:'
69
95
  print rendered_str
70
96
 
@@ -90,7 +116,7 @@ class WcoHosting::Serverhost
90
116
  ac = ActionController::Base.new
91
117
  ac.instance_variable_set( :@app, app )
92
118
  ac.instance_variable_set( :@workdir, WORKDIR )
93
- rendered_str = ac.render_to_string("scripts/create_volume")
119
+ rendered_str = ac.render_to_string("wco_hosting/scripts/create_volume")
94
120
  # puts '+++ create_volume rendered_str:'
95
121
  # print rendered_str
96
122
 
@@ -104,7 +130,7 @@ class WcoHosting::Serverhost
104
130
  `#{cmd}`
105
131
 
106
132
  cmd = "ssh #{ssh_host} 'chmod a+x #{WORKDIR}/scripts/create_volume ; \
107
- #{WORKDIR}/scripts/create_volume ' "
133
+ #{WORKDIR}/wco_hosting/scripts/create_volume ' "
108
134
  puts! cmd, 'cmd'
109
135
  `#{cmd}`
110
136
 
@@ -112,12 +138,14 @@ class WcoHosting::Serverhost
112
138
  end
113
139
 
114
140
  def create_volume app
141
+ # puts! app.service_name, 'Serverhost#create_volume'
142
+
115
143
  ac = ActionController::Base.new
116
144
  ac.instance_variable_set( :@app, app )
117
145
  ac.instance_variable_set( :@workdir, WORKDIR )
118
- rendered_str = ac.render_to_string("scripts/create_volume")
119
- # puts '+++ create_volume rendered_str:'
120
- # print rendered_str
146
+ rendered_str = ac.render_to_string("wco_hosting/scripts/create_volume")
147
+ puts '+++ create_volume rendered_str:'
148
+ print rendered_str
121
149
 
122
150
  file = Tempfile.new('prefix')
123
151
  file.write rendered_str
@@ -125,15 +153,39 @@ class WcoHosting::Serverhost
125
153
  # puts! file.path, 'file.path'
126
154
 
127
155
  cmd = "scp #{file.path} #{ssh_host}:#{WORKDIR}/scripts/create_volume"
128
- puts! cmd, 'cmd'
129
- `#{cmd}`
156
+ do_exec( cmd )
130
157
 
131
- cmd = "ssh #{ssh_host} 'chmod a+x #{WORKDIR}/scripts/create_volume ; \
132
- #{WORKDIR}/scripts/create_volume ' "
133
- puts! cmd, 'cmd'
134
- `#{cmd}`
158
+ cmd = "ssh #{ssh_host} 'chmod a+x #{WORKDIR}/scripts/create_volume ; #{WORKDIR}/scripts/create_volume ' "
159
+ do_exec( cmd )
135
160
 
136
161
  puts 'ok #create_volume'
162
+ return done_exec
163
+ end
164
+
165
+ def self.list
166
+ [[nil,nil]] + all.map { |s| [s.name, s.id] }
167
+ # all.map { |s| [s.name, s.id] }
168
+ end
169
+
170
+ def do_exec cmd
171
+ @messages ||= []
172
+ @errors ||= []
173
+ @statuses ||= []
174
+
175
+ puts! cmd, '#do_exec'
176
+ stdout, stderr, status = Open3.capture3(cmd)
177
+ puts "+++ +++ stdout"
178
+ puts stdout
179
+ @messages.push( stdout )
180
+ puts "+++ +++ stderr"
181
+ puts stderr
182
+ @errors.push( stderr )
183
+ puts! status, 'status'
184
+ @statuses.push( status.to_s.split.last.to_i )
185
+ end
186
+
187
+ def done_exec
188
+ OpenStruct.new( statuses: @statuses, errors: @errors, messages: @messages )
137
189
  end
138
190
 
139
191
 
@@ -0,0 +1,16 @@
1
+ version: '3.2'
2
+
3
+ services:
4
+
5
+ <%= @app.service_name %>:
6
+ image: <%= @app.tmpl.image %>
7
+ volumes:
8
+ - type: bind
9
+ source: volumes/<%= @app.service_name %>_data
10
+ target: /var/www/html
11
+ ports:
12
+ - <%= @app.port %>:80
13
+ restart: always
14
+
15
+
16
+
@@ -0,0 +1,16 @@
1
+ version: '3.2'
2
+
3
+ services:
4
+
5
+ <%= @app.service_name %>:
6
+ image: <%= @app.tmpl.image %>
7
+ volumes:
8
+ - type: bind
9
+ source: volumes/<%= @app.service_name %>_data
10
+ target: /var/www/html
11
+ ports:
12
+ - <%= @app.port %>:80
13
+ restart: always
14
+
15
+
16
+
@@ -0,0 +1,16 @@
1
+ version: '3.2'
2
+
3
+ services:
4
+
5
+ <%= @app.service_name %>:
6
+ image: <%= @app.tmpl.image %>
7
+ volumes:
8
+ - type: bind
9
+ source: volumes/<%= @app.service_name %>_data
10
+ target: /var/www/html
11
+ ports:
12
+ - <%= @app.port %>:80
13
+ restart: always
14
+
15
+
16
+
@@ -0,0 +1,16 @@
1
+
2
+
3
+ {
4
+ "Comment": "optional",
5
+ "Changes": [
6
+ {
7
+ "Action": "CREATE",
8
+ "ResourceRecordSet": {
9
+ "Name": "<%= @app.origin %>",
10
+ "Type": "A",
11
+ "TTL": 3600,
12
+ "ResourceRecords": [{ "Value": "<%= @app.serverhost.public_ip %>" }]
13
+ }
14
+ }
15
+ ]
16
+ }
@@ -0,0 +1,21 @@
1
+ #!/bin/bash
2
+
3
+ set -ex
4
+
5
+ cd <%= @workdir %>
6
+ rm -rf __MACOSX
7
+
8
+ ## cache/overwrite
9
+ [ ! -e <%= @app.kind %>__prototype.zip ] && curl <%= @app.tmpl.volume_zip %> > <%= @app.kind %>__prototype.zip
10
+ # curl <%= @app.tmpl.volume_zip %> > <%= @app.kind %>__prototype.zip
11
+
12
+ ## cache/overwrite
13
+ [ ! -e <%= @app.kind %>__prototype ] && rm -rf <%= @app.kind %>__prototype && unzip <%= @app.kind %>__prototype.zip
14
+ # rm -rf <%= @app.kind %>__prototype && unzip <%= @app.kind %>__prototype.zip
15
+
16
+ mv <%= @app.kind %>__prototype ./volumes/<%= @app.service_name %>_data
17
+
18
+ set +ex
19
+ echo ok #create_volume
20
+
21
+
@@ -0,0 +1,10 @@
1
+
2
+ server {
3
+ listen 443 ssl;
4
+ server_name <%= @app.host %> ;
5
+ location / {
6
+ proxy_pass http://127.0.0.1:<%= @app.port %>/;
7
+ }
8
+ # ssl_certificate /etc/letsencrypt/live/<%= @app.host %>/fullchain.pem; # managed by Certbot
9
+ # ssl_certificate_key /etc/letsencrypt/live/<%= @app.host %>/privkey.pem; # managed by Certbot
10
+ }
data/lib/ish_models.rb CHANGED
@@ -8,22 +8,22 @@ module Wco; end
8
8
  module WcoEmail; end
9
9
  module WcoHosting; end
10
10
 
11
- require 'wco/lead'
12
- require 'wco/leadset'
13
- require 'wco/office_action'
14
- require 'wco/profile'
15
- require 'wco/tag'
16
-
17
- require 'wco_email/campaign'
18
- require 'wco_email/context'
19
- require 'wco_email/conversation'
20
- require 'wco_email/email_filter'
21
- require 'wco_email/message_template'
22
- require 'wco_email/scheduled_email_action'
23
-
24
- require 'wco_hosting/appliance'
25
- require 'wco_hosting/appliance_tmpl'
26
- require 'wco_hosting/domain'
27
- require 'wco_hosting/serverhost'
11
+ # require 'wco/lead'
12
+ # require 'wco/leadset'
13
+ # require 'wco/office_action'
14
+ # require 'wco/profile'
15
+ # require 'wco/tag'
16
+
17
+ # require 'wco_email/campaign'
18
+ # require 'wco_email/context'
19
+ # require 'wco_email/conversation'
20
+ # require 'wco_email/email_filter'
21
+ # require 'wco_email/message_template'
22
+ # require 'wco_email/scheduled_email_action'
23
+
24
+ # require 'wco_hosting/appliance'
25
+ # require 'wco_hosting/appliance_tmpl'
26
+ # require 'wco_hosting/domain'
27
+ # require 'wco_hosting/serverhost'
28
28
 
29
29
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ish_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0.14
4
+ version: 3.1.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - mac_a2141
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-20 00:00:00.000000000 Z
11
+ date: 2023-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -129,6 +129,7 @@ executables: []
129
129
  extensions: []
130
130
  extra_rdoc_files: []
131
131
  files:
132
+ - README.txt
132
133
  - Rakefile
133
134
  - app/assets/config/ish_models_manifest.js
134
135
  - app/assets/stylesheets/ish_models/application.css
@@ -136,28 +137,33 @@ files:
136
137
  - app/helpers/ish_models/application_helper.rb
137
138
  - app/jobs/ish_models/application_job.rb
138
139
  - app/mailers/ish_models/application_mailer.rb
139
- - app/models/ish_models/application_record.rb
140
+ - app/models/wco/lead.rb
141
+ - app/models/wco/leadset.rb
142
+ - app/models/wco/office_action.rb
143
+ - app/models/wco/profile.rb
144
+ - app/models/wco/tag.rb
145
+ - app/models/wco_email/campaign.rb
146
+ - app/models/wco_email/context.rb
147
+ - app/models/wco_email/conversation.rb
148
+ - app/models/wco_email/email_filter.rb
149
+ - app/models/wco_email/message_template.rb
150
+ - app/models/wco_email/scheduled_email_action.rb
151
+ - app/models/wco_email/tag.rb-trash
152
+ - app/models/wco_hosting/appliance.rb
153
+ - app/models/wco_hosting/appliance_tmpl.rb
154
+ - app/models/wco_hosting/domain.rb
155
+ - app/models/wco_hosting/serverhost.rb
140
156
  - app/views/layouts/ish_models/application.html.erb
157
+ - app/views/wco_hosting/docker-compose/dc-any.erb
158
+ - app/views/wco_hosting/docker-compose/dc-helloworld.erb
159
+ - app/views/wco_hosting/docker-compose/dc-wordpress.erb
160
+ - app/views/wco_hosting/scripts/create_subdomain.json.erb
161
+ - app/views/wco_hosting/scripts/create_volume.erb
162
+ - app/views/wco_hosting/scripts/nginx_site.conf.erb
141
163
  - config/routes.rb
142
164
  - lib/ish_models.rb
143
165
  - lib/ish_models/engine.rb
144
166
  - lib/tasks/ish_models_tasks.rake
145
- - lib/wco/lead.rb
146
- - lib/wco/leadset.rb
147
- - lib/wco/office_action.rb
148
- - lib/wco/profile.rb
149
- - lib/wco/tag.rb
150
- - lib/wco_email/campaign.rb
151
- - lib/wco_email/context.rb
152
- - lib/wco_email/conversation.rb
153
- - lib/wco_email/email_filter.rb
154
- - lib/wco_email/message_template.rb
155
- - lib/wco_email/scheduled_email_action.rb
156
- - lib/wco_email/tag.rb-trash
157
- - lib/wco_hosting/appliance.rb
158
- - lib/wco_hosting/appliance_tmpl.rb
159
- - lib/wco_hosting/domain.rb
160
- - lib/wco_hosting/serverhost.rb
161
167
  homepage: https://wasya.co
162
168
  licenses:
163
169
  - MIT
@@ -1,5 +0,0 @@
1
- module IshModels
2
- class ApplicationRecord < ActiveRecord::Base
3
- self.abstract_class = true
4
- end
5
- end
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes