-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopencode
More file actions
53 lines (47 loc) · 1.78 KB
/
Copy pathopencode
File metadata and controls
53 lines (47 loc) · 1.78 KB
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
52
53
#!/bin/bash
set -e
# Configuration
IMAGE_NAME="opencode-cli"
INSTALL_DIR="${HOME}/.local/share/opencode-cli"
CONTAINERFILE="${INSTALL_DIR}/Containerfile"
# XDG Base Directory defaults
XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}"
XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-${HOME}/.config}"
# Container internal paths
# We use /home/node as HOME, but we DO NOT mount anything under it to avoid
# Docker creating root-owned intermediate directories (like .local)
CONTAINER_HOME="/home/node"
CONTAINER_DATA="/data"
CONTAINER_CACHE="/cache"
# Ensure host directories exist
mkdir -p "${XDG_DATA_HOME}/opencode"
mkdir -p "${XDG_CACHE_HOME}/opencode"
# Check if image exists, build if missing
if ! podman image exists "${IMAGE_NAME}"; then
echo "Image '${IMAGE_NAME}' not found. Building..."
if [ -f "${CONTAINERFILE}" ]; then
podman build -t "${IMAGE_NAME}" -f "${CONTAINERFILE}" "${INSTALL_DIR}"
elif [ -f "$(dirname "$0")/Containerfile" ]; then
# Fallback for running from source/repo
podman build -t "${IMAGE_NAME}" -f "$(dirname "$0")/Containerfile" "$(dirname "$0")"
else
echo "Error: Containerfile not found. Cannot build image."
exit 1
fi
fi
# Run the container
# --userns=keep-id: Maps host user to container user
# -v $PWD:$PWD: Workdir
# -v XDG directories: Persistence (Mounted outside HOME to keep HOME clean)
# -e HOME: Set to internal container home
exec podman run -it --rm \
--userns=keep-id \
-v "$PWD":"$PWD" \
-w "$PWD" \
-v "${XDG_DATA_HOME}/opencode":"${CONTAINER_DATA}" \
-v "${XDG_CACHE_HOME}/opencode":"${CONTAINER_CACHE}" \
-e HOME="${CONTAINER_HOME}" \
-e XDG_DATA_HOME="${CONTAINER_DATA}" \
-e XDG_CACHE_HOME="${CONTAINER_CACHE}" \
"${IMAGE_NAME}" "$@"