1
0
mirror of https://github.com/rancher/os.git synced 2025-09-01 14:48:55 +00:00

dind-less, make-based build system

This commit is contained in:
Ivan Mikushin
2015-07-23 18:53:01 +05:00
parent 7f1016059f
commit 6022f78edd
18 changed files with 200 additions and 392 deletions

View File

@@ -1,131 +1,3 @@
#!/bin/bash
: ${ARTIFACTS:=$(pwd)/assets}
: ${BUILD:=$(pwd)/build}
: ${DIST:=$(pwd)/dist}
# PREREQ: brew install coreutils
path()
{
local UNAME=$(uname)
if [ "$UNAME" == "Darwin" ]; then greadlink -f "$1"
elif [ "$UNAME" == "Linux" ]; then readlink -f "$1";
fi
}
write_base()
{
DOCKER_BASE=${DOCKER_BASE:?"DOCKER_BASE not defined"}
if [ "${BASE_WRITTEN}" = "true" ]; then
return
fi
mkdir -p $(dirname ${DOCKER_FILE})
cat > ${DOCKER_FILE} << EOF
FROM ${DOCKER_BASE}
ENV TERM xterm
ENV IN_DOCKER true
WORKDIR /source
EOF
BASE_WRITTEN=true
}
run()
{
local content
while [ $# -gt 1 ]; do
case $1 in
--assets)
shift 1
if [ -e "$1" ]; then
content="$content\nCOPY $1 /source/$1"
else
content="$content\nCOPY $1 /source/"
fi
;;
*)
break
;;
esac
shift 1
done
write_base
if [ -n "$content" ]; then
echo -e "$content" >> ${DOCKER_FILE}
fi
if [ -n "$1" ]; then
echo -e "\nCOPY $1 /source/$1" >> ${DOCKER_FILE}
echo -e "RUN /source/"$@"" >> ${DOCKER_FILE}
fi
if [ "$RUN_EXEC" = "true" ]; then
"$@"
fi
}
finish()
{
if [ "$RUN_EXEC" = "true" ]; then
return
fi
local cmd="docker build -t ${DOCKER_IMAGE} -f ${DOCKER_FILE} ."
echo Running $cmd
echo Pwd $(pwd)
cat ${DOCKER_FILE}
$cmd
}
reset_docker_build()
{
BASE_WRITTEN=false
}
check()
{
local hash=$1
local file=$2
if [ ! -e "$file" ]; then
return 1
fi
if [ "$hash" = dev ]; then
return 0
fi
CURRENT=$(sha1sum $file | awk '{print $1}')
[ "$hash" = "$CURRENT" ]
}
download()
{
mkdir -p ${ARTIFACTS}
local url=$2
local file=${ARTIFACTS}/$(basename $2)
local hash=$1
if [ "$3" != "" ]; then
file=${ARTIFACTS}/$3
fi
if ! check $hash $file; then
echo Downloading $url to $file
curl -sL $url > $file
fi
if ! check $hash $file; then
echo "ERROR: $file does not match checksum $hash, got $CURRENT" 1>&2
return 1
fi
}
ARTIFACTS=$(pwd)/assets
BUILD=$(pwd)/build
DIST=$(pwd)/dist