Run Django on Oracle Application Container

Issue

I have an existing django project which I am trying to deploy to Oracle’s cloud service, Application Container.

I followed Oracle’s guide to do this however there are some details missing from this guide. Specifically the guide references an app.py file which seems to come from this guide. But I can’t see how to use that in a django project.

I’ve tried replacing the calls to app.py to use django’s manage.py or wsgi.py files but Oracle servers still fail to launch. The server logs Oracle provide also don’t help, only telling me the python packages are being installed.

ACCS[web.1]: Content of APP_HOME [ /u01/app/ ] dir
ACCS[web.1]: total 96
ACCS[web.1]: -rw-r----- 1 apaas apaas 28423 May 17 10:51 readme.html
ACCS[web.1]: -rw-r----- 1 apaas apaas 40960 May 17 10:51 db.sqlite3
ACCS[web.1]: -rw-r----- 1 apaas apaas   355 Sep 10 13:26 manage.py
ACCS[web.1]: -rw-r----- 1 apaas apaas   254 Sep 10 13:28 DjangoProject.pyproj.user
ACCS[web.1]: -rw-r----- 1 apaas apaas  6990 Sep 10 13:28 DjangoProject.pyproj
ACCS[web.1]: -rw-r----- 1 apaas apaas   186 Sep 12 11:24 manifest.json
ACCS[web.1]: drwxr-x--- 1 apaas apaas    10 Sep 13 03:42 obj
ACCS[web.1]: drwxr-x--- 1 apaas apaas   160 Sep 13 03:42 app
ACCS[web.1]: drwxr-x--- 1 apaas apaas    94 Sep 13 03:42 DjangoProject
ACCS[web.1]: drwxr-xr-x 1 apaas apaas   286 Sep 13 03:42 .
ACCS[web.1]: drwxr-xr-x 1 apaas apaas    46 Sep 13 03:42 ..
ACCS[web.1]: -rw-r----- 1 apaas apaas   290 Sep 13  2018 start.sh
ACCS[web.1]: -rw-r----- 1 apaas apaas    51 Sep 13  2018 requirements.txt
ACCS[web.1]: Application should listen on 0.0.0.0:$PORT [enabling app to listen on all interfaces on $PORT env variable]
ACCS[web.1]: Starting application with launch command [ sh ./start.sh ]
APP[web.1]: Collecting Django==1.11.15 (from -r ./requirements.txt (line 1))
APP[web.1]:   Downloading https://files.pythonhosted.org/packages/f8/1c/31112c778b7a56ce18e3fff5e8915719fbe1cd3476c1eef557dddacfac8b/Django-1.11.15-py2.py3-none-any.whl (6.9MB)
APP[web.1]: Collecting pytz==2018.5 (from -r ./requirements.txt (line 2))
APP[web.1]:   Downloading https://files.pythonhosted.org/packages/30/4e/27c34b62430286c6d59177a0842ed90dc789ce5d1ed740887653b898779a/pytz-2018.5-py2.py3-none-any.whl (510kB)
APP[web.1]: Collecting setuptools==39.0.1 (from -r ./requirements.txt (line 3))
APP[web.1]:   Downloading https://files.pythonhosted.org/packages/20/d7/04a0b689d3035143e2ff288f4b9ee4bf6ed80585cc121c90bfd85a1a8c2e/setuptools-39.0.1-py2.py3-none-any.whl (569kB)
APP[web.1]: Installing collected packages: pytz, Django, setuptools
APP[web.1]: Successfully installed Django-1.11.15 pytz-2018.5 setuptools-39.0.1
APP[web.1]: You are using pip version 9.0.1, however version 18.0 is available.
APP[web.1]: You should consider upgrading via the 'pip install --upgrade pip' command.

I found use from this guide when making my start.sh file as well.

#!/bin/sh
pip --no-cache-dir install -r ./requirements.txt -t modules
export PYTHONPATH=$PYTHONPATH:modules
python manage.py runserver

I’ve contacted Oracle’s support but they were not able to find a solution either. Their recommendation was in include the PORT variable which the server uses in the wsgi.py file, which I tried.

import os
import sys

from django.core.management import call_command
from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "DjangoMedmin.settings")
application = get_wsgi_application()

PORT_NUMBER = int(os.environ.get('PORT', 8084))
call_command('runserver',  '0.0.0.0:'+str(PORT_NUMBER))

What am I missing? Is it possible to have django work with Oracle?

Solution

With some more help from Oracle support I managed to get Django working on a Application Container.

The issue was with the ALLOWED_HOSTS variable in settings.py. The tutorials I found all suggest using ALLOWED_HOSTS = ['*']. This does NOT work.

In order to get Django working I needed to include the specific URL Oracle assigns to the Application Container. So something like ALLOWED_HOSTS = ['ProjectName-AccountName.oracle-region-0.oraclecloud.com'].

Answered By – acheur

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published