-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathbuild-multiarch.sh
More file actions
executable file
·101 lines (90 loc) · 4.15 KB
/
build-multiarch.sh
File metadata and controls
executable file
·101 lines (90 loc) · 4.15 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
#!/bin/bash
# Build and push multi-architecture Docker images (AMD64 + ARM64)
# This creates manifest lists so a single tag works on both architectures.
#
# Prerequisites:
# - docker buildx with multi-platform support
# - Logged in to Docker Hub: docker login
#
# Usage:
# ./build-multiarch.sh # Build and push all images
# ./build-multiarch.sh --local # Build for local architecture only (no push)
set -e
PLATFORMS="linux/amd64,linux/arm64"
PUSH_FLAG="--push"
if [ "$1" == "--local" ]; then
PLATFORMS="linux/$(uname -m | sed 's/x86_64/amd64/' | sed 's/aarch64/arm64/')"
PUSH_FLAG="--load"
echo "🔨 Building for local platform only ($PLATFORMS)..."
else
echo "🚀 Building multi-arch images (amd64 + arm64) and pushing to Docker Hub..."
echo "⚠️ Make sure you're logged in: docker login"
echo ""
fi
# Create/use a buildx builder that supports multi-platform
BUILDER_NAME="multiarch-builder"
if ! docker buildx inspect "$BUILDER_NAME" > /dev/null 2>&1; then
echo "📦 Creating buildx builder: $BUILDER_NAME"
docker buildx create --name "$BUILDER_NAME" --use --bootstrap
else
docker buildx use "$BUILDER_NAME"
fi
# Java Producer (Avro)
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "📦 Building cnfltraining/java-producer-avro:2.0"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
docker buildx build \
--platform "$PLATFORMS" \
-t cnfltraining/java-producer-avro:2.0 \
-t cnfltraining/java-producer-avro:latest \
-f solution/java-producer-avro/Dockerfile \
$PUSH_FLAG \
solution/java-producer-avro
# Webserver (plain)
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "📦 Building cnfltraining/node-webserver:3.0"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
docker buildx build \
--platform "$PLATFORMS" \
-t cnfltraining/node-webserver:3.0 \
-t cnfltraining/node-webserver:latest \
-f webserver/Dockerfile \
$PUSH_FLAG \
webserver
# Webserver Avro
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "📦 Building cnfltraining/node-webserver-avro:3.0"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
docker buildx build \
--platform "$PLATFORMS" \
-t cnfltraining/node-webserver-avro:3.0 \
-t cnfltraining/node-webserver-avro:latest \
-f webserver-avro/Dockerfile \
$PUSH_FLAG \
webserver-avro
# Webserver Streams
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "📦 Building cnfltraining/node-webserver-streams:1.0"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
docker buildx build \
--platform "$PLATFORMS" \
-t cnfltraining/node-webserver-streams:1.0 \
-t cnfltraining/node-webserver-streams:latest \
-f webserver-streams/Dockerfile \
$PUSH_FLAG \
webserver-streams
echo ""
echo "✅ All images built successfully!"
echo ""
if [ "$1" != "--local" ]; then
echo "🔍 Verify multi-arch support with:"
echo " docker manifest inspect cnfltraining/node-webserver:3.0"
echo ""
echo "📋 Expected output shows both architectures:"
echo " - linux/amd64"
echo " - linux/arm64"
fi