#!/usr/bin/env bash set -euo pipefail gen-init () { echo "COPY common /build/common" } gen-cleanup () { echo "RUN rm -rf /build /data" } gen-docker-file () { if [ -f $src/Dockerfile.top ] ; then cat $src/Dockerfile.top gen-init fi for stage in $(cd $src && echo [0-9]*.[a-z]*) ; do case $stage in *.docker) cat $src/$stage if grep -wq '^FROM' $src/$stage ; then gen-init fi ;; *.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 gen-cleanup } if [ $# = 0 ] ; then echo >&2 "Usage: $0 []" 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 - \ --http-proxy \ --volume=$CACHE_DIR:/root/.cache \ "$@" \ . echo -n "Cache usage: " du -sh $CACHE_DIR | cut -d ' ' -f1