ish_models 0.0.33.287 → 0.0.33.291

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
  SHA256:
3
- metadata.gz: 83d872b9868c1bc820cbdcbadfde298a034010095e4f19910f1851d35cca00fd
4
- data.tar.gz: e1fc95e4a71e17c4486389a83ffcf6b1fada942f9e9a71a488f4842c157878b6
3
+ metadata.gz: 257cf440b86a79d5147a9e3147ec4606c92e0e2238a6c11e51eae7fa924d35eb
4
+ data.tar.gz: 9c35232b6ca4a0d026c306576f2916cd7121156626f8aca52c1ff0ac9cc53901
5
5
  SHA512:
6
- metadata.gz: 2a44c1b86067b6b62b9d77c0a94f71d60f3264d7549c8e1b848f17e48bef01d0c415871c95886aa0de3b806eca787669c4a87608734f141875591da6d068dc1a
7
- data.tar.gz: 960ee95e22f7e124d643d566a4b2052f547f02cefeb67e8c1b7f2a69c2d9f07bc75aaa52a722e276803e87e3a2548ba04868e40b7c9ab7f42ddc272d45e2043d
6
+ metadata.gz: 741ac3cfb2a7f6b2a562266dd88f53f091ccd2dc26c792d4f410036035e4660121df479470dd020a882abba2d84a44170b6dc47139f5c3f7753510a7f10c8053
7
+ data.tar.gz: 35ca293da5528f2ced972d41342d3f5f305d5f03e539f8fc83a37793acfa304568b0bed4ed73e7ef99d8f3a1a8b1e9f44f55306a9a33f4ac1ee0950006dfc6c4
data/lib/ish_models.rb CHANGED
@@ -81,6 +81,7 @@ require 'office/scheduled_email_action'
81
81
 
82
82
  require 'wco/appliance'
83
83
  require 'wco/appliance_tmpl'
84
+ require 'wco/leadset'
84
85
  require 'wco/price'
85
86
  require 'wco/product'
86
87
  require 'wco/serverhost'
data/lib/wco/appliance.rb CHANGED
@@ -5,7 +5,10 @@ class Wco::Appliance
5
5
 
6
6
  field :name
7
7
  validates :name, uniqueness: { scope: :leadset_id }, presence: true
8
+
8
9
  field :kind
10
+
11
+ field :service_name
9
12
  field :environment
10
13
 
11
14
  field :subdomain
@@ -19,7 +22,21 @@ class Wco::Appliance
19
22
  Leadset.find leadset_id
20
23
  end
21
24
 
22
- belongs_to :serverhost, class_name: 'Wco::Serverhost'
25
+ belongs_to :appliance_tmpl, class_name: 'Wco::ApplianceTmpl'
26
+ def tmpl
27
+ appliance_tmpl
28
+ end
29
+
30
+ belongs_to :serverhost, class_name: 'Wco::Serverhost'
31
+ belongs_to :wco_leadset, class_name: 'Wco::Leadset', inverse_of: :appliances
32
+
33
+ # field :ip
34
+ field :port
35
+
36
+ STATE_PENDING = 'state-pending'
37
+ STATE_LIVE = 'state-live'
38
+ STATE_TERM = 'state-term'
39
+ field :state, default: STATE_PENDING
23
40
 
24
41
  end
25
42
 
@@ -4,12 +4,33 @@ class Wco::ApplianceTmpl
4
4
  include Mongoid::Timestamps
5
5
 
6
6
  field :kind
7
- validates :kind, uniqueness: true, presence: true
7
+ validates :kind, uniqueness: { scope: :version }, presence: true
8
+
9
+ field :version, type: :string, default: '0.0.0'
10
+ validates :version, uniqueness: { scope: :kind }, presence: true
11
+ index({ kind: -1, version: -1 }, { name: :kind_version })
12
+
13
+ field :descr, type: :string
8
14
 
9
15
  field :image
10
16
  validates :image, presence: true
11
17
 
18
+ field :volume_zip
19
+ validates :volume_zip, presence: true
20
+
12
21
  KIND_CORPHOME1 = 'corphome1'
22
+ KIND_DRUPAL = 'drupal'
13
23
  KIND_HELLOWORLD = 'helloworld'
