Skip to content

Instantly share code, notes, and snippets.

@ahoy-jon
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahoy-jon/e8c534883a5a8c87c046 to your computer and use it in GitHub Desktop.
Save ahoy-jon/e8c534883a5a8c87c046 to your computer and use it in GitHub Desktop.
m5 : an attempt to fix some Dockerfile missing features without m4

Usage

bash m5.bash Dockerfile.m5 |docker build -

FROM dockerfile/ubuntu
INCLUDE "javaruby.m5"
#ADD MYAPP ...
FROM dockerfile/ubuntu
#This file use existing Dockerfiles to build a working Java 8 + Ruby 2.2 env !!!!
INCLUDE "https://raw.githubusercontent.com/docker-library/buildpack-deps/master/wheezy/Dockerfile"
INCLUDE "https://github.com/docker-library/ruby/raw/master/2.2/wheezy/Dockerfile"
INCLUDE "https://raw.githubusercontent.com/dockerfile/java/master/oracle-java8/Dockerfile"
#!/bin/bash
[[ $2 = "--sub" ]] && SUB=true || SUB=false
if [[ $1 == http* ]] ; then
if hash wget 2>/dev/null ; then
wget –quiet -O - -o /dev/null $1
else
curl –silent -kL $1 2>/dev/null
fi
else
cat $1
fi | sed '$a\' | while read line
do
if [[ $SUB = true && $line =~ ^FROM\ .+ ]]
then
#if the line is from a sub file and starts with a from
#quote the line
echo "#$line"
else
# if not (a sub file and line is a FROM)
if [[ $line =~ ^INCLUDE\ \"(.+)\" ]]
then
#if the line is a include instruction
#quote the line
echo ""
echo "#$line #IN $1"
#and recursively call the script with the sub flag
bash $0 ${BASH_REMATCH[1]} --sub
else
#else just print the line
echo "$line"
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment