-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·154 lines (138 loc) · 3.88 KB
/
build.sh
File metadata and controls
executable file
·154 lines (138 loc) · 3.88 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
145
146
147
148
149
150
151
152
153
154
#!/bin/bash
trap ctrl_c INT
function ctrl_c() {
echo "Requested to stop."
exit 1
}
set -euo pipefail
PREFIX="awsdeepracercommunity"
VARIANTS="cpu gpu"
PLATFORM=""
function usage() {
cat <<EOF
Usage: $0 [-a "cpu gpu"] [--platform linux/amd64|linux/arm64] [-p prefix] [-f] [-c] [--push]
-a, --variant Space-separated variants to build (default: "cpu gpu")
--platform Docker platform to build for (default: native host)
-p, --prefix Image prefix / repository namespace
-f, --no-cache Disable Docker build cache
-c, --rebuild-core Force rebuild of the core builder image
--push Push built leaf images after the build completes
EOF
}
function detect_platform() {
case "$(uname -m)" in
x86_64|amd64)
echo "linux/amd64"
;;
aarch64|arm64)
echo "linux/arm64"
;;
*)
echo "Unsupported host architecture: $(uname -m)" >&2
exit 1
;;
esac
}
while [[ $# -gt 0 ]]; do
case "$1" in
-a|--variant)
VARIANTS="$2"
shift 2
;;
--platform)
PLATFORM="$2"
shift 2
;;
-p|--prefix)
PREFIX="$2"
shift 2
;;
-f|--no-cache)
OPT_NOCACHE="--no-cache"
shift
;;
-c|--rebuild-core)
OPT_CORE="yes"
shift
;;
--push)
OPT_PUSH="yes"
shift
;;
-h|--help)
usage
exit 0
;;
*)
echo "Unknown option $1" >&2
usage
exit 1
;;
esac
done
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
VERSION=$(jq -r '.simapp' "$DIR/VERSION")
PLATFORM="${PLATFORM:-$(detect_platform)}"
case "$PLATFORM" in
linux/amd64)
TARGET_ARCH="amd64"
;;
linux/arm64)
TARGET_ARCH="arm64"
;;
*)
echo "Unsupported platform ${PLATFORM}" >&2
exit 1
;;
esac
CORE_TAG="latest-${TARGET_ARCH}"
BUNDLE_TAG="latest-${TARGET_ARCH}"
if [ "$(docker images -q ${PREFIX}/deepracer-simapp-build-core:${CORE_TAG} 2>/dev/null)" == "" ] || [ -n "${OPT_NOCACHE:-}" ] || [ -n "${OPT_CORE:-}" ]; then
echo "Preparing core builder image ${PREFIX}/deepracer-simapp-build-core:${CORE_TAG} for ${PLATFORM}..."
docker buildx build ${OPT_NOCACHE:-} --load --platform "${PLATFORM}" \
-t ${PREFIX}/deepracer-simapp-build-core:${CORE_TAG} \
-f docker/Dockerfile.build-core .
else
echo "Core builder image ${PREFIX}/deepracer-simapp-build-core:${CORE_TAG} already exists."
fi
echo "Preparing bundle distribution for ${PLATFORM}..."
docker buildx build ${OPT_NOCACHE:-} --load --platform "${PLATFORM}" \
-t ${PREFIX}/deepracer-simapp-build-bundle:${BUNDLE_TAG} \
-f docker/Dockerfile.build-bundle \
--build-arg CORE_PREFIX=${PREFIX} \
--build-arg CORE_TAG=${CORE_TAG} .
echo "Preparing docker images for [${VARIANTS}] on ${PLATFORM}"
for variant in $VARIANTS; do
case $variant in
gpu)
if [ "${TARGET_ARCH}" != "amd64" ]; then
echo "Skipping gpu build on ${PLATFORM}; only linux/amd64 is supported."
continue
fi
CORE_IMG="nvcr.io/nvidia/cuda:12.6.3-cudnn-runtime-ubuntu24.04"
NVCC_VER="cuda-nvcc-12-6"
;;
cpu)
CORE_IMG="ubuntu:24.04"
NVCC_VER=""
;;
*)
echo "Unknown variant ${variant}" >&2
exit 1
;;
esac
IMAGE_TAG="${PREFIX}/deepracer-simapp:${VERSION}-${variant}-${TARGET_ARCH}"
set -x
docker buildx build . ${OPT_NOCACHE:-} --load --platform "${PLATFORM}" \
-t "${IMAGE_TAG}" \
-f docker/Dockerfile.combined \
--build-arg IMG_VERSION="${VERSION}" \
--build-arg BUNDLE_PREFIX="${PREFIX}" \
--build-arg BUNDLE_TAG="${BUNDLE_TAG}" \
--build-arg CORE_IMG="${CORE_IMG}" \
--build-arg NVCC_VER="${NVCC_VER}"
set +x
if [ -n "${OPT_PUSH:-}" ]; then
docker push "${IMAGE_TAG}"
fi
done