14
- KINDS = [ 'SMT', 'EmailCRM', KIND_CORPHOME1, KIND_HELLOWORLD, 'Drupal', 'Odoo', 'Mautic', 'IroWor', 'eCommStore1' ]
24
+ # KINDS = [ 'smt', 'emailcrm', KIND_CORPHOME1, KIND_HELLOWORLD, KIND_DRUPAL,
25
+ # 'mautic', 'matomo',
26
+ # 'irowor', 'eCommerce' ]
27
+ KINDS = [ KIND_HELLOWORLD ]
28
+
29
+ has_many :appliances, class_name: 'Wco::Appliance'
30
+
31
+ def self.latest_of kind
32
+ where({ kind: kind }).order_by({ version: :desc }).first
33
+ end
34
+
15
35
  end
36
+ AppTmpl = Wco::ApplianceTmpl
@@ -0,0 +1,17 @@
1
+
2
+ class Wco::Leadset
3
+ include Mongoid::Document
4
+ include Mongoid::Timestamps
5
+
6
+ field :name
7
+
8
+ field :domains, type: :string, default: 'orbital.city'
9
+
10
+ has_many :serverhosts, class_name: 'Wco::Serverhost', inverse_of: :wco_leadset
11
+ def next_serverhost
12
+ serverhosts.first
13
+ end
14
+
15
+ has_many :appliances, class_name: 'Wco::Appliance', inverse_of: :wco_leadset
16
+
17
+ end
@@ -1,6 +1,5 @@
1
1
 
2
2
  require 'net/scp'
3
- # require 'autoinc'
4
3
 
5
4
  class Wco::Serverhost
6
5
  include Mongoid::Document
@@ -8,17 +7,19 @@ class Wco::Serverhost
8
7
  # include Mongoid::Autoinc
9
8
 
10
9
  field :name, type: :string
11
- validates :name, uniqueness: { scope: :leadset_id }, presence: true
10
+ # validates :name, uniqueness: { scope: :leadset_id }, presence: true
11
+ validates :name, uniqueness: { scope: :wco_leadset }, presence: true
12
12
 
13
- field :next_port, type: :integer, default: 8000
14
- # increments :next_port
13
+ # field :leadset_id, type: :integer
14
+ # has_and_belongs_to_many :leadsets, class_name: 'Wco::Leadset', inverse_of: :serverhosts
15
+ belongs_to :wco_leadset, class_name: 'Wco::Leadset'
15
16
 
16
- field :leadset_id, type: :integer
17
+ field :next_port, type: :integer, default: 8000
17
18
 
18
19
  ## net-ssh, sshkit
19
20
  field :ssh_host
20
- field :ssh_username
21
- field :ssh_key
21
+ # field :ssh_username
22
+ # field :ssh_key
22
23
  field :nginx_root, default: '/opt/nginx'
23
24
 
24
25
  has_many :appliances, class_name: 'Wco::Appliance'
@@ -50,49 +51,50 @@ class Wco::Serverhost
50
51
 
51
52
  end
52
53
 
53
- def docker_add_service rendered_str=nil, config={}
54
- # puts! config, '#docker_add_service'
55
- File.write( "/Users/piousbox/projects/docker_demo/dc-#{config[:service_name]}.yml", rendered_str )
56
- out = ` mkdir /Users/piousbox/projects/docker_demo/#{config[:service_name]}_data `
57
- puts! out, 'out'
58
- out = ` cd /Users/piousbox/projects/docker_demo/ ; \
59
- docker compose -f dc-#{config[:service_name]}.yml up -d #{config[:service_name]} ; \
60
- echo ok
61
- `;
62
- puts! out, 'out'
63
- end
54
+ WORKDIR = "/opt/projects/docker"
55
+
56
+ def add_docker_service app={}
57
+ puts! app, '#add_docker_service'
58
+
59
+ ac = ActionController::Base.new
60
+ ac.instance_variable_set( :@app, app )
61
+ ac.instance_variable_set( :@workdir, WORKDIR )
62
+ rendered_str = ac.render_to_string("docker-compose/dc-#{app[:kind]}")
63
+ puts '+++ add_docker_service rendered_str:'
64
+ print rendered_str
65
+
66
+ file = Tempfile.new('prefix')
67
+ file.write rendered_str
68
+ file.close
69
+ puts! file.path, 'file.path'
64
70
 
65
- def load_data rendered_str=nil, config={}
66
- File.write( "/Users/piousbox/projects/docker_demo/#{config[:service_name]}_data/index.html", rendered_str )
71
+ `scp #{file.path} #{ssh_host}:#{WORKDIR}/dc-#{app[:service_name]}.yml`
72
+ `ssh #{ssh_host} 'cd #{WORKDIR} ; \
73
+ docker compose -f dc-#{app[:service_name]}.yml up -d #{app[:service_name]} ; \
74
+ echo ok #add_docker_service ' `
67
75
  end
