ish_models 3.1.0.15 → 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: 878db6bcfd78a87582b23a3edf1fae48aba69227e3147867bb72dc27cf6e4fee
4
- data.tar.gz: 6dd6d2b220b3c5ee8898cbe0801ccadc4f76a1a4247e5086fd825bb1d7988cd1
3
+ metadata.gz: 9979bc99e29824d443826f24d71e64f31bc868419515883b43574b4a3754e6c9
4
+ data.tar.gz: d467751ef81aaf1572fe8f510be942f2355b1d20b7964769145c319d912fdb94
5
5
  SHA512:
6
- metadata.gz: c1cdd9e7fa1872d4af5df0aefe4af23edd0f8a00a6e6acbf6feccd0298f4a61d1b3a522a31f8de134c0174adfc62b5625b06cf7aba2635a89d7788a05431d557
7
- data.tar.gz: 6a6d9e6467c0eb65a982bda906e83cfd628577a7f24fe6d04bebb5a3349bbf77eae1abf38e4b44e69dc911e93dd9ef19516cf191b5eb82ec504b79b0ba43137d
6
+ metadata.gz: 3cf5af678f0b416eee707ecfe4b539523b6628b4bdd6566b089ea319a925cc3742c117f91a11539ad5661d2cfad22535e28e1424e58a5ea7471ed7da99d5e1fb
7
+ data.tar.gz: df8e575d99195b7a8fff8d41ab7647fbddc1cadfef51dfa27885d5f95fcfb0e29c997ce074cce0e5d5daac9d59d26c95120b513f87489f93277b55a15ec994e9
data/README.txt ADDED
@@ -0,0 +1,2 @@
1
+
2
+ IshModels, soon to be WcoModels
@@ -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
@@ -31,6 +24,9 @@ class WcoHosting::Appliance
31
24
  def tmpl
32
25
  appliance_tmpl
33
26
  end
27
+ def kind
28
+ tmpl.kind
29
+ end
34
30
 
35
31
  belongs_to :serverhost, class_name: 'WcoHosting::Serverhost'
36
32
 
@@ -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,6 +8,8 @@ class WcoHosting::Serverhost
7
8
  # include Mongoid::Autoinc
8
9
  store_in collection: 'wco_serverhosts'
9
10
 
11
+ WORKDIR = "/opt/projects/docker"
12
+
10
13
  field :name, type: :string
11
14
  validates :name, uniqueness: { scope: :leadset }, presence: true
12
15
 
@@ -24,10 +27,39 @@ class WcoHosting::Serverhost
24
27
 
25
28
  has_many :appliances, class_name: 'WcoHosting::Appliance'
26
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
+
27
59
  def add_nginx_site app
28
60
  ac = ActionController::Base.new
29
61
  ac.instance_variable_set( :@app, app )
30
- rendered_str = ac.render_to_string("scripts/nginx_site.conf")
62
+ rendered_str = ac.render_to_string("wco_hosting/scripts/nginx_site.conf")
31
63
  puts '+++ add_nginx_site rendered_str:'
32
64
  print rendered_str
33
65
 
@@ -47,21 +79,18 @@ class WcoHosting::Serverhost
47
79
  puts! cmd, 'cmd'
48
80
  `#{cmd}`
49
81
 
50
- cmd = "ssh #{ssh_host} 'certbot run -d #{app.origin} --nginx -n ' "
82
+ cmd = "ssh #{ssh_host} 'certbot run -d #{app.host} --nginx -n ' "
51
83
  puts! cmd, 'cmd'
52
84
  `#{cmd}`
53
-
54
85
  end
55
86
 
56
- WORKDIR = "/opt/projects/docker"
57
-
58
87
  def add_docker_service app
59
88
  puts! app, '#add_docker_service'
60
89
 
61
90
  ac = ActionController::Base.new
62
91
  ac.instance_variable_set( :@app, app )
63
92
  ac.instance_variable_set( :@workdir, WORKDIR )
64
- 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}")
65
94
  puts '+++ add_docker_service rendered_str:'
66
95
  print rendered_str
67
96
 
@@ -87,7 +116,7 @@ class WcoHosting::Serverhost
87
116
  ac = ActionController::Base.new
88
117
  ac.instance_variable_set( :@app, app )
89
118
  ac.instance_variable_set( :@workdir, WORKDIR )
90
- rendered_str = ac.render_to_string("scripts/create_volume")
119
+ rendered_str = ac.render_to_string("wco_hosting/scripts/create_volume")
91
120
  # puts '+++ create_volume rendered_str:'
92
121
  # print rendered_str
93
122
 
@@ -101,7 +130,7 @@ class WcoHosting::Serverhost
101
130
  `#{cmd}`
102
131
 
103
132
  cmd = "ssh #{ssh_host} 'chmod a+x #{WORKDIR}/scripts/create_volume ; \
104
- #{WORKDIR}/scripts/create_volume ' "
133
+ #{WORKDIR}/wco_hosting/scripts/create_volume ' "
105
134
  puts! cmd, 'cmd'
106
135
  `#{cmd}`
107
136
 
@@ -109,12 +138,14 @@ class WcoHosting::Serverhost
109
138
  end
110
139
 
111
140
  def create_volume app
141
+ # puts! app.service_name, 'Serverhost#create_volume'
142
+
112
143
  ac = ActionController::Base.new
113
144
  ac.instance_variable_set( :@app, app )
114
145
  ac.instance_variable_set( :@workdir, WORKDIR )
115
- rendered_str = ac.render_to_string("scripts/create_volume")
116
- # puts '+++ create_volume rendered_str:'
117
- # 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
118
149
 
119
150
  file = Tempfile.new('prefix')
120
151
  file.write rendered_str
@@ -122,15 +153,13 @@ class WcoHosting::Serverhost
122
153
  # puts! file.path, 'file.path'
123
154
 
124
155
  cmd = "scp #{file.path} #{ssh_host}:#{WORKDIR}/scripts/create_volume"
125
- puts! cmd, 'cmd'
126
- `#{cmd}`
156
+ do_exec( cmd )
127
157
 
128
- cmd = "ssh #{ssh_host} 'chmod a+x #{WORKDIR}/scripts/create_volume ; \
129
- #{WORKDIR}/scripts/create_volume ' "
130
- puts! cmd, 'cmd'
131
- `#{cmd}`
158
+ cmd = "ssh #{ssh_host} 'chmod a+x #{WORKDIR}/scripts/create_volume ; #{WORKDIR}/scripts/create_volume ' "
159
+ do_exec( cmd )
132
160
 
133
161
  puts 'ok #create_volume'
162
+ return done_exec
134
163
  end
135
164
 
136
165
  def self.list
@@ -138,4 +167,26 @@ class WcoHosting::Serverhost
138
167
  # all.map { |s| [s.name, s.id] }
139
168
  end
140
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 )
189
+ end
190
+
191
+
141
192
  end
@@ -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.15
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-21 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
File without changes
File without changes