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:
parent
eea524f6bb
commit
320f54e205
|
@ -11,7 +11,10 @@
|
||||||
"skipFiles": ["<node_internals>/**"],
|
"skipFiles": ["<node_internals>/**"],
|
||||||
"type": "node",
|
"type": "node",
|
||||||
// fix source mapping when debugging in sandbox
|
// fix source mapping when debugging in sandbox
|
||||||
"remoteRoot": "/usr/local/share/npm-global/lib/node_modules/@gemini-code",
|
// we assume debugging is done on gemini-code project itself (see CLI_PATH setup in start_sandbox.sh)
|
||||||
|
// there seems to be no way to map two distinct remoteRoots to same localRoot under same configuration
|
||||||
|
// "remoteRoot": "/usr/local/share/npm-global/lib/node_modules/@gemini-code",
|
||||||
|
"remoteRoot": "/sandbox/gemini-code/packages",
|
||||||
"localRoot": "${workspaceFolder}/packages"
|
"localRoot": "${workspaceFolder}/packages"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
FROM docker.io/library/node:20-slim
|
||||||
|
|
||||||
|
# install minimal set of packages, then clean up
|
||||||
|
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
|
man-db \
|
||||||
|
curl \
|
||||||
|
dnsutils \
|
||||||
|
less \
|
||||||
|
jq \
|
||||||
|
bc \
|
||||||
|
gh \
|
||||||
|
git \
|
||||||
|
unzip \
|
||||||
|
rsync \
|
||||||
|
ripgrep \
|
||||||
|
procps \
|
||||||
|
psmisc \
|
||||||
|
lsof \
|
||||||
|
&& apt-get clean \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
# set up npm global package folder under /usr/local/share
|
||||||
|
# give it to non-root user node, already set up in base image
|
||||||
|
RUN mkdir -p /usr/local/share/npm-global \
|
||||||
|
&& chown -R node:node /usr/local/share/npm-global
|
||||||
|
ENV NPM_CONFIG_PREFIX=/usr/local/share/npm-global
|
||||||
|
ENV PATH=$PATH:/usr/local/share/npm-global/bin
|
||||||
|
|
||||||
|
# switch to non-root user node
|
||||||
|
USER node
|
||||||
|
|
|
@ -25,6 +25,7 @@ npm run build --workspaces
|
||||||
|
|
||||||
# also build container image if sandboxing is enabled
|
# also build container image if sandboxing is enabled
|
||||||
# skip (-s) npm install + build since we did that above
|
# skip (-s) npm install + build since we did that above
|
||||||
|
# use (-d) for dev build that can reuse existing image
|
||||||
if scripts/sandbox_command.sh -q; then
|
if scripts/sandbox_command.sh -q; then
|
||||||
scripts/build_sandbox.sh -s
|
scripts/build_sandbox.sh -sd
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -24,16 +24,19 @@ CMD=$(scripts/sandbox_command.sh)
|
||||||
echo "using $CMD for sandboxing"
|
echo "using $CMD for sandboxing"
|
||||||
|
|
||||||
IMAGE=gemini-code-sandbox
|
IMAGE=gemini-code-sandbox
|
||||||
|
DOCKERFILE=${DOCKERFILE:-Dockerfile}
|
||||||
|
|
||||||
SKIP_NPM_INSTALL_BUILD=false
|
SKIP_NPM_INSTALL_BUILD=false
|
||||||
while getopts "s" opt; do
|
while getopts "sd" opt; do
|
||||||
case ${opt} in
|
case ${opt} in
|
||||||
s) SKIP_NPM_INSTALL_BUILD=true ;;
|
s) SKIP_NPM_INSTALL_BUILD=true ;;
|
||||||
\?)
|
d) DOCKERFILE=Dockerfile-dev ;;
|
||||||
echo "usage: $(basename "$0") [-s]"
|
\?)
|
||||||
echo " -s: skip npm install + npm run build"
|
echo "usage: $(basename "$0") [-s] [-d]"
|
||||||
exit 1
|
echo " -s: skip npm install + npm run build"
|
||||||
;;
|
echo " -d: use Dockerfile-dev"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
shift $((OPTIND - 1))
|
shift $((OPTIND - 1))
|
||||||
|
@ -44,30 +47,40 @@ if [ "$SKIP_NPM_INSTALL_BUILD" = false ]; then
|
||||||
npm run build
|
npm run build
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# pack cli
|
# if using Dockerfile-dev, then skip rebuild unless REBUILD_SANDBOX is set
|
||||||
echo "packing @gemini-code/cli ..."
|
# rebuild should not be necessary unless Dockerfile-dev is modified
|
||||||
rm -f packages/cli/dist/gemini-code-cli-*.tgz
|
if [ "$DOCKERFILE" = "Dockerfile-dev" ]; then
|
||||||
npm pack -w @gemini-code/cli --pack-destination ./packages/cli/dist &> /dev/null
|
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
|
# prepare global installation files for prod build
|
||||||
echo "packing @gemini-code/server ..."
|
if [ "$DOCKERFILE" = "Dockerfile" ]; then
|
||||||
rm -f packages/server/dist/gemini-code-server-*.tgz
|
# pack cli
|
||||||
npm pack -w @gemini-code/server --pack-destination ./packages/server/dist &> /dev/null
|
echo "packing @gemini-code/cli ..."
|
||||||
|
rm -f packages/cli/dist/gemini-code-cli-*.tgz
|
||||||
# give node user access to tgz files
|
npm pack -w @gemini-code/cli --pack-destination ./packages/cli/dist &>/dev/null
|
||||||
chmod 755 packages/*/dist/gemini-code-*.tgz
|
# 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
|
# build container image & prune older unused images
|
||||||
echo "building $IMAGE ... (can be slow first time)"
|
echo "building $IMAGE ... (can be slow first time)"
|
||||||
|
|
||||||
if [[ "$CMD" == "podman" ]]; then
|
if [[ "$CMD" == "podman" ]]; then
|
||||||
# use empty --authfile to skip unnecessary auth refresh overhead
|
# 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
|
elif [[ "$CMD" == "docker" ]]; then
|
||||||
# use an empty config directory to skip unnecessary auth refresh overhead
|
# 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
|
else
|
||||||
$CMD build -t "$IMAGE" . >/dev/null
|
$CMD build -f "$DOCKERFILE" -t "$IMAGE" . >/dev/null
|
||||||
fi
|
fi
|
||||||
$CMD image prune -f >/dev/null
|
$CMD image prune -f >/dev/null
|
||||||
echo "built $IMAGE"
|
echo "built $IMAGE"
|
||||||
|
|
|
@ -22,10 +22,23 @@ fi
|
||||||
|
|
||||||
CMD=$(scripts/sandbox_command.sh)
|
CMD=$(scripts/sandbox_command.sh)
|
||||||
IMAGE=gemini-code-sandbox
|
IMAGE=gemini-code-sandbox
|
||||||
WORKDIR=/sandbox/$(basename "$PWD")
|
|
||||||
CLI_PATH=/usr/local/share/npm-global/lib/node_modules/\@gemini-code/cli
|
|
||||||
DEBUG_PORT=9229
|
DEBUG_PORT=9229
|
||||||
|
|
||||||
|
PROJECT=$(basename "$PWD")
|
||||||
|
WORKDIR=/sandbox/$PROJECT
|
||||||
|
CLI_PATH=/usr/local/share/npm-global/lib/node_modules/\@gemini-code/cli
|
||||||
|
|
||||||
|
# if project is gemini-code, then run CLI from $WORKDIR/packages/cli
|
||||||
|
# note this means the global installation is not required in this case
|
||||||
|
if [[ "$PROJECT" == "gemini-code" ]]; then
|
||||||
|
CLI_PATH="$WORKDIR/packages/cli"
|
||||||
|
elif [ -n "${DEBUG:-}" ]; then
|
||||||
|
# refuse to debug using global installation
|
||||||
|
# (requires a separate attach config in launch.json, see comments there around remoteRoot)
|
||||||
|
echo "ERROR: debugging is sandbox is not supported when target/root is not gemini-code"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# use interactive tty mode and auto-remove container on exit
|
# use interactive tty mode and auto-remove container on exit
|
||||||
run_args=(-it --rm)
|
run_args=(-it --rm)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue