forked from BtbN/FFmpeg-Builds
-
Notifications
You must be signed in to change notification settings - Fork 24
/
generate.sh
executable file
·80 lines (67 loc) · 1.79 KB
/
generate.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
set -e
cd "$(dirname "$0")"
source util/vars.sh
rm -f Dockerfile
layername() {
printf "layer-"
basename "$1" | sed 's/.sh$//'
}
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"
for addin in "${ADDINS[@]}"; do
(
source addins/"${addin}.sh"
type ffbuild_dockeraddin &>/dev/null && ffbuild_dockeraddin || true
)
done
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