Skip to content

Instantly share code, notes, and snippets.

@wynemo
Last active October 3, 2015 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save wynemo/2477430 to your computer and use it in GitHub Desktop.
Save wynemo/2477430 to your computer and use it in GitHub Desktop.
openshift python tutorail

ubuntu 11.10 install openshift client tools

  • ruby stuff

      $ sudo aptitude install ruby
      $ sudo aptitude install rubygems
      $ sudo gem install json_pure
      $ sudo gem install rake
      $ sudo gem install rhc
    
  • fix the error file mime-types-1.18.gemspec then re-install all gems needed

      #should be line 9, changed it to: s.date = %q{2012-03-21}
      $ sudo vim /var/lib/gems/1.8/specifications/mime-types-1.18.gemspec 
      $ sudo gem install json_pure
      $ sudo gem install rake
      $ sudo gem install rhc
    

###now play with openshift

  1. apply a account on https://openshift.redhat.com/, get your email,password

     #create a domain(namespace)
     $ rhc domain create -n domain -l email  
     #create a app
     $ rhc app create -a appname -t python-2.6 -l email
     #now you will get folder named `appname`        
    
  2. if your app is new app created int step 1,skip this step

     #create keys
     $ ssh-keygen -t rsa -f ~/.ssh/libra_id_rsa -C email  
     #add public key
     $ rhc sshkey add -i public_key_name -k ~/.ssh/libra_id_rsa.pub  -l email
     #edit your ssh config   
     $ cat ~/.ssh/config
     Host *.rhcloud.com
     IdentityFile ~/.ssh/libra_id_rsa 
    
  3. show git url $ rhc domain status -l email

     $ rhc domain show -l email
     Git URL: ssh://some_random@appname-domain.rhcloud.com/~/git/api.git/
    
  4. then you can ssh,make yourself at home

     $ssh some_random@appname-domain.rhcloud.com
    
  5. git stuff

     #clone your app by git url or it's alreay created by step 1
     #modify setup.py
     $ cd appname
     #change install_requires=[''],use django,web.py,bottle or something
     $ vim setup.py 
     $ cd wsgi
     #use django web.py wsgi 
     #webpy example <https://github.com/ehazlett/openshift-webpy-example/blob/master/wsgi/application>
     $ vim application   
     #add and commit
     $ git push
    
  6. python stuff,get your project home folder if want to use web framework's template

     def get_home_dir():
         try:
             dir1 = os.environ['OPENSHIFT_REPO_DIR']
             if dir1.endswith('/') == False:
                 dir1 += '/'
             dir1 += 'wsgi/'
             return dir1
         except:
             return './'#shoud be /,not have permission
    
  7. show log

     $rhc-tail-files -l email -a appname
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment