push multi commands to own script

This commit is contained in:
will Farrell 2017-02-15 11:16:11 -07:00
parent 0bbd009e23
commit 0fc4c3fd7a
2 changed files with 12 additions and 6 deletions

View File

@ -2,7 +2,7 @@ FROM library/docker:1.13
ENV HOME_DIR=/opt/crontab
RUN apk add --no-cache --virtual .run-deps bash jq \
&& mkdir -p ${HOME_DIR}/projects
&& mkdir -p ${HOME_DIR}/jobs ${HOME_DIR}/projects
COPY docker-entrypoint /
ENTRYPOINT ["/docker-entrypoint"]

View File

@ -27,8 +27,6 @@ make_container_cmd() {
CONTAINER=$(echo ${1} | jq -r .container)
TMP_COMMAND=$(echo ${1} | jq -r .command)
COMMAND_ARR=()
if [ "${PROJECT}" != "null" ]; then
# create bash script to detect all running containers
@ -133,15 +131,23 @@ function build_crontab() {
continue
fi
COMMAND=$(make_cmd "$(jq -c .[$i] ${CONFIG})")
SCRIPT_NAME=$(cat /proc/sys/kernel/random/uuid)
COMMAND="/bin/bash ${HOME_DIR}/jobs/${SCRIPT_NAME}.sh"
cat << EOF > ${HOME_DIR}/jobs/${SCRIPT_NAME}.sh
#!/usr/bin/env bash
set -e
$(make_cmd "$(jq -c .[$i] ${CONFIG})")
EOF
if [ "$(jq -r .[$i].trigger ${CONFIG})" != "null" ]; then
while read j ; do
if [ "$(jq .[$i].trigger[$j].command ${CONFIG})" == "null" ]; then
echo "Command Missing: $(jq -r .[$i].trigger[$j].command ${CONFIG})"
continue
fi
TRIGGER_COMMANDS=$(make_cmd "$(jq -c .[$i].trigger[$j] ${CONFIG})")
COMMAND="${COMMAND} && ${TRIGGER_COMMANDS}"
#TRIGGER_COMMAND=$(make_cmd "$(jq -c .[$i].trigger[$j] ${CONFIG})")
$(make_cmd "$(jq -c .[$i].trigger[$j] ${CONFIG})") >> ${HOME_DIR}/jobs/${SCRIPT_NAME}.sh
#COMMAND="${COMMAND} && ${TRIGGER_COMMAND}"
done < <(jq -r '.['$i'].trigger|keys[]' ${CONFIG})
fi