django-ex/openshift/scripts/run-in-container.sh

44 lines
1.5 KiB
Bash
Raw Normal View History

2015-05-24 14:32:06 +02:00
#!/bin/bash
# Use this script to run one-off commands inside a container of a pod where your
# Python application code lives in.
2015-05-24 14:32:06 +02:00
# You can accomplish the same results by using regular commands from OpenShift.
2015-06-08 11:37:27 +02:00
# 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:
# [1] https://github.com/GoogleCloudPlatform/kubernetes/issues/8876
# [2] https://github.com/GoogleCloudPlatform/kubernetes/issues/7770
# [3] 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
#
2015-06-01 18:37:01 +02:00
# 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
2015-06-08 11:37:27 +02:00
POD_INSTANCE_NAME=`oc get pods \
2015-06-01 18:37:01 +02:00
-l "name=${POD_NAME:-django}" \
-t "{{ with index .items ${POD_INDEX:-0} }}{{ .metadata.name }}{{ end }}"`
# Run command in a container of the specified pod:
2015-06-08 11:37:27 +02:00
oc exec -p "$POD_INSTANCE_NAME" -it -- bash -c \
"cd \$HOME && source scl_source enable python33 && ${@:-echo}"