You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
1.3 KiB
74 lines
1.3 KiB
2 years ago
|
#!/bin/bash
|
||
|
set -euo pipefail
|
||
|
|
||
|
gen-docker-file ()
|
||
|
{
|
||
|
if [ -f $src/Dockerfile.top ] ; then
|
||
|
cat $src/Dockerfile.top
|
||
|
fi
|
||
|
|
||
|
echo "COPY common /build/common"
|
||
|
|
||
|
for stage in $(cd $src && echo [0-9]*.[a-z]*) ; do
|
||
|
case $stage in
|
||
|
*.docker)
|
||
|
cat $src/$stage
|
||
|
;;
|
||
|
*.d|*.sh)
|
||
|
echo "COPY $src/$stage /build/$stage"
|
||
|
echo "RUN /build/common/run $stage"
|
||
|
;;
|
||
|
*)
|
||
|
echo >&2 "ERROR: Unrecognized build stage name $stage"
|
||
|
exit 1
|
||
|
;;
|
||
|
esac
|
||
|
done
|
||
|
|
||
|
if [ -f $src/Dockerfile.bottom ] ; then
|
||
|
cat $src/Dockerfile.bottom
|
||
|
fi
|
||
|
|
||
|
echo "RUN rm -rf /build /data"
|
||
|
}
|
||
|
|
||
|
if [ $# = 0 ] ; then
|
||
|
echo >&2 "Usage: $0 <src-directory> [<podman build options>]"
|
||
|
exit 1
|
||
|
fi
|
||
|
|
||
|
src=$1
|
||
|
shift
|
||
|
|
||
|
if [ ! -v http_proxy ] ; then
|
||
|
PROXY=
|
||
|
eval "$(apt-config shell PROXY Acquire::http::proxy)"
|
||
|
if [ -n "$PROXY" ] ; then
|
||
|
export http_proxy=$PROXY
|
||
|
fi
|
||
|
fi
|
||
|
|
||
|
if [ -v http_proxy -a ! -v https_proxy ] ; then
|
||
|
export https_proxy=$http_proxy
|
||
|
fi
|
||
|
|
||
|
CACHE_DIR=${XDG_CACHE_HOME:-$HOME/.cache}/container-build
|
||
|
if [ -d $CACHE_DIR ] ; then
|
||
|
echo "Using cache $CACHE_DIR"
|
||
|
else
|
||
|
echo "Creating cache $CACHE_DIR"
|
||
|
mkdir -p $CACHE_DIR
|
||
|
fi
|
||
|
mkdir -p $CACHE_DIR/download
|
||
|
|
||
|
gen-docker-file | podman build \
|
||
|
--file - \
|
||
|
--layers \
|
||
|
--http-proxy \
|
||
|
--volume=$CACHE_DIR:/root/.cache \
|
||
|
"$@" \
|
||
|
.
|
||
|
|
||
|
echo -n "Cache usage: "
|
||
|
du -sh $CACHE_DIR | cut -d ' ' -f1
|