Göm menyn

TDDD80 Projekt: Mobila och sociala applikationer

Laborationer


Step 2. Run PostgreSQL on Openshift

Once you have rhc, you need to run rhc setup to hook into OpenShift at IDA. Use rhc setup --help to figure out how to end up at openshift.ida.liu.se.

rhc --help . --help you can attach to any rhc command to get the documentation. Also, use rhc --tail to watch what happens with apps you are running.

On OpenShift applications are run on gears. Read about gears for applications that OpenShift can then start and stop when you push new code to OpenShift. This can be cone manually or using start projects on GitHub such as for flask. Read first, do later ...

Once you've created that application it will be cloned to the location in your local computer you are using so make sure you are in the terminal at the right location on your computer. Of course, you can also clone from OpenShift using the Git URL your repo has. You find that using rhc apps.

Once you have your local git repo from your OpenShift origin, you also need to add a second remote URL for your gitlab repo. Create a new project on gitlab.ida.liu.se and add a second remote to be able to push both to OpenShift and to gitlab when developing. The idea is that you should push working things to OpenShift and things under development to gitlab.ida.liu.se.

OpenShift, like all containers and webservers, have ideas about how things should be done that is different and more secure and efficient than localhost. Folders to store persistent data, how to communicate with databases, how to install systems you depend on and so forth. In 2015 a lot of students had problems connecting to databses becasue they didn't understand that Opeshift has internal ports and external prots. This means connecting to a database on the Openshift server worsk fine, but connecting to the same machine in the same way from localhost is not possible. This means you should run different databases locally and on OpenShift, which is good practice anyway. You can test for the availability of environmental variables that are set on OpenShift like in this pythoncode for flask like this.

 
	
if 'OPENSHIFT_POSTGRESQL_DB_URL' in os.environ:
    app.config['SQLALCHEMY_DATABASE_URI'] =os.environ['OPENSHIFT_POSTGRESQL_DB_URL']
else:
    app.config['SQLALCHEMY_DATABASE_URI'] ="sqlite:///tmp/testdb.db"

Read more on hooking the database here.

Sidansvarig: Rita Kovordanyi
Senast uppdaterad: 2018-02-16