-
Notifications
You must be signed in to change notification settings - Fork 66
/
build.sh
executable file
·149 lines (130 loc) · 3.12 KB
/
build.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/bin/bash
SRC=$(realpath $(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd))
OUT=$SRC/out
SRCDIR=
ATTEMPTS=10
JOBS=$((`nproc` + 2))
JOBFAIL=30
DRYRUN=
UPDATE=
CHANNELS=()
TARGETS=()
PUSH=
IMAGE=docker.io/chromedp/headless-shell
URL='https://hub.docker.com/layers/chromedp/headless-shell/%s/images/sha256-%s?context=explore'
OPTIND=1
while getopts "o:s:a:j:k:nuc:t:pi:l:" opt; do
case "$opt" in
o) OUT=$OPTARG ;;
s) SRCDIR=$OPTARG ;;
a) ATTEMPTS=$OPTARG ;;
j) JOBS=$OPTARG ;;
k) JOBFAIL=$OPTARG ;;
n) DRYRUN=-n ;;
u) UPDATE=-u ;;
c) CHANNELS+=($OPTARG) ;;
t) TARGETS+=($OPTARG) ;;
p) PUSH=-p ;;
i) IMAGE=$OPTARG ;;
l) URL=$OPTARG ;;
esac
done
# determine source dir
if [ -z "$SRCDIR" ]; then
if [ -d /media/src ]; then
SRCDIR=/media/src
else
SRCDIR=$OUT
fi
fi
set -e
# determine channels
if [ ${#CHANNELS[@]} -eq 0 ]; then
CHANNELS=(stable beta dev)
fi
# determine targets
if [ ${#TARGETS[@]} -eq 0 ]; then
TARGETS=(amd64 arm64)
fi
echo "------------------------------------------------------------"
echo "STARTING ($(date))"
# determine versions
declare -A VERSIONS
for CHANNEL in ${CHANNELS[@]}; do
VERSIONS[$CHANNEL]=$(verhist -platform win64 -channel "$CHANNEL" -latest)
done
# order channels low -> high
CHANNELS_ORDER=$(
for i in ${!VERSIONS[@]}; do
echo "${VERSIONS[$i]}:::$i"
done | sort -V | awk -F::: '{print $2}' |xargs
)
# join_by ',' ${A[@]} ${B[@]}
join_by() {
local d=${1-} f=${2-}
if shift 2; then
printf %s "$f" "${@/#/$d}"
fi
}
channels() {
local s=()
for CHANNEL in $CHANNELS_ORDER; do
s+=("$CHANNEL:${VERSIONS[$CHANNEL]}")
done
join_by ' ' ${s[@]}
}
# display builds
echo "BUILDING: $(channels) [${TARGETS[@]}]"
echo -e "\n\nCLEANUP ($(date))"
$SRC/cleanup.sh \
-o "$OUT" \
-i "$IMAGE" \
-c $(join_by ' -c ' ${CHANNELS[@]}) \
-v $(join_by ' -v ' ${VERSIONS[@]})
echo "ENDED CLEANUP ($(date))"
# build
for CHANNEL in $CHANNELS_ORDER; do
VERSION=${VERSIONS[$CHANNEL]}
# skip build if archive already exists
if [[ -f $OUT/headless-shell-$VERSION-amd64.tar.bz2 && -f $OUT/headless-shell-$VERSION-arm64.tar.bz2 ]]; then
echo -e "\n\nSKIPPING BUILD FOR CHANNEL $CHANNEL $VERSION ($(date))"
continue
fi
# build
echo -e "\n\nSTARTING BUILD FOR CHANNEL $CHANNEL $VERSION ($(date))"
RET=1
$SRC/build-headless-shell.sh \
-o $OUT \
-s $SRCDIR \
-c $CHANNEL \
-a $ATTEMPTS \
-j $JOBS \
-k $JOBFAIL \
$DRYRUN \
$UPDATE \
-t $(join_by ' -t ' ${TARGETS[@]}) \
-v $VERSION \
&& RET=$?
if [ $RET -ne 0 ]; then
echo "COULD NOT BUILD $CHANNEL $VERSION ($(date))"
fi
echo "ENDED BUILD FOR $CHANNEL $VERSION ($(date))"
done
# build images
for CHANNEL in $CHANNELS_ORDER; do
VERSION=${VERSIONS[$CHANNEL]}
TAGS=($CHANNEL)
if [ "$CHANNEL" = "stable" ]; then
TAGS+=(latest)
fi
echo -e "\n\nSTARTING IMAGE BUILD FOR CHANNEL $CHANNEL $VERSION ($(date))"
$SRC/build-image.sh \
-o $OUT \
-t $(join_by ' -t ' ${TARGETS[@]}) \
-g $(join_by ' -g ' ${TAGS[@]}) \
-v "$VERSION" \
-i "$IMAGE" \
$PUSH
echo "ENDED IMAGE BUILD FOR CHANNEL $CHANNEL $VERSION ($(date))"
done
echo "DONE ($(date))"