Add fully layered build

This commit is contained in:
BtbN 2021-04-06 03:41:36 +02:00
parent d3518d0933
commit c419c549b9
4 changed files with 77 additions and 11 deletions

View file

@ -5,19 +5,69 @@ source util/vars.sh
rm -f Dockerfile
to_df() {
printf "$@" >> Dockerfile
echo >> Dockerfile
layername() {
printf "layer-"
basename "$1" | sed 's/.sh$//'
}
to_df "FROM ${REGISTRY}/${REPO}/base-${TARGET}:latest"
to_df "ENV TARGET=$TARGET VARIANT=$VARIANT REPO=$REPO ADDINS_STR=$ADDINS_STR"
for script in scripts.d/*.sh; do
(
SELF="$script"
source $script
exec_dockerstage() {
SCRIPT="$1"
(
SELF="$SCRIPT"
source "$SCRIPT"
ffbuild_enabled || exit 0
ffbuild_dockerstage || exit $?
)
)
}
to_df() {
_of="${TODF:-Dockerfile}"
printf "$@" >> "$_of"
echo >> "$_of"
}
to_df "FROM ${REGISTRY}/${REPO}/base-${TARGET}:latest AS base"
to_df "ENV TARGET=$TARGET VARIANT=$VARIANT REPO=$REPO ADDINS_STR=$ADDINS_STR"
PREVLAYER="base"
for ID in $(ls -1d scripts.d/??-* | sed -s 's|^.*/\(..\).*|\1|' | sort -u); do
LAYER="layer-$ID"
for STAGE in scripts.d/$ID-*; do
to_df "FROM $PREVLAYER AS $(layername "$STAGE")"
if [[ -f "$STAGE" ]]; then
exec_dockerstage "$STAGE"
else
for STAGE in "${STAGE}"/??-*; do
exec_dockerstage "$STAGE"
done
fi
done
to_df "FROM $PREVLAYER AS $LAYER"
for STAGE in scripts.d/$ID-*; do
if [[ -f "$STAGE" ]]; then
SCRIPT="$STAGE"
else
SCRIPTS=( "$STAGE"/??-* )
SCRIPT="${SCRIPTS[-1]}"
fi
(
SELF="$SCRIPT"
SELFLAYER="$(layername "$STAGE")"
source "$SCRIPT"
ffbuild_enabled || exit 0
ffbuild_dockerlayer || exit $?
TODF="Dockerfile.final" PREVLAYER="__PREVLAYER__" \
ffbuild_dockerfinal || exit $?
)
done
PREVLAYER="$LAYER"
done
to_df "FROM base"
sed "s/__PREVLAYER__/$PREVLAYER/g" Dockerfile.final | sort -u >> Dockerfile
rm Dockerfile.final

View file

@ -8,6 +8,14 @@ ffbuild_enabled() {
return 0
}
ffbuild_dockerlayer() {
to_df "COPY --from=${SELFLAYER} /usr/\$FFBUILD_TOOLCHAIN/. /usr/\$FFBUILD_TOOLCHAIN"
}
ffbuild_dockerfinal() {
to_df "COPY --from=${PREVLAYER} /usr/\$FFBUILD_TOOLCHAIN/. /usr/\$FFBUILD_TOOLCHAIN"
}
ffbuild_dockerbuild() {
git-mini-clone "$MINGW_REPO" "$MINGW_COMMIT" mingw
cd mingw/mingw-w64-headers

View file

@ -39,6 +39,14 @@ ffbuild_dockerstage() {
to_df "RUN --mount=src=${SELF},dst=/stage.sh run_stage /stage.sh"
}
ffbuild_dockerlayer() {
to_df "COPY --from=${SELFLAYER} \$FFBUILD_PREFIX/. \$FFBUILD_PREFIX"
}
ffbuild_dockerfinal() {
to_df "COPY --from=${PREVLAYER} \$FFBUILD_PREFIX/. \$FFBUILD_PREFIX"
}
ffbuild_configure() {
return 0
}