-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathbuild_single.sh
More file actions
executable file
·144 lines (118 loc) · 4.45 KB
/
build_single.sh
File metadata and controls
executable file
·144 lines (118 loc) · 4.45 KB
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
#!/bin/bash
# Exit on error
set -e
# Logging function
log() {
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')] $@"
}
# Retry function
retry() {
local retries=${RETRIES:-3}
local count=0
until "$@"; do
exit_code=$?
count=$((count + 1))
if [ $count -lt $retries ]; then
log "Retrying ($count/$retries)..."
sleep 5
else
log "Failed after $count attempts."
return $exit_code
fi
done
return 0
}
# Parse arguments
while [[ "$#" -gt 0 ]]; do
case $1 in
--bun) BUN_VERSION="$2"; shift ;;
--node) NODE_VERSION="$2"; shift ;;
--distro) DISTRO="$2"; shift ;;
*) echo "Unknown parameter passed: $1"; exit 1 ;;
esac
shift
done
if [ -z "$BUN_VERSION" ] || [ -z "$NODE_VERSION" ] || [ -z "$DISTRO" ]; then
echo "Usage: $0 --bun <version> --node <version> --distro <distro>"
exit 1
fi
log "Building image for Bun version $BUN_VERSION, Node version $NODE_VERSION, Distro $DISTRO"
# Read versions.json for codename lookup (optional, but good for tagging)
# If versions.json is not present, we might miss some tags, but the matrix generation should have ensured we have what we need.
# Actually, we need versions.json to know the codename (e.g. "Iron") and to check if it's "latest".
# We can expect versions.json to be present in the working directory (downloaded by workflow).
if [ -f "versions.json" ]; then
json_data=$(cat versions.json)
else
json_data="{}"
fi
REGISTRY=${REGISTRY:-imbios}
PLATFORMS=${PLATFORMS:-linux/amd64,linux/arm64}
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%.*}
local is_canary=false
if [[ $bun_version == *"-canary"* ]]; then
is_canary=true
bun_version="canary"
fi
echo "$REGISTRY/bun-node:${bun_version}-${node_version}-${distro}"
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}"
elif [[ $bun_version == "canary" ]]; then
echo "$REGISTRY/bun-node:canary-${node_minor}-${distro}"
echo "$REGISTRY/bun-node:canary-${node_major}-${distro}"
fi
local codename=$(echo "${json_data}" | jq -r ".nodejs.\"${node_major}\".name")
if [ "$codename" != "null" ]; then
echo "$REGISTRY/bun-node:${bun_version}-${codename}-${distro}"
if [[ $is_canary == false ]]; then
echo "$REGISTRY/bun-node:latest-${codename}-${distro}"
fi
fi
if [[ $is_canary == false ]]; then
echo "$REGISTRY/bun-node:latest-${node_version}-${distro}"
echo "$REGISTRY/bun-node:latest-${node_major}-${distro}"
fi
# Latest tag logic
# We rely on the caller (workflow) or check versions.json to see if this is the latest Node version.
local latest_node_major=$(echo "${json_data}" | jq -r '.nodejs | keys | map(tonumber) | max')
if [[ $is_canary == false && "$node_major" == "$latest_node_major" && $distro == "debian" ]]; then
echo "$REGISTRY/bun-node:latest"
fi
if [[ $is_canary == false ]]; then
echo "$REGISTRY/bun-node:${node_major}-${distro}"
fi
}
tag_distro=$DISTRO
if [ "$DISTRO" == "debian-slim" ]; then
tag_distro="slim"
fi
tags=($(generate_tags "$BUN_VERSION" "$NODE_VERSION" "$tag_distro"))
image_name="$REGISTRY/bun-node:${BUN_VERSION}-${NODE_VERSION}-${tag_distro}"
node_major=${NODE_VERSION%%.*}
for tag in "${tags[@]}"; do
log "Tagging $image_name as $tag"
retry docker buildx build --sbom=true --provenance=true --platform "$PLATFORMS" -t "$image_name" -t "$tag" "./src/base/${node_major}/${DISTRO}" --push --provenance=mode=max
if [ "$DISTRO" == "alpine" ]; then
log "Building and Tagging Alpine image with Git"
retry docker buildx build --sbom=true --provenance=true --platform "$PLATFORMS" -t "$image_name-git" -t "$tag-git" "./src/git/${node_major}/${DISTRO}" --push --provenance=mode=max
fi
done
# Output success JSON fragment for aggregation
# We need to update versions.json with the new versions.
# We output a JSON file that the workflow can pick up.
bun_tag="latest"
if [[ $BUN_VERSION == *"-canary"* ]]; then
bun_tag="canary"
fi
# Create a partial JSON update
echo "{\"nodejs\": {\"$node_major\": {\"version\": \"v$NODE_VERSION\"}}, \"bun\": {\"$bun_tag\": \"v$BUN_VERSION\"}}" > build_success.json