Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added .sample.env
Empty file.
2 changes: 1 addition & 1 deletion app/controllers/code_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
75 changes: 75 additions & 0 deletions bin/deploy
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions data.json
Original file line number Diff line number Diff line change
@@ -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