Skip to content

Instantly share code, notes, and snippets.

@j4zzcat
Last active February 26, 2017 09:17
Show Gist options
  • Save j4zzcat/e016868a6a97aa67fcf59eb96f0ab67e to your computer and use it in GitHub Desktop.
Save j4zzcat/e016868a6a97aa67fcf59eb96f0ab67e to your computer and use it in GitHub Desktop.
#! /bin/bash
# Create a temp file
program=$(mktemp /tmp/XXXX)
# Get the line number of the last match of __PROGRAM_START__
# Just grep-ing the file to find the marker will match the grep itself
cut_pos=$(cat ${0} | grep -n '__PROGRAM_START__' | tail -1 | awk -F ':' '{print $1}')
# Get the docker image tag to run the program in
image_tag=$(tail +${cut_pos} ${0} | head -n 1 | awk '{print $3}')
# Write the program starting from a line after the __PROGRAM_START__ marker,
# and make it executable
tail +${cut_pos} ${0} | tail -n +2 > ${program}
chmod a+x ${program}
# Launch the program in a docker container and exit the bash script
exec docker run --rm -it -v ${program}:${program} ${image_tag} ${program}
# Start of program marker (__PROGRAM_START__), followed by the docker image
# to use for running the program
# __PROGRAM_START__ ruby:2.4
#! /usr/bin/env ruby
puts "hello"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment