Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/test/sanity/scripts/run-docker.sh
5241 views
1
#!/bin/sh
2
set -e
3
4
CONTAINER=""
5
ARCH="amd64"
6
MIRROR="mcr.microsoft.com/mirror/docker/library/"
7
BASE_IMAGE=""
8
PAGE_SIZE=""
9
ARGS=""
10
11
while [ $# -gt 0 ]; do
12
case "$1" in
13
--container) CONTAINER="$2"; shift 2 ;;
14
--arch) ARCH="$2"; shift 2 ;;
15
--base-image) BASE_IMAGE="$2"; shift 2 ;;
16
--page-size) PAGE_SIZE="$2"; shift 2 ;;
17
*) ARGS="$ARGS $1"; shift ;;
18
esac
19
done
20
21
if [ -z "$CONTAINER" ]; then
22
echo "Error: --container is required"
23
exit 1
24
fi
25
26
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
27
ROOT_DIR=$(cd "$SCRIPT_DIR/.." && pwd)
28
29
# Only build if image doesn't exist (i.e., not loaded from cache)
30
if ! docker image inspect "$CONTAINER" > /dev/null 2>&1; then
31
if [ "$PAGE_SIZE" != "" ]; then
32
echo "Setting up QEMU user-mode emulation for $ARCH"
33
docker run --privileged --rm tonistiigi/binfmt --install "$ARCH"
34
fi
35
36
echo "Building container image: $CONTAINER"
37
docker buildx build \
38
--platform "linux/$ARCH" \
39
--build-arg "MIRROR=$MIRROR" \
40
${BASE_IMAGE:+--build-arg "BASE_IMAGE=$BASE_IMAGE"} \
41
--tag "$CONTAINER" \
42
--file "$ROOT_DIR/containers/$CONTAINER.dockerfile" \
43
"$ROOT_DIR/containers"
44
else
45
echo "Using cached container image: $CONTAINER"
46
fi
47
48
# For 64K page size, use QEMU system emulation with a 64K kernel
49
if [ "$PAGE_SIZE" = "64k" ]; then
50
exec "$SCRIPT_DIR/run-qemu-64k.sh" \
51
--container "$CONTAINER" \
52
-- $ARGS
53
else
54
echo "Running sanity tests in container"
55
docker run \
56
--rm \
57
--platform "linux/$ARCH" \
58
--volume "$ROOT_DIR:/root" \
59
--entrypoint sh \
60
"$CONTAINER" \
61
/root/containers/entrypoint.sh $ARGS
62
fi
63
64