2020-09-01 22:07:54 +00:00
|
|
|
#!/bin/bash
|
2021-12-06 18:29:52 +00:00
|
|
|
set -e
|
2020-09-01 22:07:54 +00:00
|
|
|
cd "$(dirname "$0")"
|
2020-09-02 23:03:23 +00:00
|
|
|
source util/vars.sh
|
2020-09-01 22:07:54 +00:00
|
|
|
|
2023-06-18 14:44:57 +00:00
|
|
|
rm -f Dockerfile Dockerfile.{dl,final,dl.final}
|
2020-09-01 22:07:54 +00:00
|
|
|
|
2021-04-06 01:41:36 +00:00
|
|
|
layername() {
|
|
|
|
printf "layer-"
|
|
|
|
basename "$1" | sed 's/.sh$//'
|
|
|
|
}
|
|
|
|
|
2023-06-18 14:44:57 +00:00
|
|
|
to_df() {
|
|
|
|
_of="${TODF:-Dockerfile}"
|
|
|
|
printf "$@" >> "$_of"
|
|
|
|
echo >> "$_of"
|
|
|
|
}
|
|
|
|
|
2023-06-18 19:25:50 +00:00
|
|
|
default_dl() {
|
|
|
|
to_df "RUN git-mini-clone \"$SCRIPT_REPO\" \"$SCRIPT_COMMIT\" \"$1\""
|
|
|
|
}
|
|
|
|
|
2023-06-18 14:44:57 +00:00
|
|
|
###
|
|
|
|
### Generate download Dockerfile
|
|
|
|
###
|
|
|
|
|
|
|
|
exec_dockerstage_dl() {
|
|
|
|
SCRIPT="$1"
|
|
|
|
(
|
|
|
|
SELF="$SCRIPT"
|
|
|
|
SELFLAYER="$(layername "$STAGE")"
|
|
|
|
source "$SCRIPT"
|
2023-06-18 19:25:50 +00:00
|
|
|
ffbuild_dockerdl || exit $?
|
2023-06-18 14:44:57 +00:00
|
|
|
TODF="Dockerfile.dl.final" ffbuild_dockerlayer_dl || exit $?
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export TODF="Dockerfile.dl"
|
|
|
|
|
|
|
|
to_df "FROM ${REGISTRY}/${REPO}/base:latest AS base"
|
|
|
|
to_df "ENV TARGET=$TARGET VARIANT=$VARIANT REPO=$REPO ADDINS_STR=$ADDINS_STR"
|
2023-06-18 19:25:50 +00:00
|
|
|
to_df "WORKDIR \$FFBUILD_DLDIR"
|
2023-06-18 14:44:57 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
if [[ -f "$STAGE" ]]; then
|
|
|
|
to_df "FROM $PREVLAYER AS $(layername "$STAGE")"
|
|
|
|
exec_dockerstage_dl "$STAGE"
|
|
|
|
else
|
|
|
|
for STAGE in "${STAGE}"/??-*; do
|
|
|
|
to_df "FROM $PREVLAYER AS $(layername "$STAGE")"
|
|
|
|
exec_dockerstage_dl "$STAGE"
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
done
|
|
|
|
|
|
|
|
to_df "FROM base AS intermediate"
|
|
|
|
cat Dockerfile.dl.final >> "$TODF"
|
|
|
|
rm Dockerfile.dl.final
|
|
|
|
|
|
|
|
to_df "FROM base"
|
|
|
|
to_df "COPY --from=intermediate \$FFBUILD_DLDIR/. \$FFBUILD_DLDIR"
|
|
|
|
|
|
|
|
if [[ "$TARGET" == "dl" && "$VARIANT" == "only" ]]; then
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
###
|
|
|
|
### Generate main Dockerfile
|
|
|
|
###
|
|
|
|
|
2021-04-06 01:41:36 +00:00
|
|
|
exec_dockerstage() {
|
|
|
|
SCRIPT="$1"
|
|
|
|
(
|
|
|
|
SELF="$SCRIPT"
|
|
|
|
source "$SCRIPT"
|
|
|
|
ffbuild_enabled || exit 0
|
|
|
|
ffbuild_dockerstage || exit $?
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2023-06-18 14:44:57 +00:00
|
|
|
export TODF="Dockerfile"
|
2020-09-01 22:07:54 +00:00
|
|
|
|
2021-04-06 01:41:36 +00:00
|
|
|
to_df "FROM ${REGISTRY}/${REPO}/base-${TARGET}:latest AS base"
|
2020-09-27 21:11:10 +00:00
|
|
|
to_df "ENV TARGET=$TARGET VARIANT=$VARIANT REPO=$REPO ADDINS_STR=$ADDINS_STR"
|
2020-09-01 22:07:54 +00:00
|
|
|
|
2022-11-02 20:50:05 +00:00
|
|
|
for addin in "${ADDINS[@]}"; do
|
|
|
|
(
|
|
|
|
source addins/"${addin}.sh"
|
2022-11-03 00:41:44 +00:00
|
|
|
type ffbuild_dockeraddin &>/dev/null && ffbuild_dockeraddin || true
|
2022-11-02 20:50:05 +00:00
|
|
|
)
|
|
|
|
done
|
|
|
|
|
2021-04-06 01:41:36 +00:00
|
|
|
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"
|
2020-09-01 22:07:54 +00:00
|
|
|
done
|
2021-04-06 01:41:36 +00:00
|
|
|
|
|
|
|
to_df "FROM base"
|
|
|
|
sed "s/__PREVLAYER__/$PREVLAYER/g" Dockerfile.final | sort -u >> Dockerfile
|
|
|
|
rm Dockerfile.final
|