-
Notifications
You must be signed in to change notification settings - Fork 36
Use environment variable to set application context root
When installing the reverse proxy to point to our servers, it was requested that the url should include a reference to gwells.
So the prod url would look like https://<prodroot>/gwells
Django does not automatically agree with such a treatment and must be adapted. It is fairly easy for do that in the code and configuration but it was deemed wise to push the gwells string into an environment variable in OpenShift which Django then can read and apply.
- Create/Set Environment Variable in OpenShift
- Update Django
- Set local activate.bat (virtualenv setting)
- Test
- Select the environmnet you want to set the variable for. (e.g. Groundwater Wells (Dev)).
- Select "Overview" from the site menu
- Open drop down with the systems's URL (e.g. https://gwells-dev.pathfinder.gov.bc.ca/gwells)
- Select url in "Deployment Config gwells"
- In the new window, choose "Environment", you have now arrived on the Environment variables page
- Create new variable "APP_CONTEXT_ROOT"
- Set the value to "gwells"
- In settings.py add:
# Controls app context
APP_CONTEXT_ROOT = os.getenv('APP_CONTEXT_ROOT','')
`* and change the setting for the statisc files:`
if APP_CONTEXT_ROOT:
STATIC_URL = '/'+ APP_CONTEXT_ROOT +'/static/'
else:
STATIC_URL = '/static/'
- in url.py change the urls to include the APP_CONTEXT_ROOT setting
# Creating 2 versions of the app_root. One without and one with trailing slash
# This will allow for any or no additional app_root context to be provided
app_root = settings.APP_CONTEXT_ROOT
if app_root:
app_root_slash = app_root + '/'
else:
app_root_slash = app_root
urlpatterns = [
url(r'^'+ app_root +'$', views.HomeView.as_view(), name='home'),
url(r'^'+ app_root_slash +'$', views.well_search, name='home'),
....
- Add:
SET APP_CONTEXT_ROOT=gwells
- Start your local Django, navigate
- Set and reset the APP_CONTEXT_ROOT to test the difference
- Working on GWELLS (full workflow from writing code to deploying to prod)
- Water terminologies
- Testing
- Swagger Documentation
- Restore a database backup manually
- (Archived) Manual Syncing of DEV to TEST to PROD
- (Archived) Setup GWells data migration for local dev test
- Update PostGres Oracle Foreign Data Wrapper image
- Increase PostgreSQL Database storage
- (Archived) Regular Corruption of the PostgreSQL DB
- (Archived) Recovering from a corrupt PostgreSQL Database