Standardize installer on 2 spaces

This commit is contained in:
Jose Diaz-Gonzalez committed 2014-11-16 02:59:42 -05:00
1 parent 0f6ca81afd
commit 52774536ca
1 file changed
+96 -96
+96 -96
View File
@@ -3,120 +3,120 @@ require "sinatra"
require "open3" require "open3"
if ARGV[0] == "onboot" if ARGV[0] == "onboot"
File.open("/etc/init/dokku-installer.conf", "w") do |f| File.open("/etc/init/dokku-installer.conf", "w") do |f|
f.puts "start on runlevel [2345]" f.puts "start on runlevel [2345]"
f.puts "exec #{File.absolute_path(__FILE__)} selfdestruct" f.puts "exec #{File.absolute_path(__FILE__)} selfdestruct"
end end
File.open("/etc/nginx/conf.d/dokku-installer.conf", "w") do |f| File.open("/etc/nginx/conf.d/dokku-installer.conf", "w") do |f|
f.puts "upstream dokku-installer { server 127.0.0.1:2000; }" f.puts "upstream dokku-installer { server 127.0.0.1:2000; }"
f.puts "server {" f.puts "server {"
f.puts " listen 80;" f.puts " listen 80;"
f.puts " location / {" f.puts " location / {"
f.puts " proxy_pass http://dokku-installer;" f.puts " proxy_pass http://dokku-installer;"
f.puts " }" f.puts " }"
f.puts "}" f.puts "}"
end end
`rm /etc/nginx/sites-enabled/*` `rm /etc/nginx/sites-enabled/*`
puts "Installed Upstart service and default Nginx virtualhost for installer to run on boot." puts "Installed Upstart service and default Nginx virtualhost for installer to run on boot."
exit exit
end end
dokku_root = ENV["DOKKU_ROOT"] || "/home/dokku"
admin_key = `cat /root/.ssh/authorized_keys`.split("\n").first
hostname = `bash -c '[[ $(dig +short $HOSTNAME) ]] && echo $HOSTNAME || curl icanhazip.com'`.strip
template = DATA.read
version = "v0.3.0" version = "v0.3.0"
dokku_root = ENV["DOKKU_ROOT"] || "/home/dokku"
admin_key = `cat /root/.ssh/authorized_keys`.split("\n").first
hostname = `bash -c '[[ $(dig +short $HOSTNAME) ]] && echo $HOSTNAME || curl icanhazip.com'`.strip
template = DATA.read
set :port, 2000 set :port, 2000
set :environment, :production set :environment, :production
disable :protection disable :protection
get "/" do get "/" do
ERB.new(template).result binding ERB.new(template).result binding
end end
post "/setup" do post "/setup" do
if params[:vhost] == "true" if params[:vhost] == "true"
File.open("#{dokku_root}/VHOST", "w") {|f| f.write params[:hostname] } File.open("#{dokku_root}/VHOST", "w") {|f| f.write params[:hostname] }
else else
`rm #{dokku_root}/VHOST` `rm #{dokku_root}/VHOST`
end end
File.open("#{dokku_root}/HOSTNAME", "w") {|f| f.write params[:hostname] } File.open("#{dokku_root}/HOSTNAME", "w") {|f| f.write params[:hostname] }
Open3.capture2("sshcommand acl-add dokku admin", :stdin_data => params[:key]) Open3.capture2("sshcommand acl-add dokku admin", :stdin_data => params[:key])
Thread.new { Thread.new {
`rm /etc/nginx/conf.d/dokku-installer.conf && /etc/init.d/nginx stop && /etc/init.d/nginx start` `rm /etc/nginx/conf.d/dokku-installer.conf && /etc/init.d/nginx stop && /etc/init.d/nginx start`
`rm /etc/init/dokku-installer.conf && stop dokku-installer` `rm /etc/init/dokku-installer.conf && stop dokku-installer`
}.run if ARGV[0] == "selfdestruct" }.run if ARGV[0] == "selfdestruct"
end end
__END__ __END__
<html> <html>
<head> <head>
<title>Dokku Setup</title> <title>Dokku Setup</title>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" /> <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
</head> </head>
<body> <body>
<div class="container" style="width: 640px;"> <div class="container" style="width: 640px;">
<form id="form" role="form"> <form id="form" role="form">
<h1>Dokku Setup <small><%= version %></small></h1> <h1>Dokku Setup <small><%= version %></small></h1>
<div class="form-group"> <div class="form-group">
<h3><small style="text-transform: uppercase;">Admin Access</small></h3> <h3><small style="text-transform: uppercase;">Admin Access</small></h3>
<label for="key">Public Key</label><br /> <label for="key">Public Key</label><br />
<textarea class="form-control" name="key" rows="7" id="key"><%= admin_key %></textarea> <textarea class="form-control" name="key" rows="7" id="key"><%= admin_key %></textarea>
</div> </div>
<div class="form-group"> <div class="form-group">
<h3><small style="text-transform: uppercase;">Hostname Configuration</small></h3> <h3><small style="text-transform: uppercase;">Hostname Configuration</small></h3>
<div class="form-group"> <div class="form-group">
<label for="hostname">Hostname</label> <label for="hostname">Hostname</label>
<input class="form-control" type="text" id="hostname" name="hostname" value="<%= hostname %>" /> <input class="form-control" type="text" id="hostname" name="hostname" value="<%= hostname %>" />
</div> </div>
<div class="checkbox"> <div class="checkbox">
<label><input id="vhost" name="vhost" type="checkbox" value="true"> Use <abbr title="Nginx will be run on port 80 and backend to your apps based on hostname">virtualhost naming</abbr> for apps</label> <label><input id="vhost" name="vhost" type="checkbox" value="true"> Use <abbr title="Nginx will be run on port 80 and backend to your apps based on hostname">virtualhost naming</abbr> for apps</label>
</div> </div>
<p>Your app URLs will look like:</p> <p>Your app URLs will look like:</p>
<pre id="example">http://hostname:port</pre> <pre id="example">http://hostname:port</pre>
</div> </div>
<button type="button" onclick="setup()" class="btn btn-primary">Finish Setup</button> <span style="padding-left: 20px;" id="result"></span> <button type="button" onclick="setup()" class="btn btn-primary">Finish Setup</button> <span style="padding-left: 20px;" id="result"></span>
</form> </form>
</div> </div>
<div id="error-output"></div> <div id="error-output"></div>
<script> <script>
function setup() { function setup() {
if ($.trim($("#key").val()) == "") { if ($.trim($("#key").val()) == "") {
alert("Your admin public key cannot be blank.") alert("Your admin public key cannot be blank.")
return return
} }
if ($.trim($("#hostname").val()) == "") { if ($.trim($("#hostname").val()) == "") {
alert("Your hostname cannot be blank.") alert("Your hostname cannot be blank.")
return return
} }
data = $("#form").serialize() data = $("#form").serialize()
$("input,textarea,button").prop("disabled", true); $("input,textarea,button").prop("disabled", true);
$.post('/setup', data) $.post('/setup', data)
.done(function() { .done(function() {
$("#result").html("Success!") $("#result").html("Success!")
window.location.href = "http://progrium.viewdocs.io/dokku/application-deployment"; window.location.href = "http://progrium.viewdocs.io/dokku/application-deployment";
}) })
.fail(function(data) { .fail(function(data) {
$("#result").html("Something went wrong...") $("#result").html("Something went wrong...")
$("#error-output").html(data.responseText) $("#error-output").html(data.responseText)
}); });
} }
function update() { function update() {
if ($("#vhost").is(":checked") && $("#hostname").val().match(/^(\d{1,3}\.){3}\d{1,3}$/)) { if ($("#vhost").is(":checked") && $("#hostname").val().match(/^(\d{1,3}\.){3}\d{1,3}$/)) {
alert("In order to use virtualhost naming, the hostname must not be an IP but a valid domain name.") alert("In order to use virtualhost naming, the hostname must not be an IP but a valid domain name.")
$("#vhost").prop('checked', false); $("#vhost").prop('checked', false);
} }
if ($("#vhost").is(':checked')) { if ($("#vhost").is(':checked')) {
$("#example").html("http://&lt;app-name&gt;."+$("#hostname").val()) $("#example").html("http://&lt;app-name&gt;."+$("#hostname").val())
} else { } else {
$("#example").html("http://"+$("#hostname").val()+":&lt;app-port&gt;") $("#example").html("http://"+$("#hostname").val()+":&lt;app-port&gt;")
} }
} }
$("#vhost").change(update); $("#vhost").change(update);
$("#hostname").change(update); $("#hostname").change(update);
update(); update();
</script> </script>
</body> </body>
</html> </html>