Created
December 25, 2019 21:28
-
-
Save j4zzcat/d974921d488f42e16760f6e5115dc4e6 to your computer and use it in GitHub Desktop.
Dockerise
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env bash | |
PROGRAM_HOME=$(realpath ${0} 2>/dev/null || cd "$(dirname "${0}")" ; pwd -P)/.. | |
RUNTIME_TAG=pixie-runtime:1.0 | |
function run_script { | |
CUT_LINE=$(cat ${0} | grep -n '#! dockerise ' | tail -1 | awk -F ':' '{print $1}') | |
tail +${CUT_LINE} ${0} | tail -n +2 | \ | |
docker run --rm -i \ | |
-v /var/run/docker.sock:/var/run/docker.sock \ | |
-v ${TMP_DIR}:/tmp \ | |
${RUNTIME_TAG} \ | |
ruby - ${@} | |
} | |
function build_runtime { | |
cat <<EOT | docker build - -t ${RUNTIME_TAG} | |
FROM ruby:2.6 | |
RUN gem install docopt | |
EOT | |
} | |
if [ $(docker images | tail -n +2 | awk '{print $1":"$2}' | grep ${RUNTIME_TAG}) ]; then | |
run_script ${@} | |
echo ${?} | |
else | |
build_runtime | |
fi | |
exit 0 | |
#! dockerise pixie-runtime:1.0 | |
#! /usr/bin/env ruby | |
puts "hello" | |
p ARGV | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment