Class: FullStack
- Inherits:
-
Object
- Object
- FullStack
- Defined in:
- lib/full_stack.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #authenticate ⇒ Object
- #brew_message ⇒ Object
- #download_feed(url) ⇒ Object
-
#initialize(site, options) ⇒ FullStack
constructor
A new instance of FullStack.
- #launch_daemons ⇒ Object
- #run ⇒ Object
- #vae_remote_path ⇒ Object
- #vae_thrift_path ⇒ Object
Constructor Details
#initialize(site, options) ⇒ FullStack
Returns a new instance of FullStack.
4 5 6 7 8 9 |
# File 'lib/full_stack.rb', line 4 def initialize(site, ) @site = site = @stop = false @pids = [] end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
2 3 4 |
# File 'lib/full_stack.rb', line 2 def end |
Instance Method Details
#authenticate ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/full_stack.rb', line 11 def authenticate req = Net::HTTP::Post.new("/api/local/v1/authorize") req.body = "username=#{CGI.escape(@site.username)}&password=#{CGI.escape(@site.password)}" res = VaeLocal.fetch_from_vaeplatform(@site.subdomain, req) data = JSON.parse(res.body) if data['valid'] == "valid" FileUtils.mkdir_p(@site.data_path) if !File.exists?(@site.data_path + "/assets/") FileUtils.ln_s("#{vae_remote_path}/public", @site.data_path + "/assets") end @site.secret_key = data['secret_key'] generation = File.exists?("#{@site.data_path}feed_generation") ? File.open("#{@site.data_path}feed_generation").read.to_i : 0 if data['feed_url'] and data['feed_generation'].to_i > generation puts "Downloading updated Site Data Feed..." if curl = File.which("curl") `curl -o #{Shellwords.shellescape(@site.data_path)}feed.xml #{Shellwords.shellescape(data['feed_url'])}` else download_feed(data['feed_url']) end File.open("#{@site.data_path}feed_generation",'w') { |f| f.write(data['feed_generation']) } end File.open("#{@site.data_path}settings.php",'w') { |f| f.write(data['settings']) } else raise VaeError, "Error Connecting to Vae with the supplied Username and Password. Please make sure this user has Vae Local permissions assigned." end rescue JSON::ParserError raise VaeError, "An unknown error occurred signing into Vae Platform. Please email support for help." end |
#brew_message ⇒ Object
125 126 127 |
# File 'lib/full_stack.rb', line 125 def "\n\nTo install Vae Local Full Stack dependencies on macOS via Homebrew, run the following commands:\n brew tap actionverb/tap\n brew install vae-remote vae-thrift vaeql\n\nMake sure you resolve any errors from Homebrew before proceeding." end |
#download_feed(url) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/full_stack.rb', line 40 def download_feed(url) url_base = url.split('/')[2] url_path = '/'+url.split('/')[3..-1].join('/') Net::HTTP.start(url_base) { |http| File.open("#{@site.data_path}feed.xml", 'w') { |f| http.get(URI.escape(url_path)) { |str| f.write str } } } end |
#launch_daemons ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/full_stack.rb', line 61 def launch_daemons puts "Using Vae daemons at #{vae_thrift_path}" if VaeLocal.port_open?(9090) @pids << fork { Dir.chdir("#{vae_thrift_path}/rb/") STDOUT.reopen("/dev/null", "w") STDERR.reopen("/dev/null", "w") exec "bundle exec ./vaerubyd.rb" } end port = 9091 serve_root = @site.root loop { break if VaeLocal.port_open?(port) port = port + 1 } if File.exists?(@site.root + "/.jekyll") serve_root = @site.root + "/_site/" FileUtils.mkdir_p(serve_root) @pids << fork { exec "bundle exec jekyll build --watch --source #{Shellwords.shellescape(@site.root)} --destination #{Shellwords.shellescape(serve_root)}" } end @pids << fork { Dir.chdir("#{vae_thrift_path}/cpp/") ENV['VAE_LOCAL_VAEDB_PORT'] = port.to_s exec "./vaedb --port #{port} --busaddress 'tcp://*:#{port-4000}' --test --log_level #{options[:log_level]}" } @pids << fork { Dir.chdir(serve_root) ENV['VAE_LOCAL_BACKSTAGE'] = @site.subdomain + ".vaeplatform." + (ENV['VAEPLATFORM_LOCAL'] ? "dev" : "com") ENV['VAE_LOCAL_SECRET_KEY'] = @site.secret_key ENV['VAE_LOCAL_DATA_PATH'] = @site.data_path if [:php_runtime] == "hhvm" ENV['VAE_LOCAL_HHVM'] = "1" exec "hhvm -c #{vae_remote_path}/tests/dependencies/php.ini -m server -d hhvm.pid_file=/tmp/vae_local.hhvm.pid -d auto_prepend_file=#{vae_remote_path}/lib/index.php -d hhvm.server.default_document=#{vae_remote_path}/lib/index.php -d hhvm.server.error_document404=#{vae_remote_path}/lib/index.php -d hhvm.server.port=#{options[:port]} -d hhvm.server.source_root=#{Shellwords.shellescape(@site.root)}" else exec "php -c #{vae_remote_path}/tests/dependencies/php.ini -S 0.0.0.0:#{options[:port]} #{vae_remote_path}/lib/index.php" end } end |
#run ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/full_stack.rb', line 52 def run authenticate launch_daemons trap("INT") { @stop = true } loop { break if @stop; sleep 0.5 } puts "Quit signal received, cleaning up ..." @pids.map { |pid| Process.kill("TERM", pid) } end |
#vae_remote_path ⇒ Object
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/full_stack.rb', line 103 def vae_remote_path return @vae_remote_path if @vae_remote_path thisdir = File.dirname(__FILE__) [ "#{thisdir}/../../vae_remote", "#{thisdir}/../../../vae_remote", "/usr/local/vae_remote", "/usr/local/opt/vae-remote", "/usr/local/Cellar/vae_remote/1.0.0", "~/vae_remote" ].each { |path| if File.exists?(path) and File.exists?(path + "/lib/general.php") return @vae_remote_path = path end } raise VaeError, "Could not find Vae Remote on your system.#{brew_message}" end |
#vae_thrift_path ⇒ Object
114 115 116 117 118 119 120 121 122 123 |
# File 'lib/full_stack.rb', line 114 def vae_thrift_path return @vae_thrift_path if @vae_thrift_path thisdir = File.dirname(__FILE__) [ "#{thisdir}/../../vae_thrift", "#{thisdir}/../../../vae_thrift", "/usr/local/vae_thrift", "/usr/local/opt/vae-thrift", "/usr/local/Cellar/vae_thrift/1.0.0", "~/vae_thrift", "#{vae_remote_path}/tests/dependencies/vae_thrift" ].each { |path| if File.exists?(path) and File.exists?(path + "/cpp/vaedb") return @vae_thrift_path = path end } raise VaeError, "Could not find Vae Thrift on your system.#{brew_message}" end |