From 370627c3bf634262455f3af86538f579898f5ee1 Mon Sep 17 00:00:00 2001 From: Mike Olund Date: Fri, 24 Mar 2017 09:48:35 -0700 Subject: [PATCH] OpenShift documentation updates --- README.md | 68 ----------------------- openshift/README.md | 80 +++++++++++++++++++++++++-- openshift/scripts/destroy-env.sh | 29 ---------- openshift/scripts/run-in-container.sh | 41 ++++++++++++++ 4 files changed, 115 insertions(+), 103 deletions(-) delete mode 100755 openshift/scripts/destroy-env.sh create mode 100644 openshift/scripts/run-in-container.sh diff --git a/README.md b/README.md index b40eb72f..df5be54a 100644 --- a/README.md +++ b/README.md @@ -54,74 +54,6 @@ To run this project in your development machine, follow these steps: See: `openshift/README.md` -## Logs - -By default your Django application is served with gunicorn and configured to output its access log to stderr. -You can look at the combined stdout and stderr of a given pod with this command: - - oc get pods # list all pods in your project - oc logs - -This can be useful to observe the correct functioning of your application. - - -## One-off command execution - -At times you might want to manually execute some command in the context of a running application in OpenShift. -You can drop into a Python shell for debugging, create a new user for the Django Admin interface, or perform any other task. - -You can do all that by using regular CLI commands from OpenShift. -To make it a little more convenient, you can use the script `openshift/scripts/run-in-container.sh` that wraps some calls to `oc`. -In the future, the `oc` CLI tool might incorporate changes that make this script obsolete. - -Here is how you would run a command in a pod specified by label: - -1. Log in to the Openshift instance - - ``` - oc login --token= - ``` - -1. Select the project where you want to run the command - - ``` - oc project - ``` - -1. Inspect the output of the command below to find the name of a pod that matches a given label: - - oc get pods -l - -1. Open a shell in the pod of your choice. Because of how the images produced - with CentOS and RHEL work currently, we need to wrap commands with `bash` to - enable any Software Collections that may be used (done automatically inside - every bash shell). - - oc exec -p -it -- bash - -1. Finally, execute any command that you need and exit the shell. - - -The wrapper script combines the steps above into one. You can use it like this: - - ./run-in-container.sh ./manage.py migrate # manually migrate the database - # (done for you as part of the deployment process) - ./run-in-container.sh ./manage.py createsuperuser # create a user to access Django Admin - ./run-in-container.sh ./manage.py shell # open a Python shell in the context of your app - -If your Django pods are labeled with a name other than "django", you can use: - - POD_NAME=name ./run-in-container.sh ./manage.py check - -If there is more than one replica, you can also specify a POD by index: - - POD_INDEX=1 ./run-in-container.sh ./manage.py shell - -Or both together: - - POD_NAME=django-example POD_INDEX=2 ./run-in-container.sh ./manage.py shell - - ## Data persistence For local development a SQLite database will be used. For OpenShift deployments data will be stored in a PostgreSQL database, with data files residing on a persistent volume. diff --git a/openshift/README.md b/openshift/README.md index 46f77d96..2da4a267 100644 --- a/openshift/README.md +++ b/openshift/README.md @@ -4,9 +4,9 @@ There are three deployment environments set up for different purposes within Ope |Environment| URL |Justice URL| |-----------|-----|-----------| -|DEV|[https://edivorce-dev.pathfinder.gov.bc.ca]|[https://justice.gov.bc.ca/divorce-dev]| -|TEST|[https://edivorce-test.pathfinder.gov.bc.ca]|[https://justice.gov.bc.ca/divorce-test]| -|PROD|[https://edivorce-prod.pathfinder.gov.bc.ca]|[https://justice.gov.bc.ca/divorce]| +|DEV|https://edivorce-dev.pathfinder.gov.bc.ca|https://justice.gov.bc.ca/divorce-dev| +|TEST|https://edivorce-test.pathfinder.gov.bc.ca|https://justice.gov.bc.ca/divorce-test| +|PROD|https://edivorce-prod.pathfinder.gov.bc.ca|https://justice.gov.bc.ca/divorce| These instructions assume you have 4 EMPTY projects created in OpenShift: @@ -165,7 +165,7 @@ oc policy add-role-to-user system:image-puller system:serviceaccount:jag-csb-edi oc policy add-role-to-user edit system:serviceaccount:jag-csb-edivorce-tools:default -n jag-csb-edivorce-dev ``` -Deploy the Django app and the Postgresql DB +Deploy the Django app and the Postgresql DB (Read the section about "Important Configuration Options" above!) ``` oc process edivorce -v ENVIRONMENT_TYPE=dev,PROXY_NETWORK=123.45.67.89/0,BASICAUTH_ENABLED=True | oc create -f - ``` @@ -202,7 +202,7 @@ oc policy add-role-to-user system:image-puller system:serviceaccount:jag-csb-edi oc policy add-role-to-user edit system:serviceaccount:jag-csb-edivorce-tools:default -n jag-csb-edivorce-test ``` -Deploy the Django app and the Postgresql DB +Deploy the Django app and the Postgresql DB (Read the section about "Important Configuration Options" above!) ``` oc process edivorce -v ENVIRONMENT_TYPE=test,PROXY_NETWORK=123.45.67.89/0,BASICAUTH_ENABLED=True | oc create -f - ``` @@ -238,7 +238,7 @@ oc policy add-role-to-user system:image-puller system:serviceaccount:jag-csb-edi oc policy add-role-to-user edit system:serviceaccount:jag-csb-edivorce-tools:default -n jag-csb-edivorce-prod ``` -Deploy the Django app and the Postgresql DB +Deploy the Django app and the Postgresql DB (Read the section about "Important Configuration Options" above!) ``` oc process edivorce -v ENVIRONMENT_TYPE=prod,PROXY_NETWORK=123.45.67.89/0 | oc create -f - ``` @@ -289,3 +289,71 @@ exit ## How to access Jenkins for eDivorce - Login to https://edivorce-jenkins.pathfinder.gov.bc.ca with the username/password that was provided to you. + +## Logs + +By default your Django application is served with gunicorn and configured to output its access log to stderr. +You can look at the combined stdout and stderr of a given pod with this command: + + oc get pods # list all pods in your project + oc logs + +This can be useful to observe the correct functioning of your application. + + +## One-off command execution + +At times you might want to manually execute some command in the context of a running application in OpenShift. +You can drop into a Python shell for debugging, create a new user for the Django Admin interface, or perform any other task. + +You can do all that by using regular CLI commands from OpenShift. +To make it a little more convenient, you can use the script `openshift/scripts/run-in-container.sh` that wraps some calls to `oc`. +In the future, the `oc` CLI tool might incorporate changes that make this script obsolete. + +Here is how you would run a command in a pod specified by label: + +1. Log in to the Openshift instance + + ``` + oc login --token= + ``` + +1. Select the project where you want to run the command + + ``` + oc project + ``` + +1. Inspect the output of the command below to find the name of a pod that matches a given label: + + oc get pods -l + +1. Open a shell in the pod of your choice. Because of how the images produced + with CentOS and RHEL work currently, we need to wrap commands with `bash` to + enable any Software Collections that may be used (done automatically inside + every bash shell). + + oc exec -p -it -- bash + +1. Finally, execute any command that you need and exit the shell. + + +The wrapper script combines the steps above into one. You can use it like this: + + ./run-in-container.sh ./manage.py migrate # manually migrate the database + # (done for you as part of the deployment process) + ./run-in-container.sh ./manage.py createsuperuser # create a user to access Django Admin + ./run-in-container.sh ./manage.py shell # open a Python shell in the context of your app + +If your Django pods are labeled with a name other than "django", you can use: + + POD_NAME=name ./run-in-container.sh ./manage.py check + +If there is more than one replica, you can also specify a POD by index: + + POD_INDEX=1 ./run-in-container.sh ./manage.py shell + +Or both together: + + POD_NAME=django-example POD_INDEX=2 ./run-in-container.sh ./manage.py shell + diff --git a/openshift/scripts/destroy-env.sh b/openshift/scripts/destroy-env.sh deleted file mode 100755 index 009beca2..00000000 --- a/openshift/scripts/destroy-env.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env bash - -# this is hard-coded to only destroy the dev environment -# you can chage it to 'test' or 'prod' if you are sure you want to destroy EVERYTHING, include the database -oc project jag-csb-edivorce-test - -# delete all imagestreams -oc delete is --all - -# delete services by name (we don't want to accidentally delete the gluster service!) -oc delete svc weasyprint -oc delete svc postgresql -oc delete svc edivorce-django - -# delete routes -oc delete route --all - -# delete persistent volume claims -oc delete pvc --all - -# delete replication controllers -oc delete rc --all - -# delete deployment configurations -oc delete dc --all - -# delete pods -oc delete po --all - No newline at end of file diff --git a/openshift/scripts/run-in-container.sh b/openshift/scripts/run-in-container.sh new file mode 100644 index 00000000..4dbbe3c1 --- /dev/null +++ b/openshift/scripts/run-in-container.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +# Use this script to run one-off commands inside a container of a pod where your +# Python application code lives in. + +# You can accomplish the same results by using regular commands from OpenShift. +# This script is just wrapping calls to `oc` to make it a little more +# convenient to use. In the future, the `oc` cli tool might incorporate changes +# that make this script obsolete. + +# Related GitHub issues: +# - https://github.com/GoogleCloudPlatform/kubernetes/issues/8876 +# - https://github.com/openshift/origin/issues/2001 + + +# Usage examples: +# +# ./run-in-container.sh ./manage.py migrate +# ./run-in-container.sh ./manage.py createsuperuser +# ./run-in-container.sh ./manage.py shell +# +# If your Python pods are labeled with a name other than "django", you can use: +# +# POD_NAME=name ./run-in-container.sh ./manage.py check +# +# If there is more than one replica, you can also specify a POD by index: +# +# POD_INDEX=1 ./run-in-container.sh ./manage.py shell +# +# Or both together: +# +# POD_NAME=frontend POD_INDEX=2 ./run-in-container.sh ./manage.py shell + + +# Get name of a currently deployed pod by label and index +POD_INSTANCE_NAME=`oc get pods \ + -l "name=${POD_NAME:-django-frontend}" \ + -t "{{ with index .items ${POD_INDEX:-0} }}{{ .metadata.name }}{{ end }}"` + +# Run command in a container of the specified pod: +oc exec -p "$POD_INSTANCE_NAME" -it -- bash -c "${@:-echo}" \ No newline at end of file