openshiftopenshift-nextgen

How to create a requirements.txt file for OpenShift Online Next Gen Developer Preview?


tl;dr

I am trying to create a requirements.txt file for an existing application that is running locally.

I want to know what contents should go in the requirements.txt file.

I'm doing this in order to get the local application running on:

OpenShift Online (Next Gen) Developer Preview

Detail

myapplication.py has a number of standard import statements, eg:

#  from python standard library

import os
import re
import StringIO
import json
import ast
import struct
import time
import collections

It also contains import statements in the format from X import X, eg:

#  additional modules

from bottle import route, post, default_app, template, view, TEMPLATE_PATH, response, request, static_file, install, redirect
# BEGIN pymongo
import pymongo
from bson.json_util import dumps
import gridfs
# END pymongo
import requests
from bs4 import BeautifulSoup
import lxml
import base64
import tldextract
from PIL import Image
import serial

from beaker.middleware import SessionMiddleware
from cork import Cork
from cork.cork import AuthException
from cork.cork import AAAException
from cork.backends import MongoDBBackend

import user_settings (a local .py file)

When setting up the app locally, I also had to install these from the Ubuntu Software Centre:

apache2
virtualenv
mod_wsgi

And these packages were required for pip installs in virtualenv to work:

python2.7-dev
libxml2-dev
libxslt1-dev
apache2-dev
zlib1g-dev
libjpeg8-dev

These were installed in pip whilst virtualenv was activated:

pip install bottle
pip install https://github.com/FedericoCeratto/bottle-cork/archive/master.zip
pip install requests
pip install pymongo==2.8
pip install beautifulsoup4
pip install lxml
pip install Beaker
pip install pillow
pip install tldextract
pip install serial

Questions

01) Will the contents of my requirements.txt file just need to look like this:

pymongo
requests
lxml
tldextract
pyserial
bottle
git+git://github.com/FedericoCeratto/bottle-cork.git#egg=bottle-cork
beautifulsoup4
Beaker
pillow

02) Will myapplication.py still need to have the import statements as defined above?

03) The following were required for pip installs to work in virtualenv, are these already in the OpenShift environment and, if not, how do I add them?

python2.7-dev
libxml2-dev
libxslt1-dev
apache2-dev
zlib1g-dev
libjpeg8-dev

04) Does requirements.txt live in the top directory of the repo directory?

For reference and further information, these are the results of running pip freeze locally in the virtualenv:

(ENV) me@my-computer:/var/www/html/site-name/ENV$ pip freeze
-markerlib==0.0.0
Beaker==1.8.0
beautifulsoup4==4.4.1
bottle==0.12.9
bottle-cork==0.12.0a2
funcsigs==1.0.0
idna==2.1
lxml==3.6.0
ordereddict==1.1
Pillow==3.2.0
pkg-resources==0.0.0
pycrypto==2.6.1
pymongo==2.8
pyserial==3.0.1
requests==2.9.1
tldextract==1.7.5

Solution

  • 1) This is what I ended up using for requirements.txt:

    pymongo 
    requests
    lxml
    tldextract
    pyserial
    bottle
    # git repo at specific commit - bottle-cork==0.12.0a2
    git+git://github.com/FedericoCeratto/bottle-cork.git@557bc6cc249ea8dcb7b76d85bde116527eb41223#egg=bottle-cork
    beautifulsoup4
    Beaker
    pillow
    

    And the build seems to work.

    In answer to my other questions:

    2) Yes, keep the import statements as is in the Python application.

    3) All installs of packages in requirements.txt seem to go ahead without requiring explicit installation of:

    python2.7-dev
    libxml2-dev
    libxslt1-dev
    apache2-dev
    zlib1g-dev
    libjpeg8-dev
    

    4) Yes, requirements.txt lives in the top directory of the repo.