mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-21 01:07:46 +00:00
instant (dev) sandbox (#171)
* instant (dev) sandbox * leave Dockerfile as is to pass deploy test * fix comma * fix prod build * do not use "images exists" which docker does not support * separate dev-mode flag * Merge remote-tracking branch 'origin/main' into instant_sandbox
This commit is contained in:
@@ -24,16 +24,19 @@ CMD=$(scripts/sandbox_command.sh)
|
||||
echo "using $CMD for sandboxing"
|
||||
|
||||
IMAGE=gemini-code-sandbox
|
||||
DOCKERFILE=${DOCKERFILE:-Dockerfile}
|
||||
|
||||
SKIP_NPM_INSTALL_BUILD=false
|
||||
while getopts "s" opt; do
|
||||
while getopts "sd" 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
|
||||
;;
|
||||
s) SKIP_NPM_INSTALL_BUILD=true ;;
|
||||
d) DOCKERFILE=Dockerfile-dev ;;
|
||||
\?)
|
||||
echo "usage: $(basename "$0") [-s] [-d]"
|
||||
echo " -s: skip npm install + npm run build"
|
||||
echo " -d: use Dockerfile-dev"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
shift $((OPTIND - 1))
|
||||
@@ -44,30 +47,40 @@ if [ "$SKIP_NPM_INSTALL_BUILD" = false ]; then
|
||||
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
|
||||
# if using Dockerfile-dev, then skip rebuild unless REBUILD_SANDBOX is set
|
||||
# rebuild should not be necessary unless Dockerfile-dev is modified
|
||||
if [ "$DOCKERFILE" = "Dockerfile-dev" ]; then
|
||||
if $CMD images -q "$IMAGE" | grep -q . && [ -z "${REBUILD_SANDBOX:-}" ]; then
|
||||
echo "using existing $IMAGE (set REBUILD_SANDBOX=true to force rebuild)"
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
# 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
|
||||
|
||||
# give node user access to tgz files
|
||||
chmod 755 packages/*/dist/gemini-code-*.tgz
|
||||
# prepare global installation files for prod build
|
||||
if [ "$DOCKERFILE" = "Dockerfile" ]; then
|
||||
# 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
|
||||
# give node user (used during installation, see Dockerfile) access to these files
|
||||
chmod 755 packages/*/dist/gemini-code-*.tgz
|
||||
fi
|
||||
|
||||
# build container image & prune older unused images
|
||||
echo "building $IMAGE ... (can be slow first time)"
|
||||
|
||||
if [[ "$CMD" == "podman" ]]; then
|
||||
# use empty --authfile to skip unnecessary auth refresh overhead
|
||||
$CMD build --authfile=<(echo '{}') -t "$IMAGE" . >/dev/null
|
||||
$CMD build --authfile=<(echo '{}') -f "$DOCKERFILE" -t "$IMAGE" . >/dev/null
|
||||
elif [[ "$CMD" == "docker" ]]; then
|
||||
# use an empty config directory to skip unnecessary auth refresh overhead
|
||||
$CMD --config="empty" build -t "$IMAGE" . >/dev/null
|
||||
$CMD --config="empty" build -f "$DOCKERFILE" -t "$IMAGE" . >/dev/null
|
||||
else
|
||||
$CMD build -t "$IMAGE" . >/dev/null
|
||||
$CMD build -f "$DOCKERFILE" -t "$IMAGE" . >/dev/null
|
||||
fi
|
||||
$CMD image prune -f >/dev/null
|
||||
echo "built $IMAGE"
|
||||
|
||||
Reference in New Issue
Block a user