fix: address jq parsing errors when some properties are not set.

This commit is contained in:
Robert Wlodarczyk 2022-07-16 10:22:43 -07:00
parent a523ad7d74
commit 9316c9f5c2

View File

@ -67,19 +67,19 @@ slugify() {
make_image_cmd() {
DOCKERARGS=$(echo "${1}" | jq -r .dockerargs)
VOLUMES=$(echo "${1}" | jq -r '.volumes | map(" -v " + .) | join("")')
PORTS=$(echo "${1}" | jq -r '.ports | map(" -p " + .) | join("")')
EXPOSE=$(echo "${1}" | jq -r '.expose | map(" --expose " + .) | join("")')
VOLUMES=$(echo "${1}" | jq -r 'select(.volumes != null) | .volumes | map(" -v " + .) | join("")')
PORTS=$(echo "${1}" | jq -r 'select(.ports != null) | .ports | map(" -p " + .) | join("")')
EXPOSE=$(echo "${1}" | jq -r 'select(.expose != null) | .expose | map(" --expose " + .) | join("")')
NAME=$(echo "${1}" | jq -r 'select(.name != null) | .name')
NETWORK=$(echo "${1}" | jq -r 'select(.network != null) | .network')
ENVIRONMENT=$(echo "${1}" | jq -r '.environment | map(" -e " + .) | join("")')
ENVIRONMENT=$(echo "${1}" | jq -r 'select(.environment != null) | .environment | map(" -e " + .) | join("")')
if [ "${DOCKERARGS}" == "null" ]; then DOCKERARGS=; fi
if [ -n "${NAME}" ]; then DOCKERARGS="${DOCKERARGS} --rm --name ${NAME} "; fi
if [ -n "${NETWORK}" ]; then DOCKERARGS="${DOCKERARGS} --network ${NETWORK} "; fi
if [ -n "${VOLUMES}" ]; then DOCKERARGS="${DOCKERARGS}${VOLUMES}"; fi
if [ -n "${ENVIRONMENT}" ]; then DOCKERARGS="${DOCKERARGS}${ENVIRONMENT}"; fi
if [ -n "${PORTS}" ]; then DOCKERARGS="${DOCKERARGS}${PORTS}"; fi
if [ -n "${EXPOSE}" ]; then DOCKERARGS="${DOCKERARGS}${EXPOSE}"; fi
if [ -n "${NAME}" ]; then DOCKERARGS+=" --rm --name ${NAME} "; fi
if [ -n "${NETWORK}" ]; then DOCKERARGS+=" --network ${NETWORK} "; fi
if [ -n "${VOLUMES}" ]; then DOCKERARGS+="${VOLUMES}"; fi
if [ -n "${ENVIRONMENT}" ]; then DOCKERARGS+="${ENVIRONMENT}"; fi
if [ -n "${PORTS}" ]; then DOCKERARGS+="${PORTS}"; fi
if [ -n "${EXPOSE}" ]; then DOCKERARGS+="${EXPOSE}"; fi
IMAGE=$(echo "${1}" | jq -r .image | envsubst)
TMP_COMMAND=$(echo "${1}" | jq -r .command)
echo "docker run ${DOCKERARGS} ${IMAGE} ${TMP_COMMAND}"