feat: various modifications
- Default ubuntu user is removed - Can add apt packages during image building with --apt-packages="list of pkg" - Remove and/or prune podman image option - Fix condition checks
This commit is contained in:
@@ -0,0 +1,100 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR=$(realpath -- "$(dirname -- "${BASH_SOURCE[0]}")")
|
||||
|
||||
IMAGE_REPO="${IMAGE_REPO:-localhost/opencode-dev}"
|
||||
IMAGE="${IMAGE_REPO}"
|
||||
|
||||
if ! podman image exists "$IMAGE"; then
|
||||
echo "Image $IMAGE does not exist. Build it first with ./build.sh" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Folders
|
||||
BASE_DIR="${OPENCODE_DEV_HOME:-$HOME/opencode-dev}"
|
||||
PROJECTS_DIR="${PROJECT_DIR:-$BASE_DIR/projects}"
|
||||
OPC_CONFIG="${OPENCODE_CONFIG:-$BASE_DIR/opencode-config}"
|
||||
OPC_DATA="${OPENCODE_SHARE_DATA:-$BASE_DIR/opencode-data}"
|
||||
OPC_CACHE="${OPENCODE_CACHE:-$BASE_DIR/opencode-cache}"
|
||||
M2_FOLDER="${M2_FOLDER:-$BASE_DIR/m2}"
|
||||
NPM_MODULES="${NPM_MODULES:-$BASE_DIR/npm-modules}"
|
||||
NPM_CACHE="${NPM_CACHE:-$BASE_DIR/npm-cache}"
|
||||
PIP_CACHE="${PIP_CACHE:-$BASE_DIR/pip-cache}"
|
||||
|
||||
if [[ ! -d "$PROJECTS_DIR" ]]; then
|
||||
echo "Project directory missing: $PROJECTS_DIR" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p \
|
||||
"$BASE_DIR" \
|
||||
"$PROJECTS_DIR" \
|
||||
"$OPC_CONFIG" \
|
||||
"$OPC_DATA" \
|
||||
"$OPC_CACHE" \
|
||||
"$M2_FOLDER" \
|
||||
"$NPM_MODULES" \
|
||||
"$NPM_CACHE" \
|
||||
"$PIP_CACHE"
|
||||
|
||||
START_DIR="${1:-$PROJECTS_DIR}"
|
||||
shift || true
|
||||
|
||||
if [[ "$START_DIR" = /* ]]; then
|
||||
if [[ "$START_DIR" == "$PROJECTS_DIR"* ]]; then
|
||||
REL="${START_DIR#"$PROJECTS_DIR"}"
|
||||
START_DIR="/workspace${REL}"
|
||||
else
|
||||
echo "Absolute paths outside $PROJECTS_DIR require --mount and are not accepted as the initial directory." >&2
|
||||
exit 2
|
||||
fi
|
||||
else
|
||||
START_DIR="/workspace/${START_DIR#./}"
|
||||
fi
|
||||
|
||||
ARGS=(
|
||||
run --rm -it
|
||||
--name opencode-dev
|
||||
--user dev
|
||||
--userns=keep-id
|
||||
--network=default
|
||||
--tz=local
|
||||
|
||||
--security-opt=no-new-privileges
|
||||
--cap-drop=ALL
|
||||
|
||||
-e "START_DIR=${START_DIR}"
|
||||
|
||||
-v "$OPC_CONFIG:/home/dev/.config/opencode:rw"
|
||||
-v "$OPC_DATA:/home/dev/.local/share/opencode:rw"
|
||||
-v "$OPC_CACHE:/home/dev/.cache/opencode:rw"
|
||||
-v "$M2_FOLDER:/home/dev/.m2:rw"
|
||||
-v "$NPM_CACHE:/home/dev/.npm:rw"
|
||||
-v "$PIP_CACHE:/home/dev/.cache/pip:rw"
|
||||
-v "$PROJECTS_DIR:/workspace:rw"
|
||||
)
|
||||
|
||||
if [[ -f "$HOME/.gitconfig" ]]; then
|
||||
ARGS+=(-v "$HOME/.gitconfig:/home/dev/.gitconfig:ro")
|
||||
else
|
||||
echo "WARNING: host .gitconfig not found, using container inner configuration"
|
||||
fi
|
||||
|
||||
# Additional bind mounts:
|
||||
# ./dev.sh --mount "$HOME/other:/extra"
|
||||
while (($#)); do
|
||||
case "$1" in
|
||||
--mount)
|
||||
[[ $# -ge 2 ]] || { echo "--mount requires host:container[:ro|rw]" >&2; exit 2; }
|
||||
ARGS+=(-v "$2")
|
||||
shift 2
|
||||
;;
|
||||
*)
|
||||
echo "Unknown option: $1" >&2
|
||||
exit 2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
exec podman "${ARGS[@]}" "$IMAGE" bash
|
||||
Reference in New Issue
Block a user