Skip to content

Instantly share code, notes, and snippets.

@BenWhitehead
Last active August 29, 2015 14:11
Show Gist options
  • Save BenWhitehead/a2a59c55ab47968b50df to your computer and use it in GitHub Desktop.
Save BenWhitehead/a2a59c55ab47968b50df to your computer and use it in GitHub Desktop.
Bash script to "run" a marthon.json manifest that contains a docker image.

A script that reads a marathon json manifest and turns it into the local representation to run the docker image.

Install

Install script to a location in your path (~/bin), Make it executable chmod +x run-marathon-json.

Usage:

run-marathon-json marathon.json

Dependencies

!. jq command line json tool

#!/bin/bash
IFS=$'\n'
function main {(
local rawJson=$(cat $1)
local cmdToRun=(
docker run
--net=host
)
local image=$(echo ${rawJson} | jq -r '.container.docker.image')
local cmd=$(echo ${rawJson} | jq -r '.cmd // ""')
local args=$(echo ${rawJson} | jq -r '.args // ""')
local envs=$(echo ${rawJson} | jq -r '.env | to_entries | [map([.key, .value] | .[0] + "=" + .[1])] | .[0] | .[]')
for e in ${envs}; do
cmdToRun+=(-e ${e})
done
cmdToRun+=(-i -t ${image})
cmdToRun+=(${cmd})
cmdToRun+=(${args})
echo "Running > ${cmdToRun[@]}"
# for item in "${cmdToRun[@]}"; do
# echo "item = $item"
# done
${cmdToRun[@]}
)}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment