Commits

Brent Tubbs committed b078a09

adding silk build

  • Participants
  • Parent commits 7ef595c

Comments (0)

Files changed (2)

     sudo('virtualenv --no-site-packages --python=%s %s' % (env.config['runtime'], env.envdir))
     build_mx_tools()
 
-def _pip_install_deps(dep_list):
-    # Write it out
-    file_contents = '\n'.join(dep_list)
-    tmpfile = tempfile.NamedTemporaryFile()
-    tmpfile.write(file_contents)
-    tmpfile.seek(0) # Rewind the file so that the putter can read it.
-
-    # Upload it to the remote host
-    tmp_remote = '/tmp/%s-reqs.txt' % ''.join([random.choice('abcdefghijklmnopqrstuvwxyz') for x in xrange(5)])
-    put(tmpfile.name, tmp_remote)
-
-    # Closing a tempfile will clean it up automatically.
-    tmpfile.close()
-
-    # Run pip install remotely
-    pip_cmd = silk.lib.get_pip_cmd(env.config)
-    sudo('%s/bin/%s -r %s' % (env.envdir, pip_cmd, tmp_remote))
-
-    # Clean up remote reqs file
-    sudo('rm %s' % tmp_remote)
-
-def install_python_deps():
-    """
-    Runs pip install inside the remote virtualenv.  First for silk's dependencies and
-    then for the site's.
-    """
-    for dep_dict in (env.config['silk_deps'], env.config['site_deps']):
-        if dep_dict['python_packages']:
-            _pip_install_deps(dep_dict['python_packages'])
-
 def install_deps():
     """
     Wraps the apt deps, virtualenv creation, and python deps functions to ensure
     _write_templates(template_list, env)
     restart()
 
+def build():
+
+    #- check that you're running on ubuntu
+    if not silk.lib.os_is_ubuntu():
+        sys.exit('This command can only be run on Ubuntu')
+    
+    #- Create local directory at /srv/<build_name>
+    local('mkdir %s' % env.remote_root)
+
+    #- Copy all the site code into the build directory
+    local('cp -r %s %s/' % (env.local_root, env.remote_root))
+
+    #- create a virtualenv inside the build directory
+    python_version = env.config['runtime']
+    local_env = '%s/env' % env.remote_root
+    local('virtualenv --no-site-packages --python=%s %s' % (python_version,
+                                                            local_env))
+
+    #- install all python packages into that virtualenv
+        # first create a tmp requirements file
+    dep_list = env.config['site_deps']['python_packages']
+    file_contents = '\n'.join(dep_list)
+    tmpfile = tempfile.NamedTemporaryFile()
+    tmpfile.write(file_contents)
+
+    pip = os.path.join(local_env, 'bin', 'pip')
+    local('%s -r %s' % (pip, tmpfile.name))
+    # Closing a tempfile will clean it up automatically.
+    tmpfile.close()
+    #- create conf and logs folders in the build directory
+    #- write supervisord log file for the build directory
+    pass
+
 def push():
     """
     The main function.  Assuming you have nginx and supervisord installed and
         cmd = '%s/%s' % (bin_dir, cmd)
     return cmd
 
+def os_is_ubuntu():
+    """
+    Examines /etc/issue and looks for the apt-get program to determine whether
+    the current OS is ubuntu.
+    """
+    if not os.path.isfile('/etc/issue'):
+        return False
+    elif not open('/etc/issue', 'r').read().startswith('Ubuntu'):
+        return False
+    elif os.popen('which apt-get').read() == '':
+        return False
+    else:
+        return True
+
 def get_config(site_root=None, role=None):
     """
     Returns merged site and role config.  Tries hard to come up with