diff --git a/.sample.env b/.sample.env new file mode 100644 index 0000000..e69de29 diff --git a/app/controllers/code_controller.rb b/app/controllers/code_controller.rb index 1f9370f..0c12ced 100644 --- a/app/controllers/code_controller.rb +++ b/app/controllers/code_controller.rb @@ -13,7 +13,7 @@ def evaluate result.rows.map {|row| row.join("\t") }, ].join("\n") elsif params[:system] == "accupacDatabase" - sample_data = File.read(Rails.root.join("../data.json")) + sample_data = File.read(Rails.root.join("data.json")) sample_id = params[:code].scan(/q\d{6}/i).last.upcase render plain: [ diff --git a/bin/deploy b/bin/deploy new file mode 100755 index 0000000..59141b0 --- /dev/null +++ b/bin/deploy @@ -0,0 +1,75 @@ +#!/usr/bin/env ruby + +require "droplet_kit" + +access_token = ARGV[0] + +client = DropletKit::Client.new(access_token: access_token) +ssh_keys = client.ssh_keys.all.collect {|key| key.fingerprint} +server_name = "engine-#{Random.rand(9999)}" + +droplet = DropletKit::Droplet.new( + name: server_name, + region: "nyc1", + image: 23219707, # "Docker 17.03.0-ce on 14.04", + size: "s-1vcpu-1gb", + ssh_keys: ssh_keys, +) + +created = client.droplets.create(droplet) + +puts "Waiting for the server to spin up." +until client.droplets.find(id: created.id).status == "active" + sleep 5 +end +puts "It's up!" +puts + +droplet = client.droplets.find(id: created.id) + +IP = droplet.networks.v4.first.ip_address + +def run(command) + `ssh -o "StrictHostKeyChecking no" root@#{IP} '#{command}'`. + tap { |result| puts result } +end + +puts "Waiting for SSH access" +result = "" +begin + result = run "hostname" + sleep 5 +end until result.to_s.strip == server_name +puts "SSH is up!" +puts + +run "git clone https://github.com/assembleapp/engine.git" +# TODO This should not be necessary once `.sample.env` is included in the repo. +run "cd engine && touch .sample.env" + +run "apt-add-repository ppa:brightbox/ruby-ng" +run "apt-get update -qq" + +# TODO it's not clear if all of these are necessary. +# Various internet searches suggested some combination of these +# as prerequisites of Nokogiri and Postgres. +# We should verify that each item on the list is necessary. +run "apt-get install -y ruby2.5 ruby2.5-dev libgmp-dev libxml2-dev libxslt-dev zlib1g-dev g++ make libpq-dev postgresql" + +# Start up postgres +run "/etc/init.d/postgresql start" +run "sudo -u postgres createuser -s -d -r -e root" + +run "gem install bundler" +run "cd engine && bundle install" +run "cd engine && ./bin/setup" + +run "cd engine && rails s -b 0.0.0.0 -p 80 -d" + +puts "The site is up!" +puts "Visit http://#{IP} in your browser." + +# If on OS X, we can do this automatically +if(`uname -s`.strip == "Darwin") + `open http://#{IP}` +end diff --git a/data.json b/data.json new file mode 100644 index 0000000..90450ee --- /dev/null +++ b/data.json @@ -0,0 +1,6 @@ +id part item customer +Q603540 0123123456 Shaving Cream PharmaGuys +Q603640 0123123456 Shaving Cream PharmaGuys +Q604320 0123123456 Shaving Cream PharmaGuys +Q603740 0123234567 Anti-Cavity Toothpaste Dental Tech +Q604420 0123234567 Anti-Cavity Toothpaste Dental Tech