Skip to content

Instantly share code, notes, and snippets.

@AntonTyutin
Created April 24, 2019 06:08
Show Gist options
  • Save AntonTyutin/13299d25619cc2bc1b6574392851cf7b to your computer and use it in GitHub Desktop.
Save AntonTyutin/13299d25619cc2bc1b6574392851cf7b to your computer and use it in GitHub Desktop.
Converts JSON to YAML with query capabilities
#!/bin/sh
if ! docker images -q yq | grep '' 1>/dev/null
then
docker build --pull -t yq - <<EOF
FROM alpine
RUN apk add --no-cache py2-pip jq && pip install -q yq
ENTRYPOINT ["yq"]
EOF
fi
PROXY_ENV=""
for VAR in `env | grep -vE '^(USER|HOME|UID)='`
do
PROXY_ENV="$PROXY_ENV -e $VAR"
done
docker run --rm -i $([ -t 0 ] && echo '-t') \
-u $(id -u) \
-w /src \
-v $PWD:/src \
$PROXY_ENV \
$RUN_ARGS \
yq -y "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment