Skip to content

Commit f62a733

Browse files
authored
Add developer mode option for cdpy (#71)
* Correct some Error and logging messages in quickstart.sh * Add 'CLDR_PYTHON_PATH' option to quickstart.sh, which may be set to the mounted path of cdpy, e.g. /runner/project/cdpy/src * Correct usage of inventory_static.ini in readme Signed-off-by: Daniel Chaffelson <[email protected]>
1 parent 65adf4e commit f62a733

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

quickstart.sh

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ PROJECT_DIR=${1:-${PARENT_DIRECTORY}}
3333
echo "Checking if Docker is running..."
3434
{ docker info >/dev/null 2>&1; echo "Docker OK"; } || { echo "Docker is required and does not seem to be running - please start Docker and retry" ; exit 1; }
3535

36-
docker pull ${IMAGE_NAME}:"${IMAGE_TAG}"
36+
echo "Checking for updated execution container image '${IMAGE_FULL_NAME}'"
37+
docker pull "${IMAGE_FULL_NAME}"
3738

3839
echo "Ensuring default credential paths are available in calling using profile for mounting to execution environment"
3940
for thisdir in ".aws" ".ssh" ".cdp" ".azure" ".kube" ".config" ".config/cloudera-deploy/log" ".config/cloudera-deploy/profiles"
@@ -51,17 +52,26 @@ if [ ! -f "${HOME}"/.config/cloudera-deploy/profiles/default ]; then
5152
fi
5253

5354
# If CLDR_COLLECTION_PATH is set, the default version in the container will be removed and this path added to the Ansible Collection path
54-
# The path supplied must be relative to PROJECT_DIR
55+
# The path supplied must be relative to PROJECT_DIR, e.g. ansible_dev/collections
5556
if [ -n "${CLDR_COLLECTION_PATH}" ]; then
5657
echo "Path to custom Cloudera Collection supplied as ${CLDR_COLLECTION_PATH}, adding to Ansible Collection path"
5758
ANSIBLE_COLLECTIONS_PATH="/opt/cldr-runner/collections:/runner/project/${CLDR_COLLECTION_PATH}"
59+
QUICKSTART_PROMPT='Quickstart? Run this command -- ansible-playbook project/cloudera-deploy/main.yml -e "definition_path=examples/sandbox" -t run,default_cluster'
5860
else
5961
echo "Custom Cloudera Collection path not found"
6062
ANSIBLE_COLLECTIONS_PATH="/opt/cldr-runner/collections"
63+
QUICKSTART_PROMPT='Quickstart? Run this command -- ansible-playbook /opt/cloudera-deploy/main.yml -e "definition_path=examples/sandbox" -t run,default_cluster'
6164
fi
6265

63-
echo "Mounting ${PROJECT_DIR} to container as Project Directory /runner/project"
64-
echo "Creating Container ${CONTAINER_NAME} from image ${IMAGE_FULL_NAME}"
66+
# If CLDR_PYTHON_PATH is set, that will be set as the system PYTHONPATH variable in the container
67+
# This is a good way to point at any custom python source code in your /runner/project mount, including CDPY
68+
# The path supplied must be a full path to the source root for each source included, e.g /runner/project/cdpy/src
69+
if [ -n "${CLDR_PYTHON_PATH}" ]; then
70+
echo "Path to custom Python sourcecode supplied as ${CLDR_PYTHON_PATH}, setting as System PYTHONPATH"
71+
PYTHONPATH="${CLDR_PYTHON_PATH}"
72+
else
73+
echo "'CLDR_PYTHON_PATH' is not set, skipping setup of PYTHONPATH in execution container"
74+
fi
6575

6676
echo "Checking if ssh-agent is running..."
6777
if pgrep -x "ssh-agent" >/dev/null
@@ -75,12 +85,12 @@ fi
7585
echo "Checking OS"
7686
if [ ! -f "/run/host-services/ssh-auth.sock" ];
7787
then
78-
if [ ! -z "$SSH_AUTH_SOCK" ];
88+
if [ -n "${SSH_AUTH_SOCK}" ];
7989
then
8090
SSH_AUTH_SOCK=${SSH_AUTH_SOCK}
8191
else
82-
echo "SSH_AUTH_SOCK is empty or not set, unable to proceed. Exiting"
83-
exit -1
92+
echo "ERROR: SSH_AUTH_SOCK is empty or not set, unable to proceed. Exiting"
93+
exit 1
8494
fi
8595
else
8696
SSH_AUTH_SOCK=${SSH_AUTH_SOCK}
@@ -95,11 +105,11 @@ if [ ! "$(docker ps -q -f name=${CONTAINER_NAME})" ]; then
95105
docker rm "${CONTAINER_NAME}" >/dev/null 2>&1 || echo "Execution container '${CONTAINER_NAME}' already removed, continuing..."
96106
fi
97107
# create new container if not running
98-
echo "Creating new execution container named '${CONTAINER_NAME}'"
108+
echo "Creating new execution container named '${CONTAINER_NAME}' with '${PROJECT_DIR}' mounted to /runner/project from image '${IMAGE_FULL_NAME}'"
99109
docker run -td \
100110
--detach-keys="ctrl-@" \
101111
-v "${PROJECT_DIR}":/runner/project \
102-
--mount type=bind,src=${SSH_AUTH_SOCK},target=/run/host-services/ssh-auth.sock \
112+
--mount type=bind,src="${SSH_AUTH_SOCK}",target=/run/host-services/ssh-auth.sock \
103113
-e SSH_AUTH_SOCK="/run/host-services/ssh-auth.sock" \
104114
-e ANSIBLE_LOG_PATH="/home/runner/.config/cloudera-deploy/log/${CLDR_BUILD_VER:-latest}-$(date +%F_%H%M%S)" \
105115
-e ANSIBLE_INVENTORY="inventory" \
@@ -109,6 +119,7 @@ if [ ! "$(docker ps -q -f name=${CONTAINER_NAME})" ]; then
109119
-e ANSIBLE_HOST_KEY_CHECKING=false \
110120
-e ANSIBLE_SSH_RETRIES=10 \
111121
-e ANSIBLE_COLLECTIONS_PATH="${ANSIBLE_COLLECTIONS_PATH}" \
122+
-e PYTHONPATH="${PYTHONPATH}" \
112123
-e ANSIBLE_ROLES_PATH="/opt/cldr-runner/roles" \
113124
-e AWS_DEFAULT_OUTPUT="json" \
114125
--mount "type=bind,source=${HOME}/.aws,target=/home/runner/.aws" \
@@ -128,6 +139,9 @@ if [ ! "$(docker ps -q -f name=${CONTAINER_NAME})" ]; then
128139
if [ -n "${CLDR_COLLECTION_PATH}" ]; then
129140
docker exec -td "${CONTAINER_NAME}" /usr/bin/env rm -rf /opt/cldr-runner/collections/ansible_collections/cloudera
130141
fi
142+
if [ -n "${CLDR_PYTHON_PATH}" ]; then
143+
docker exec -td "${CONTAINER_NAME}" pip uninstall -y cdpy
144+
fi
131145
fi
132146

133147
cat <<SSH_HOST_KEY
@@ -141,7 +155,7 @@ cat <<SSH_HOST_KEY
141155
142156
SSH_HOST_KEY
143157

144-
echo 'Quickstart? Run this command -- ansible-playbook /opt/cloudera-deploy/main.yml -e "definition_path=examples/sandbox" -t run,default_cluster'
158+
echo "${QUICKSTART_PROMPT}"
145159
docker exec \
146160
--detach-keys="ctrl-@" \
147161
-it "${CONTAINER_NAME}" \

readme.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ Within the directory, you *must* supply the following files:
460460

461461
Optionally, if deploying a CDP Private Cloud cluster or need to set up adhoc IaaS infrastructure, you can supply the following :
462462

463-
* `inventory_static.ini`
463+
* `inventory_template.ini`
464464
* `inventory_template.ini`
465465

466466
The definition directory can host any other file or asset, such as data files, additional configuration details, additional playbooks. However, Cloudera Deploy will not operate unless the `definition.yml` and `application.yml` files are present.
@@ -501,7 +501,7 @@ NOTE: This file is a standard Ansible playbook, and when it is executed (via `im
501501

502502
=== `inventory_static.ini`
503503

504-
You may also include an `inventory_static.ini` file that describes your static Ansible inventory. This file will be automatically loaded and added to the Ansible inventory. Note that you can also use the standard Ansible `-i` switch to include other static inventory.
504+
You may also include an `inventory_template.ini` file that describes your static Ansible inventory. This file will be automatically loaded and added to the Ansible inventory. Note that you can also use the standard Ansible `-i` switch to include other static inventory.
505505

506506
=== `inventory_template.ini`
507507

0 commit comments

Comments
 (0)