socotra-build 0.3.23 → 0.3.24

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/socotra-build.rb +0 -8
  3. data/lib/tenant.rb +97 -0
  4. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ff371fbd0cce6094dd41d75aa93b08441817c241
4
- data.tar.gz: aea9ada6a6b9abd515c590b3bb8789e58fe1a2d6
3
+ metadata.gz: 6960b35e032078950542ff01f1c5de7dd7d42a8e
4
+ data.tar.gz: 7e2e9661906dc669bd4902bc6c8799be5d3b8c97
5
5
  SHA512:
6
- metadata.gz: cf449a0e65e799b2ffc07bd932ba8b4e61a9e38f047729c27d90476195c23812bcc8ac9924a96910b66a8b352545fab296b2b792ae4c011504be9b4fbe18f275
7
- data.tar.gz: 678c50e680c4070cc7acc7bff3539466824774fe25375d86e455f5e8518ce40d00372c58fa55360cd3778a73566fc6930b6ed2dfe2bada1ac2bc7a341811e861
6
+ metadata.gz: 8b030a780150b700c042dfb4c23f164c1122c8b9cac7a1632183ef2e892e5a4c1d3555d186669e66a2303f10bab1f21f3f17019a2fa2b4b0e40ef6a01a275293
7
+ data.tar.gz: 18a2c7e4befe1ab594477fbcbedd01468e5244ee677ee0891482a1a19b5eb720efbdb3c13bba54619db325664cd5014750f665f642dd80c80d00e1c68c546b20
data/lib/socotra-build.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require 'open3'
2
2
  require 'set'
3
- require_relative 's3_uploader'
4
3
 
5
4
  def self.safe_retry(cmd, description, error_message="command failed", raise_on_fail=true, log_level="ERROR", log=true, tries=3)
6
5
  begin
@@ -135,10 +134,3 @@ def self.install_socotra_py_modules(pymodule, environment)
135
134
  cmd = "/usr/bin/yes|sudo pip install --trusted-host socotra-pypi-euw1.s3-website-eu-west-1.amazonaws.com --extra-index-url=http://socotra-pypi-euw1.s3-website-eu-west-1.amazonaws.com/#{pymodule}/#{environment} #{pymodule}"
136
135
  system_safe(cmd, "install_#{pymodule}_py_module", "Failed to install #{pymodule}")
137
136
  end
