closes #5930. Merge branch '5930-smalldocfix'
[arvados.git] / docker / build_tools / build.rb
index fd5543c3b1874c6d06609e5b05df1b3300848868..e3309a922982647574f266ae7bfbe8d3b0894f58 100755 (executable)
@@ -14,11 +14,16 @@ def main options
   # Check that:
   #   * Docker is installed and can be found in the user's path
   #   * Docker can be run as a non-root user
-  #      - TODO: put the user is in the docker group if necessary
+  #      - TODO: put the user in the docker group if necessary
   #      - TODO: mount cgroup automatically
   #      - TODO: start the docker service if not started
 
-  docker_path = %x(which docker).chomp
+  docker_path = %x(which docker.io).chomp
+
+  if docker_path.empty?
+    docker_path = %x(which docker).chomp
+  end
+
   if docker_path.empty?
     warn "Docker not found."
     warn ""
@@ -28,7 +33,7 @@ def main options
     warn "Installation instructions for a variety of platforms can be found at"
     warn "http://docs.docker.io/en/latest/installation/"
     exit 1
-  elsif not docker_ok?
+  elsif not docker_ok? docker_path
     warn "WARNING: docker could not be run."
     warn "Please make sure that:"
     warn "  * You have permission to read and write /var/run/docker.sock"
@@ -46,28 +51,41 @@ def main options
   # Generate a config.yml if it does not exist or is empty
   if not File.size? 'config.yml'
     print "Generating config.yml.\n"
-    print "Arvados needs to know the email address of the administrative user,\n"
-    print "so that when that user logs in they are automatically made an admin.\n"
-    print "This should be the email address you use to log in to Google.\n"
-    print "\n"
-    admin_email_address = ""
-    until is_valid_email? admin_email_address
-      print "Enter your Google ID email address here: "
-      admin_email_address = gets.strip
-      if not is_valid_email? admin_email_address
-        print "That doesn't look like a valid email address. Please try again.\n"
-      end
-    end
+    # print "Arvados needs to know the email address of the administrative user,\n"
+    # print "so that when that user logs in they are automatically made an admin.\n"
+    # print "This should be an email address associated with a Google account.\n"
+    # print "\n"
+    # admin_email_address = ""
+    # until is_valid_email? admin_email_address
+    #   print "Enter your Google ID email address here: "
+    #   admin_email_address = gets.strip
+    #   if not is_valid_email? admin_email_address
+    #     print "That doesn't look like a valid email address. Please try again.\n"
+    #   end
+    # end
+
+    # print "Arvados needs to know the shell login name for the administrative user.\n"
+    # print "This will also be used as the name for your git repository.\n"
+    # print "\n"
+    # user_name = ""
+    # until is_valid_user_name? user_name
+    #   print "Enter a shell login name here: "
+    #   user_name = gets.strip
+    #   if not is_valid_user_name? user_name
+    #     print "That doesn't look like a valid shell login name. Please try again.\n"
+    #   end
+    # end
 
     File.open 'config.yml', 'w' do |config_out|
+      config_out.write "# If a _PW or _SECRET variable is set to an empty string, a password\n"
+      config_out.write "# will be chosen randomly at build time. This is the\n"
+      config_out.write "# recommended setting.\n\n"
       config = YAML.load_file 'config.yml.example'
-      config['API_AUTO_ADMIN_USER'] = admin_email_address
+      #config['API_AUTO_ADMIN_USER'] = admin_email_address
+      #config['ARVADOS_USER_NAME'] = user_name
       config['API_HOSTNAME'] = generate_api_hostname
-      config['PUBLIC_KEY_PATH'] = find_or_create_ssh_key(config['API_HOSTNAME'])
+      config['API_WORKBENCH_ADDRESS'] = 'false'
       config.each_key do |var|
-        if var.end_with?('_PW') or var.end_with?('_SECRET')
-          config[var] = rand(2**256).to_s(36)
-        end
         config_out.write "#{var}: #{config[var]}\n"
       end
     end
@@ -75,11 +93,12 @@ def main options
 
   # If all prerequisites are met, go ahead and build.
   if ip_forwarding_enabled? and
-      docker_ok? and
+      docker_ok? docker_path and
       debootstrap_ok? and
       File.exists? 'config.yml'
-    warn "Building Arvados."
-    system '/usr/bin/make', '-f', options[:makefile], *ARGV
+    exit 0
+  else
+    exit 6
   end
 end
 
@@ -109,6 +128,15 @@ def is_valid_email? str
   str.match /^\S+@\S+\.\S+$/
 end
 
+# is_valid_user_name?
+#   Returns true if its arg looks like a valid unix username.
+#   This is a very very loose sanity check.
+#
+def is_valid_user_name? str
+  # borrowed from Debian's adduser (version 3.110)
+  str.match /^[_.A-Za-z0-9][-\@_.A-Za-z0-9]*\$?$/
+end
+
 # generate_api_hostname
 #   Generates a 5-character randomly chosen API hostname.
 #
@@ -133,24 +161,8 @@ end
 # docker_ok?
 #   Returns 'true' if docker can be run as the current user.
 #
-def docker_ok?
-  return system 'docker images > /dev/null 2>&1'
-end
-
-# find_or_create_ssh_key arvados_name
-#   Returns the SSH public key appropriate for this Arvados instance,
-#   generating one if necessary.
-#
-def find_or_create_ssh_key arvados_name
-  ssh_key_file = "#{ENV['HOME']}/.ssh/arvados_#{arvados_name}_id_rsa"
-  unless File.exists? ssh_key_file
-    system 'ssh-keygen',
-           '-f', ssh_key_file,
-           '-C', "arvados@#{arvados_name}",
-           '-P', ''
-  end
-
-  return "#{ssh_key_file}.pub"
+def docker_ok?(docker_path)
+  return system "#{docker_path} images > /dev/null 2>&1"
 end
 
 # install_docker
@@ -216,6 +228,5 @@ if __FILE__ == $PROGRAM_NAME
       options[:makefile] = mk
     end
   end
-
   main options
 end