Tag cloud

Tip: How to Get to the OpenShift Shell

I wanted to examine the Perl environment on OpenShift and got tired of making snapshots, unzipping the archive and poking through the files. I wanted a shell. Here's how to get one.

  1. Get the application info first

    $ rhc-domain-info 
    Password: 
    Application Info
    ================
    myapp
        Framework: perl-5.10
         Creation: 2012-03-08T13:34:46-04:00
             UUID: 8946b976ad284cf5b2401caf736186bd
          Git URL: ssh://8946b976ad284cf5b2401caf736186bd@myapp-mydomain.rhcloud.com/~/git/myapp.git/
       Public URL: http://myapp-mydomain.rhcloud.com/
    
     Embedded: 
          None
    
  2. The Git URL has your username and host

  3. Now just ssh into the application

    $ ssh 8946b976ad284cf5b2401caf736186bd@myapp-mydomain.rhcloud.com
    
        Welcome to OpenShift shell
    
        This shell will assist you in managing OpenShift applications.
    
        !!! IMPORTANT !!! IMPORTANT !!! IMPORTANT !!!
        Shell access is quite powerful and it is possible for you to
        accidentally damage your application.  Proceed with care!
        If worse comes to worst, destroy your application with 'rhc app destroy'
        and recreate it
        !!! IMPORTANT !!! IMPORTANT !!! IMPORTANT !!!
    
        Type "help" for more info.
    
    [myapp-mydomain.rhcloud.com ~]\>
    

Voila!

There are comments.

How to Update Dependencies on OpenShift

If you are already running some cool application on OpenShift it could be the case that you have to update some of the packages installed as dependencies. Here is an example for an application using the python-2.6 cartridge.

Pull latest upstream packages

The most simple method is to update everything to the latest upstream versions.

  1. Backup! Backup! Backup!

    rhc-snapshot -a mycoolapp
    mv mycoolapp.tar.gz mycoolapp-backup-before-update.tar.gz
    
  2. If you haven't specified any particular version in setup.py it will look like this:

    ...
    install_requires=[
                    'difio-openshift-python',
                    'MySQL-python',
                    'Markdown',
                   ],
    ...
    
  3. To update simply push to OpenShift instructing it to rebuild your virtualenv:

    cd mycoolapp/
    touch .openshift/markers/force_clean_build
    git add .openshift/markers/force_clean_build
    git commit -m "update to latest upstream"
    git push
    

Voila! The environment hosting your application is rebuilt from scratch.

Keeping some packages unchanged

Suppose that before the update you have Markdown-2.0.1 and you want to keep it! This is easily solved by adding versioned dependency to setup.py

-       'Markdown',
+       'Markdown==2.0.1',

If you do that OpenShift will install the same Markdown version when rebuilding your application. Everything else will use the latest available versions.

Note: after the update it's recommended that you remove the .openshift/markers/force_clean_build file. This will speed up the push/build process and will not surprise you with unwanted changes.

Update only selected packages

Unless your application is really simple or you have tested the updates, I suspect that you want to update only selected packages. This can be done without rebuilding the whole virtualenv. Use versioned dependencies in setup.py :

-       'Markdown==2.0.1',
-       'django-countries',
+       'Markdown>=2.1',
+       'django-countries>=1.1.2',

No need for force_clean_build this time. Just

    git commit && git push

At the time of writing my application was using Markdown-2.0.1 and django-countries-1.0.5. Then it updated to Markdown-2.1.1 and django-countires-1.1.2 which also happened to be the latest versions.

Note: this will not work without force_clean_build

-       'django-countries==1.0.5',
+       'django-countries',

Warning

OpenShift uses a local mirror of Python Package Index. It seems to be updated every 24 hours or so. Have this in mind if you want to update to a package that was just released. It will not work! See How to Deploy Python Hotfix on OpenShift if you wish to work around this limitation.

There are comments.

Spinning-up a Development Instance on OpenShift

Difio is hosted on OpenShift. During development I often need to spin-up another copy of Difio to use for testing and development. With OpenShift this is easy and fast. Here's how:

  1. Create another application on OpenShift. This will be your development instance.

    rhc-create-app -a myappdevel -t python-2.6
    
  2. Find out the git URL for the production application:

    $ rhc-user-info
    Application Info
    ================
    myapp
        Framework: python-2.6
         Creation: 2012-02-10T12:39:53-05:00
             UUID: 723f0331e17041e8b34228f87a6cf1f5
          Git URL: ssh://723f0331e17041e8b34228f87a6cf1f5@myapp-mydomain.rhcloud.com/~/git/myapp.git/
       Public URL: http://myapp-mydomain.rhcloud.com/
    
  3. Push the current code base from the production instance to devel instance:

    cd myappdevel
    git remote add production -m master ssh://723f0331e17041e8b34228f87a6cf1f5@myapp-mydomain.rhcloud.com/~/git/myapp.git/
    git pull -s recursive -X theirs production master
    git push
    
  4. Now your myappdevel is the same as your production instance. You will probably want to modify your database connection settings at this point and start adding new features.

There are comments.


Page 2 / 2