-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathbuild_multiarch.sh
More file actions
executable file
·71 lines (60 loc) · 2.19 KB
/
build_multiarch.sh
File metadata and controls
executable file
·71 lines (60 loc) · 2.19 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
#!/bin/bash
set -e
# Multiarch Docker Build Script
# This script builds the ops-cli Docker image for multiple architectures
IMAGE_NAME="${IMAGE_NAME:-ghcr.io/adobe/ops-cli}"
IMAGE_TAG="${IMAGE_TAG:-latest}"
PLATFORMS="${PLATFORMS:-linux/amd64,linux/arm64}"
PUSH="${PUSH:-false}"
echo "Building multiarch Docker image..."
echo "Image: ${IMAGE_NAME}:${IMAGE_TAG}"
echo "Platforms: ${PLATFORMS}"
echo "Push to registry: ${PUSH}"
# Login to GitHub Container Registry if pushing
if [ "$PUSH" = "true" ]; then
if [ -z "$GITHUB_USERNAME" ] || [ -z "$GITHUB_TOKEN" ]; then
echo "Error: GITHUB_USERNAME and GITHUB_TOKEN environment variables must be set when PUSH=true"
exit 1
fi
echo "Logging in to ghcr.io..."
echo "$GITHUB_TOKEN" | docker login ghcr.io -u "$GITHUB_USERNAME" --password-stdin
if [ $? -ne 0 ]; then
echo "Error: Failed to login to GitHub Container Registry"
exit 1
fi
echo "Successfully logged in to ghcr.io"
fi
# Build the image
BUILD_ARGS=""
if [ "$PUSH" = "true" ]; then
BUILD_ARGS="--push"
else
BUILD_ARGS="--load"
fi
# Note: --load only works for single platform builds
# For multiplatform builds without pushing, use --output type=docker
if [ "$PUSH" = "false" ] && [[ "$PLATFORMS" == *","* ]]; then
echo "Warning: Cannot use --load with multiple platforms."
echo "Building without --load (image will not be loaded to local docker)."
echo "To load to local docker, specify a single platform or use --push to push to registry."
BUILD_ARGS=""
fi
docker buildx build \
--platform ${PLATFORMS} \
--tag ${IMAGE_NAME}:${IMAGE_TAG} \
${BUILD_ARGS} \
--file Dockerfile \
.
echo "Build complete!"
if [ "$PUSH" = "true" ]; then
echo "Image pushed to registry as ${IMAGE_NAME}:${IMAGE_TAG}"
else
if [[ "$PLATFORMS" == *","* ]]; then
echo "Note: Multi-platform images were built but not loaded to local docker."
echo "To use them, either:"
echo " 1. Push to a registry: PUSH=true ./build_multiarch.sh"
echo " 2. Build for single platform: PLATFORMS=linux/amd64 ./build_multiarch.sh"
else
echo "Image loaded to local docker as ${IMAGE_NAME}:${IMAGE_TAG}"
fi
fi