This repository has been archived by the owner on Nov 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreate-images.sh
executable file
·50 lines (46 loc) · 2.03 KB
/
create-images.sh
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
#!/bin/bash
set -euo pipefail
SOURCE=./src/
DEST=./out/
WASI_MAX_CHUNK=50MB
C2W=c2w
C2W_EXTRA_FLAGS_V=${C2W_EXTRA_FLAGS:-}
# /image : image name
# /Dockerfile : dockerfile to use
# /target : target compiler (wasi, emscripten, default: wasi)
# /arch : image architecture (default: amd64)
for I in $(ls -1 ${SOURCE}) ;
do
OUTPUT_NAME="${I}-container"
if [ $(cat "${SOURCE}/${I}/target" || true) == "emscripten" ] ; then
TARGETARCH=$(cat "${SOURCE}/${I}/arch" || true)
if [ "${TARGETARCH}" == "" ] ; then
TARGETARCH="amd64"
fi
if [ -f "${SOURCE}/${I}/image" ]; then
${C2W} --to-js --target-arch="${TARGETARCH}" ${C2W_EXTRA_FLAGS_V} --build-arg JS_OUTPUT_NAME=${OUTPUT_NAME} "$(cat ${SOURCE}/${I}/image)" "${DEST}"
elif [ -f "${SOURCE}/${I}/Dockerfile" ]; then
cat ${SOURCE}/${I}/Dockerfile | docker buildx build --progress=plain -t ${I} --platform="linux/${TARGETARCH}" --load -
${C2W} --to-js --target-arch="${TARGETARCH}" ${C2W_EXTRA_FLAGS_V} --build-arg JS_OUTPUT_NAME=${OUTPUT_NAME} "${I}" "${DEST}"
else
echo "no image source found for ${I}"
exit 1
fi
else
TARGETARCH=$(cat "${SOURCE}/${I}/arch" || true)
if [ "${TARGETARCH}" == "" ] ; then
TARGETARCH="amd64"
fi
if [ -f "${SOURCE}/${I}/image" ]; then
${C2W} --target-arch="${TARGETARCH}" ${C2W_EXTRA_FLAGS_V} "$(cat ${SOURCE}/${I}/image)" "${DEST}/${OUTPUT_NAME}.wasm"
elif [ -f "${SOURCE}/${I}/Dockerfile" ]; then
cat ${SOURCE}/${I}/Dockerfile | docker buildx build --progress=plain -t ${I} --platform="linux/${TARGETARCH}" --load -
${C2W} --target-arch="${TARGETARCH}" ${C2W_EXTRA_FLAGS_V} "${I}" "${DEST}/${OUTPUT_NAME}.wasm"
else
echo "no image source found for ${I}"
exit 1
fi
split -d -b "${WASI_MAX_CHUNK}" --additional-suffix=.wasm "${DEST}/${OUTPUT_NAME}.wasm" "${DEST}/${OUTPUT_NAME}"
rm "${DEST}/${OUTPUT_NAME}.wasm"
fi
done