summaryrefslogtreecommitdiff
path: root/scripts/build_sandbox.sh
blob: a34679e942b828b1fe15b0f464c4641c13c1c427 (plain)
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
#!/bin/bash
set -euo pipefail

IMAGE=gemini-code-sandbox

SKIP_NPM_INSTALL_BUILD=false
while getopts "s" opt; do
    case ${opt} in
        s) SKIP_NPM_INSTALL_BUILD=true ;;
        \?)
            echo "usage: $(basename "$0") [-s]"
            echo "  -s: skip npm install + npm run build"
            exit 1
            ;;
    esac
done
shift $((OPTIND - 1))

# use docker if installed, otherwise try to use podman instead
if command -v docker &> /dev/null; then
    CMD=docker
elif command -v podman &> /dev/null; then
    CMD=podman
else
    echo "ERROR: missing docker or podman for sandboxing"
    exit 1
fi
echo "using $CMD for sandboxing"

# npm install + npm run build unless skipping via -s option
if [ "$SKIP_NPM_INSTALL_BUILD" = false ]; then
    npm install
    npm run build
fi

# pack cli
echo "packing @gemini-code/cli ..."
rm -f packages/cli/dist/gemini-code-cli-*.tgz
npm pack -w @gemini-code/cli --pack-destination ./packages/cli/dist &> /dev/null

# pack server
echo "packing @gemini-code/server ..."
rm -f packages/server/dist/gemini-code-server-*.tgz
npm pack -w @gemini-code/server --pack-destination ./packages/server/dist &> /dev/null

# build container image & prune older unused images
# use empty --authfile to skip unnecessary auth refresh overhead
echo "building $IMAGE ... (can be slow first time)"
$CMD build --authfile <(echo '{}') -t "$IMAGE" . >/dev/null
$CMD image prune -f
echo "built $IMAGE"