Skip to content

Commit b7864f6

Browse files
authored
Merge pull request #241 from huoqifeng/multiarch-scripts
multi-arch: create build scripts for multi-arch
2 parents 4b7be3d + 39953fa commit b7864f6

File tree

2 files changed

+140
-0
lines changed

2 files changed

+140
-0
lines changed

dev/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,8 @@ cd dev/
7575
```
7676

7777
Then run the Kepler binary at `_output/bin/_/kepler`
78+
79+
## Build kepler and base multi-arch images
80+
```bash
81+
./hack/build-images.sh help
82+
```

hack/build-images.sh

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit
4+
set -o pipefail
5+
set -o nounset
6+
7+
script_dir=$(dirname "$(readlink -f "$0")")
8+
9+
registry="quay.io/sustainable_computing_io"
10+
11+
supported_arches=("linux/amd64" "linux/s390x" "linux/arm64")
12+
13+
function install_packages() {
14+
sudo apt install -y qemu-user-static binfmt-support build-essential
15+
}
16+
17+
function setup_docker_experimental() {
18+
mkdir -p $HOME/.docker
19+
echo '{
20+
"experimental": "enabled"
21+
}' | tee $HOME/.docker/config.json
22+
}
23+
24+
function create_builx_builder () {
25+
BUILDX_VERSION=$1 ## v0.8.2
26+
ARCH=$2 ### amd64
27+
BUILDX_BIN=buildx-${BUILDX_VERSION}.linux-${ARCH}
28+
wget https://github.com/docker/buildx/releases/download/v0.8.2/${BUILDX_BIN}
29+
chmod +x ${BUILDX_BIN}
30+
mkdir -p ~/.docker/cli-plugins
31+
mv ${BUILDX_BIN} ~/.docker/cli-plugins/docker-buildx
32+
33+
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
34+
35+
docker buildx create --name multi-arch --platform "linux/amd64,linux/s390x,linux/arm64" --use
36+
docker buildx ls
37+
docker buildx inspect --bootstrap
38+
}
39+
40+
function setup_env_for_arch() {
41+
case "$1" in
42+
"linux/amd64")
43+
kernel_arch="amd64"
44+
;;
45+
"linux/s390x")
46+
kernel_arch="s390x"
47+
;;
48+
"linux/arm64")
49+
kernel_arch="arm64"
50+
;;
51+
(*) echo "$1 is not supported" && exit 1
52+
esac
53+
}
54+
55+
function help() {
56+
echo "Usage: $0 setup"
57+
echo " $0 base"
58+
echo " $0 kepler"
59+
echo " $0 help"
60+
}
61+
62+
function setup_docker_buildx() {
63+
install_packages
64+
setup_docker_experimental
65+
create_builx_builder "v0.8.2" "amd64"
66+
}
67+
68+
function build_image_base() {
69+
image="kepler_base"
70+
pushd "${script_dir}/.."
71+
72+
tag=$(date +%Y%m%d%H%M%s)
73+
74+
for arch in ${supported_arches[@]}; do
75+
setup_env_for_arch "${arch}"
76+
77+
echo "Building ${image} image for ${arch}"
78+
docker buildx build \
79+
-f ./build/Dockerfile.base.${kernel_arch} \
80+
-t "${registry}/${image}:${kernel_arch}-${tag}" \
81+
--platform="${arch}" \
82+
--load \
83+
.
84+
docker tag "${registry}/${image}:${kernel_arch}-${tag}" "${registry}/${image}:latest-${kernel_arch}"
85+
docker push "${registry}/${image}:${kernel_arch}-${tag}"
86+
docker push "${registry}/${image}:latest-${kernel_arch}"
87+
done
88+
popd
89+
90+
create_image_manifest_base
91+
}
92+
93+
function create_image_manifest_base () {
94+
docker manifest create \
95+
${registry}/${image}:latest \
96+
${registry}/${image}:latest-amd64 \
97+
${registry}/${image}:latest-s390x \
98+
${registry}/${image}:latest-arm64
99+
100+
docker manifest push ${registry}/${image}:latest
101+
}
102+
103+
function build_image_kepler() {
104+
echo "TBD..."
105+
}
106+
107+
108+
if [ $# -eq 0 ];
109+
then
110+
help 1>&2;
111+
exit 1
112+
fi
113+
114+
115+
case "$1" in
116+
"setup")
117+
echo "setup_docker_buildx..."
118+
setup_docker_buildx
119+
;;
120+
"base")
121+
echo "build image kepler_base..."
122+
build_image_base
123+
;;
124+
"kepler")
125+
echo "build image kepler..."
126+
build_image_kepler
127+
;;
128+
"help")
129+
help;
130+
exit 0 ;;
131+
(*)
132+
help 1>&2;
133+
exit 1 ;;
134+
esac
135+

0 commit comments

Comments
 (0)