-
-
Notifications
You must be signed in to change notification settings - Fork 65
/
update.sh
executable file
·147 lines (128 loc) · 3.59 KB
/
update.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
#!/bin/bash
trap killgroup SIGINT
action=${1:-push}
platform=${2:-linux/amd64,linux/arm64}
function killgroup() {
echo killing...
kill 0
}
function generated_warning() {
cat <<-EOH
#
# NOTE: THIS DOCKERFILE IS GENERATED VIA "update.sh"
#
# PLEASE DO NOT EDIT IT DIRECTLY.
#
EOH
}
function docker_tag_exists() {
docker manifest inspect $1:$2 &> /dev/null && docker manifest inspect ghcr.io/$1:$2 &> /dev/null
}
# wkhtmltopdf versions
for version in \
0.12.6 \
; do
# edition small (contains only wkhtmltopdf) or full (with wkhtmltopdf, wkhtmltoimage and lib)
for edition in \
small \
full \
; do
# Supported base images
for image in \
alpine:3.20.3 \
node:22.11.0-alpine3.20 \
python:3.13.0-alpine3.20 \
; do
# Parse image string
base="${image%%:*}"
baseVersion="${image##*:}"
baseVersionClean="${baseVersion%%-*}"
# Apply patch based on edition
case "$edition" in
small)
replaceRules="
/%%EDITION1%%/d;
/%%EDITION2%%/d;
"
;;
full)
replaceRules="
s/%%EDITION1%%/COPY --from=builder \/bin\/wkhtmltoimage \/bin\/wkhtmltoimage/g;
s/%%EDITION2%%/COPY --from=builder \/lib\/libwkhtmltox* \/lib\//g;
"
;;
esac
# Check for base OS type (currently only alpine)
case "$image" in
alpine*)
os="alpine"
template="Dockerfile-alpine.template"
replaceRules+="
s/%%IMAGE%%/$image/g;
s/%%WKHTMLTOXVERSION%%/$version/g;
s/%%END%%/ENTRYPOINT [\"wkhtmltopdf\"]/g;
"
;;
*alpine*)
os="alpine"
template="Dockerfile-alpine.template"
replaceRules+="
s/%%IMAGE%%/$image/g;
s/%%WKHTMLTOXVERSION%%/$version/g;
/%%END%%/d;
"
;;
*)
echo "WARNING: OS Type not supported"
exit
;;
esac
case "$image" in
alpine*)
replaceRules+="
s/%%BUILDER%%/$image/g;
"
;;
node*)
replaceRules+="
s/%%BUILDER%%/alpine:3.20/g;
"
;;
python*)
replaceRules+="
s/%%BUILDER%%/alpine:3.20/g;
"
;;
*)
echo "WARNING: OS Type not supported"
exit
;;
esac
# Prepare imageName and tag
if [ "$os" == "$base" ]; then
imageName="$base-wkhtmltopdf"
else
imageName="$os-$base-wkhtmltopdf"
fi
tag="$baseVersionClean-$version-$edition"
dir="archive/$imageName"
file="Dockerfile_$tag"
# Build container if needed
if ! docker_tag_exists "surnet/$imageName" "$tag"; then
# Prepare Dockerfile
mkdir -p "$dir"
{ generated_warning; cat "$template"; } > "$dir/$file"
sed -i.bak -e "$replaceRules" "$dir/$file"
# Build container
echo "Starting build for surnet/$imageName:$tag"
docker buildx build . -f "$dir/$file" -t "surnet/$imageName:$tag" --platform ${platform} --${action} \
&& docker buildx build . -f "$dir/$file" -t "ghcr.io/surnet/$imageName:$tag" --platform ${platform} --${action} \
&& echo "Successfully built and pushed surnet/$imageName:$tag" || echo "Building or pushing failed for surnet/$imageName:$tag"
fi
done
done
done
wait
echo "###########################################################
The script completed creating and pushing docker images
###########################################################"