This repository has been archived by the owner on Jan 11, 2022. It is now read-only.
forked from nodejs/docker-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.sh
executable file
·118 lines (96 loc) · 3.3 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
#!/bin/bash
set -ue
. functions.sh
cd "$(cd "${0%/*}" && pwd -P)";
IFS=' ' read -ra versions <<< "$(get_versions . "$@")"
if [ ${#versions[@]} -eq 0 ]; then
fatal "No valid versions found!"
fi
# Global variables
# Get architecure and use this as target architecture for docker image
# See details in function.sh
# TODO: Should be able to specify target architecture manually
arch=$(get_arch)
yarnVersion="$(curl -sSL --compressed https://yarnpkg.com/latest-version)"
function update_node_version {
local baseuri=$1
shift
local version=$1
shift
local template=$1
shift
local dockerfile=$1
shift
local variant=
if [[ $# -eq 1 ]]; then
variant=$1
shift
fi
fullVersion="$(curl -sSL --compressed "$baseuri" | grep '<a href="v'"$version." | sed -E 's!.*<a href="v([^"/]+)/?".*!\1!' | cut -d'.' -f2,3| sort -n | tail -1)"
(
cp "$template" "$dockerfile"
local fromprefix=
if [[ "$arch" != "amd64" && "$variant" != "onbuild" ]]; then
fromprefix="$arch\\/"
fi
sed -E -i.bak 's/^FROM (.*)/FROM '"$fromprefix"'\1/' "$dockerfile" && rm "$dockerfile".bak
sed -E -i.bak 's/^(ENV NODE_VERSION |FROM .*node:).*/\1'"$version.${fullVersion:-0}"'/' "$dockerfile" && rm "$dockerfile".bak
sed -E -i.bak 's/^(ENV YARN_VERSION ).*/\1'"$yarnVersion"'/' "$dockerfile" && rm "$dockerfile".bak
# shellcheck disable=SC1004
new_line=' \\\
'
# Add GPG keys
for key_type in "node" "yarn"
do
while read -r line
do
pattern="\"\\$\\{$(echo "$key_type" | tr '[:lower:]' '[:upper:]')_KEYS\\[@\\]\\}\""
sed -E -i.bak -e "s/([ \\t]*)($pattern)/\\1${line}${new_line}\\1\\2/" "$dockerfile" && rm "$dockerfile".bak
done < "keys/$key_type.keys"
sed -E -i.bak "/$pattern/d" "$dockerfile" && rm "$dockerfile".bak
done
if [[ "${version/.*/}" -ge 10 ]]; then
sed -E -i.bak 's/FROM (.*)alpine:3.4/FROM \1alpine:3.7/' "$dockerfile"
rm "$dockerfile.bak"
elif [[ "${version/.*/}" -ge 8 || "$arch" = "ppc64le" || "$arch" = "s390x" || "$arch" = "arm64" || "$arch" = "arm32v7" ]]; then
sed -E -i.bak 's/FROM (.*)alpine:3.4/FROM \1alpine:3.6/' "$dockerfile"
rm "$dockerfile.bak"
fi
)
}
function add_stage {
local baseuri=$1
shift
local version=$1
shift
local variant=$1
shift
echo ' - stage: Build
env:
- NODE_VERSION: "'"$version"'"
- VARIANT: "'"$variant"'"
' >> .travis.yml
}
echo '#### DO NOT MODIFY. THIS FILE IS AUTOGENERATED ####
' | cat - travis.yml.template > .travis.yml
for version in "${versions[@]}"; do
# Skip "docs" and other non-docker directories
[ -f "$version/Dockerfile" ] || continue
info "Updating version $version..."
parentpath=$(dirname "$version")
versionnum=$(basename "$version")
baseuri=$(get_config "$parentpath" "baseuri")
add_stage "$baseuri" "$version" "default"
update_node_version "$baseuri" "$versionnum" "$parentpath/Dockerfile.template" "$version/Dockerfile" &
# Get supported variants according the target architecture
# See details in function.sh
IFS=' ' read -ra variants <<< "$(get_variants "$parentpath")"
for variant in "${variants[@]}"; do
# Skip non-docker directories
[ -f "$version/$variant/Dockerfile" ] || continue
add_stage "$baseuri" "$version" "$variant"
update_node_version "$baseuri" "$versionnum" "$parentpath/Dockerfile-$variant.template" "$version/$variant/Dockerfile" "$variant" &
done
done
wait
info "Done!"