-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build-updated.sh
executable file
·164 lines (140 loc) · 5.22 KB
/
build-updated.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/bin/bash
# Exit on error
set -e
# Logging function
log() {
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')] $@"
}
# Function to validate version format
validate_version() {
local version=$1
local regex="^[0-9]+\.[0-9]+\.[0-9]+(-canary\.[0-9]{8}\.[0-9]+)?$"
if [[ ! $version =~ $regex ]]; then
echo "Invalid version format: $version"
exit 1
fi
}
# Convert comma-separated strings to arrays
IFS=',' read -ra NODE_VERSIONS <<<"$NODE_VERSIONS_TO_BUILD"
IFS=',' read -ra BUN_VERSIONS <<<"$BUN_VERSIONS_TO_BUILD"
IFS=',' read -ra DISTROS <<<"$DISTROS"
# If NODE_VERSIONS_TO_BUILD is empty, but BUN_VERSIONS_TO_BUILD is not,
# build all versions from versions.json
if [ -z "$NODE_VERSIONS_TO_BUILD" ]; then
IFS=',' read -ra NODE_MAJOR_VERSIONS <<<"$NODE_MAJOR_VERSIONS_TO_CHECK"
NODE_VERSIONS=()
for node_major_version in "${NODE_MAJOR_VERSIONS[@]}"; do
node_version=$(cat versions.json | jq -r ".nodejs.\"${node_major_version}\".version")
if [ "$node_version" != "null" ]; then
# Remove v from version
NODE_VERSIONS+=("${node_version//v/}")
fi
done
fi
log "Building Node versions: ${NODE_VERSIONS[*]}"
# If BUN_VERSIONS_TO_BUILD is empty, but NODE_VERSIONS_TO_BUILD is not,
# build all versions from versions.json
if [ -z "$BUN_VERSIONS_TO_BUILD" ]; then
BUN_VERSIONS=()
for bun_version in $(cat versions.json | jq -r '.bun | keys[]'); do
# Remove v from version
BUN_VERSIONS+=("${bun_version//v/}")
done
fi
log "Building Bun versions: ${BUN_VERSIONS[*]}"
# Validate versions
for version in "${NODE_VERSIONS[@]}"; do
validate_version "$version"
done
for version in "${BUN_VERSIONS[@]}"; do
validate_version "$version"
done
# Read the JSON file
json_data=$(cat versions.json)
# Function to generate tags
generate_tags() {
local bun_version=$1
local node_version=$2
local distro=$3
local node_major=${node_version%%.*}
local node_minor=${node_version%.*}
local bun_major=${bun_version%%.*}
local bun_minor=${bun_version%.*}
# Canary version check
local is_canary=false
if [[ $bun_version == *"-canary"* ]]; then
is_canary=true
bun_version="canary"
fi
# Base tag
echo "$REGISTRY/bun-node:${bun_version}-${node_version}-${distro}"
# Additional tags
if [ $is_canary == false ]; then
echo "$REGISTRY/bun-node:${bun_minor}-${node_version}-${distro}"
echo "$REGISTRY/bun-node:${bun_major}-${node_version}-${distro}"
echo "$REGISTRY/bun-node:${bun_version}-${node_minor}-${distro}"
echo "$REGISTRY/bun-node:${bun_version}-${node_major}-${distro}"
echo "$REGISTRY/bun-node:${bun_minor}-${node_minor}-${distro}"
echo "$REGISTRY/bun-node:${bun_minor}-${node_major}-${distro}"
echo "$REGISTRY/bun-node:${bun_major}-${node_minor}-${distro}"
echo "$REGISTRY/bun-node:${bun_major}-${node_major}-${distro}"
elif [[ $bun_version == "canary" ]]; then
echo "$REGISTRY/bun-node:canary-${node_minor}-${distro}"
echo "$REGISTRY/bun-node:canary-${node_major}-${distro}"
fi
# Special nodejs codename tags
# Extract the codename for the current version
local codename=$(echo "${json_data}" | jq -r ".nodejs.\"${node_major}\".name")
echo "$REGISTRY/bun-node:${bun_version}-${codename}-${distro}"
if [[ $is_canary == false ]]; then
echo "$REGISTRY/bun-node:latest-${node_version}-${distro}"
echo "$REGISTRY/bun-node:latest-${node_major}-${distro}"
echo "$REGISTRY/bun-node:latest-${codename}-${distro}"
fi
# Special 'latest' tag
local is_latest_lts=false
if [[ "$node_major" == "20" ]]; then
is_latest_lts=true
fi
if [[ $is_canary == false && $is_latest_lts == true && $distro == "debian" ]]; then
echo "$REGISTRY/bun-node:latest"
fi
# Special 'node_major-distro' tag
if [[ $is_canary == false ]]; then
echo "$REGISTRY/bun-node:${node_major}-${distro}"
fi
}
# Build, tag, and push loop
for bun_version in "${BUN_VERSIONS[@]}"; do
for node_version in "${NODE_VERSIONS[@]}"; do
for distro in "${DISTROS[@]}"; do
tag_distro=$distro
if [ "$distro" == "debian-slim" ]; then
tag_distro="slim"
fi
# Generate tags
tags=($(generate_tags "$bun_version" "$node_version" "$tag_distro"))
# Building the image
node_major=${node_version%%.*}
log "Building image for Bun version $bun_version, Node version $node_version, Distro $distro"
image_name="$REGISTRY/bun-node:${bun_version}-${node_version}-${tag_distro}"
for tag in "${tags[@]}"; do
log "Tagging $image_name as $tag"
docker buildx build --platform "$PLATFORMS" -t "$image_name" -t "$tag" "./src/base/${node_major}/${distro}" --push
# alpine image with git
if [ "$distro" == "alpine" ]; then
log "Building and Tagging Alpine image with Git"
docker buildx build --platform "$PLATFORMS" -t "$image_name-git" -t "$tag-git" "./src/git/${node_major}/${distro}" --push
fi
done
# On success, update the versions.json file
log "Updating versions.json file"
bun_tag="latest"
if [[ $bun_version == *"-canary"* ]]; then
bun_tag="canary"
fi
json_data=$(echo "${json_data}" | jq ".nodejs.\"${node_major}\".version = \"v${node_version}\"" | jq ".bun.\"${bun_tag}\" = \"v${bun_version}\"")
echo "${json_data}" >versions.json
done
done
done