138
-
139
- def self.sync_logs(repo, build_id)
140
- cmd = "cp -f console.log logs/"
141
- system_safe(cmd, "copy_console_log", "Failed to copy console log")
142
-
143
- upload_to_s3("logs", "socotra-builds/#{repo}/#{build_id}")
144
- end
data/lib/tenant.rb ADDED
@@ -0,0 +1,97 @@
1
+ require "json"
2
+ require "httpclient"
3
+ require "open-uri"
4
+ require "zlib"
5
+ require "rubygems/package"
6
+ require "tempfile"
7
+ require "yaml"
8
+
9
+ def self.get_url(url)
10
+ timeout = 1200
11
+ c = HTTPClient.new
12
+ c.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE
13
+ c.ssl_config.timeout = timeout
14
+ connection_exceptions = [HTTPClient::BadResponseError, HTTPClient::ConnectTimeoutError]
15
+
16
+ begin
17
+ ssl_tries ||= timeout
18
+ dns_tries ||= timeout
19
+ http_tries ||= timeout
20
+ content = c.get_content(url)
21
+ rescue OpenSSL::SSL::SSLError
22
+ if (ssl_tries -= 1) > 0
23
+ sleep 1
24
+ retry
25
+ else
26
+ puts "ERROR: ELB is up, but instances are not (SSL)"
27
+ $build_failure = true
28
+ end
29
+ rescue *connection_exceptions
30
+ if (http_tries -= 1) > 0
31
+ sleep 1
32
+ retry
33
+ else
34
+ puts "ERROR: ELB is up, but instances are not (HTTP)"
35
+ $build_failure = true
36
+ end
37
+ rescue SocketError
38
+ if (dns_tries -= 1) > 0
39
+ sleep 1
40
+ retry
41
+ else
42
+ puts "ERROR: DNS record not created"
43
+ $build_failure = true
44
+ end
45
+ else
46
+ return content
47
+ end
48
+ end
49
+
50
+ def self.load_production_assets(version, github_username, github_password, tenant_name, domain, socotra_username, socotra_password, api_url, apidoc_url)
51
+ url = "https://github.com/socotra/prime/archive/#{version}.tar.gz"
52
+ assets_dir = Dir.mktmpdir
53
+ assets_artifact = "#{assets_dir}/#{version}.tar.gz"
54
+
55
+ open(assets_artifact, "w").write(open(url, :http_basic_authentication => [github_username, github_password]).read)
56
+
57
+ tar_extract = Gem::Package::TarReader.new(Zlib::GzipReader.open(assets_artifact))
58
+ tar_extract.rewind
59
+ tar_extract.each do |entry|
60
+ if entry.file?
61
+ FileUtils.mkdir_p(File.dirname("#{assets_dir}/#{entry.full_name}"))
62
+ File.open("#{assets_dir}/#{entry.full_name}", "wb") do |f|
63
+ f.write(entry.read)
64
+ end
65
+ File.chmod(entry.header.mode, "#{assets_dir}/#{entry.full_name}")
66
+ end
67
+ end
68
+ tar_extract.close
69
+
70
+ cmd = "socotraadmin tenant add_tenant #{tenant_name} --tenant_hostname=#{tenant_name}.co.#{domain} --tenant_path=#{assets_dir}/prime-#{version} --overwrite_ontology --admin_username=#{socotra_username} --admin_password=#{socotra_password} --apidoc_url=#{apidoc_url} --api_url=#{api_url}"
71
+ system_safe(cmd, "load_prod_assets_for_pr", "Failed to load prod asset for PR")
72
+ end
73
+
74
+ def self.load_tabular_datasources(jwtsecret, api_url, apidoc_url, admin_username, admin_password, tenant_name)
75
+ cmd = "socotraadmin tabular_datasource create_bulk \
76
+ --jwtsecret=#{$jwtsecret} \
77
+ --api_url=#{$api_url} \
78
+ --apidoc_url=#{$apidoc_url} \
79
+ --admin_username=#{$admin_username} \
80
+ --admin_password=#{$admin_password} \
81
+ #{$tenant_name} \
82
+ $(pwd)/data/tables.json"
83
+ system_safe(cmd, "load_tabular_datasources", "Failed to load tabular datasources")
84
+ end
85
+
86
+ def self.load_assets_from_branch(tenant_name, domain, admin_username, admin_password, api_url, apidoc_url)
87
+ cmd = "socotraadmin tenant add_tenant #{tenant_name} --overwrite_ontology --tenant_hostname=#{tenant_name}.co.#{domain} --tenant_path=. --admin_username=#{admin_username} --admin_password=#{admin_password} --apidoc_url=#{apidoc_url} --api_url=#{api_url}"
88
+
89
+ system_safe(cmd, "load_branch_assets_for_pr", "Failed to load prod asset for PR")
90
+ end
91
+
92
+ def self.load_tasks(version, environment, tenant_name)
93
+ cmd = "sg docker -c \'tasker --path=reports --tag=#{$version} --environment=#{$environment} --timezone='Africa/Kigali' --tenant=#{$tenant_name} -v\'"
94
+ system_safe(cmd, "load_tasks", "Failed to load task for PR")
95
+ end
96
+
97
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: socotra-build
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.23
4
+ version: 0.3.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Antenesse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-05 00:00:00.000000000 Z
11
+ date: 2015-12-20 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Common functions for build
14
14
  email: chris.antenesse@socotra.com
@@ -19,6 +19,7 @@ files:
19
19
  - lib/s3_uploader.rb
20
20
  - lib/socotra-build-update.rb
21
21
  - lib/socotra-build.rb
22
+ - lib/tenant.rb
22
23
  homepage: http://rubygems.org/gems/socotra
23
24
  licenses:
24
25
  - MIT