68
76
 
77
+ def create_volume app={}
78
+ # puts! app, '#create_volume'
69
79
 
70
- end
80
+ ac = ActionController::Base.new
81
+ ac.instance_variable_set( :@app, app )
82
+ ac.instance_variable_set( :@workdir, WORKDIR )
83
+ rendered_str = ac.render_to_string("scripts/create_volume")
84
+ # puts '+++ create_volume rendered_str:'
85
+ # print rendered_str
86
+
87
+ file = Tempfile.new('prefix')
88
+ file.write rendered_str
89
+ file.close
90
+ # puts! file.path, 'file.path'
71
91
 
72
- # class Instance
73
- # def chmod
74
- # start do |ssh|
75
- # ssh.exec "sudo chmod +x /tmp/provision.sh"
76
- # # other operations on ssh
77
- # end
78
- # end
79
- # private
80
- # def start
81
- # Net::SSH.start(ip, 'ubuntu', keys: "mykey.pem" ) do |ssh|
82
- # yield ssh
83
- # end
84
- # end
85
- # end
86
-
87
-
88
- ## works:
89
- # nginx_root = '/opt/nginx'
90
- # config = { service_name: 'abba', }
91
- # Net::SSH.start( "18.209.12.11", "ubuntu", keys: "access/mac_id_rsa_3.pem" ) do |ssh|
92
- # out = ssh.scp.upload! "tmp/#{config[:service_name]}", "/opt/tmp/two.txt" do |ch, name, sent, total|
93
- # puts "#{name}: #{sent}/#{total}"
94
- # end
95
- # puts! out, 'out'
96
- # end
92
+ `scp #{file.path} #{ssh_host}:#{WORKDIR}/scripts/create_volume`
93
+ `ssh #{ssh_host} 'chmod a+x #{WORKDIR}/scripts/create_volume ; \
94
+ #{WORKDIR}/scripts/create_volume ' `
95
+ end
96
+ # alias_method :create_volume, :create_volume_2
97
97
 
98
98
 
99
+ end
100
+
@@ -0,0 +1,45 @@
1
+
2
+
3
+
4
+ # WORKDIR = "/Users/piousbox/projects/docker_wco"
5
+
6
+ # class Instance
7
+ # def chmod
8
+ # start do |ssh|
9
+ # ssh.exec "sudo chmod +x /tmp/provision.sh"
10
+ # # other operations on ssh
11
+ # end
12
+ # end
13
+ # private
14
+ # def start
15
+ # Net::SSH.start(ip, 'ubuntu', keys: "mykey.pem" ) do |ssh|
16
+ # yield ssh
17
+ # end
18
+ # end
19
+ # end
20
+
21
+
22
+ ## works:
23
+ # nginx_root = '/opt/nginx'
24
+ # config = { service_name: 'abba', }
25
+ # Net::SSH.start( "18.209.12.11", "ubuntu", keys: "access/mac_id_rsa_3.pem" ) do |ssh|
26
+ # out = ssh.scp.upload! "tmp/#{config[:service_name]}", "/opt/tmp/two.txt" do |ch, name, sent, total|
27
+ # puts "#{name}: #{sent}/#{total}"
28
+ # end
29
+ # puts! out, 'out'
30
+ # end
31
+
32
+
33
+
34
+
35
+ def create_volume_1 config={}
36
+ puts! config, '#create_volume'
37
+
38
+ out = ` cd #{WORKDIR} ; \
39
+ [ ! -e #{config[:kind]}__prototype.zip ] && wget #{config.tmpl.volume_zip} ; \
40
+ [ ! -e #{config[:kind]}__prototype ] && unzip #{config[:kind]}__prototype.zip ; \
41
+ mv #{config[:kind]}__prototype #{config[:service_name]}_data ; \
42
+ echo ok #create_volume
43
+ `;
44
+ puts! out, 'out'
45
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ish_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.33.287
4
+ version: 0.0.33.291
5
5
  platform: ruby
6
6
  authors:
7
7
  - piousbox
@@ -233,9 +233,11 @@ files:
233
233
  - lib/video.rb
234
234
  - lib/wco/appliance.rb
235
235
  - lib/wco/appliance_tmpl.rb
236
+ - lib/wco/leadset.rb
236
237
  - lib/wco/price.rb
237
238
  - lib/wco/product.rb
238
239
  - lib/wco/serverhost.rb
240
+ - lib/wco/serverhost.rb-trash
239
241
  - lib/wco/subscription.rb
240
242
  homepage: https://wasya.co
241
243
  licenses: