Add script to run command in container

This commit is contained in:
Rodolfo Carvalho 2015-05-24 14:32:06 +02:00
parent bcefb8c464
commit 1e9b2d599c
1 changed files with 23 additions and 0 deletions

23
scripts/run-in-container.sh Executable file
View File

@ -0,0 +1,23 @@
#!/bin/bash
# Use this script to run one-off commands inside a container of a pod
# (where your application code lives in)
#
# Examples:
# ./run-in-container.sh web date
# ./run-in-container.sh database env
# ./run-in-container.sh web ./manage.py migrate
# ./run-in-container.sh web ./manage.py createsuperuser
# ./run-in-container.sh web tail -f access.log
# POD_INDEX=1 ./run-in-container.sh web tail -f access.log
POD_NAME="$1"
if [[ -z "$POD_NAME" ]]; then
echo "missing pod name"
exit 1
fi
shift
quoted_args="$(printf " %q" "${@:-echo}")"
osc exec -p $(osc get pods -l "name=$POD_NAME" -t "{{ with index .items ${POD_INDEX:-0} }}{{ .metadata.name }}{{ end }}") -it -- bash -c "cd \$HOME && scl enable python33 \"$quoted_args\""