-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
update.sh
executable file
·105 lines (89 loc) · 2.65 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
#!/bin/bash
trap killgroup SIGINT
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
}
# opencv versions
for version in \
4.10.0 \
; do
# edition small (opencv only) or full (with opencv_contrib)
for edition in \
base \
text \
; do
# Supported base images
for image in \
alpine:3.20.3 \
node:22.11.0-alpine3.20 \
; do
# Parse image string
base="${image%%:*}"
baseVersion="${image##*:}"
baseVersionClean="${baseVersion%%-*}"
# Check for base OS type (currently only alpine)
case "$image" in
alpine*)
os="alpine"
template="Dockerfile-alpine-$edition.template"
replaceRules="
s/%%IMAGE%%/$image/g;
s/%%OPENCVVERSION%%/$version/g;
/%%END%%/d;
"
;;
*alpine*)
os="alpine"
template="Dockerfile-alpine-$edition.template"
replaceRules="
s/%%IMAGE%%/$image/g;
s/%%OPENCVVERSION%%/$version/g;
s/%%END%%/ENV OPENCV4NODEJS_DISABLE_AUTOBUILD=1/g;
"
;;
*)
echo "WARNING: OS Type not supported"
exit
;;
esac
# Prepare imageName and tag
if [ "$os" == "$base" ]; then
imageName="$base-opencv"
else
imageName="$os-$base-opencv"
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 linux/amd64,linux/arm64 --push \
&& docker buildx build . -f "$dir/$file" -t "ghcr.io/surnet/$imageName:$tag" --platform linux/amd64,linux/arm64 --push \
&& 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
###########################################################"