-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·70 lines (62 loc) · 2.36 KB
/
Copy pathrun.sh
File metadata and controls
executable file
·70 lines (62 loc) · 2.36 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env bash
### VARIABLES
UID="${UID:-$(id -u)}"
GID="${GID:-$(id -g)}"
PORT="${OPENCODE_PORT:-4096}"
PROJECT_PATH="${PROJECT_PATH:-$(pwd)}"
CONTAINER_NAME="opencoded"
OC_AUTH_PATH="$HOME/.local/share/opencode/auth.json"
set -e
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m'
echo -e "${BLUE}Setting up OpenCode Docker environment...${NC}"
mkdir -p ~/.config/opencode
mkdir -p ~/.local/share/opencode
mkdir -p ~/.ssh
echo -e "${GREEN}Directories created.${NC}"
if [ ! -f "$OC_AUTH_PATH" ]; then
echo -e "${YELLOW}Creating empty auth.json...${NC}"
echo '{}' >"$OC_AUTH_PATH"
echo -e "${GREEN}auth.json created at $OC_AUTH_PATH${NC}"
else
echo -e "${GREEN}auth.json already exists.${NC}"
fi
if [ ! -f "$HOME/.ssh/id_ed25519" ]; then
echo -e "${YELLOW}WARNING: ~/.ssh/id_ed25519 not found. Git operations may not work.${NC}"
echo -e "Generate one with:"
echo -e "${CYAN}ssh-keygen -t ed25519 -C 'your@email.com'${NC}"
fi
if docker ps -a --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}$"; then
echo ""
echo -e "${YELLOW}Container '${CONTAINER_NAME}' already exists.${NC}"
echo -e "Stopping and removing existing container..."
docker stop "$CONTAINER_NAME" >/dev/null 2>&1 || true
docker rm "$CONTAINER_NAME" >/dev/null 2>&1 || true
echo -e "${GREEN}Existing container removed.${NC}"
fi
echo ""
echo -e "${BLUE}Project path: ${PROJECT_PATH}${NC}"
echo -e "${BLUE}Starting OpenCode container on port $PORT...${NC}"
docker run -d \
--name "$CONTAINER_NAME" \
--rm \
--user "${UID}:${GID}" \
-p "${PORT}:4096" \
-v "${PROJECT_PATH}:/workspace" \
-v "$HOME/.ssh/id_ed25519:/home/opencoded/.ssh/id_ed25519:ro" \
-v "$HOME/.config/opencode:/home/opencoded/.config/opencode" \
-v "$HOME/.local/share/opencode/auth.json:/home/opencoded/.local/share/opencode/auth.json" \
-e "GH_TOKEN=${GH_TOKEN:-}" \
-e "OPENCODE_SERVER_USERNAME=${OPENCODE_SERVER_USERNAME:-opencode}" \
-e "OPENCODE_SERVER_PASSWORD=${OPENCODE_SERVER_PASSWORD:-}" \
ghcr.io/brockar/opencoded:latest web --hostname 0.0.0.0 --port 4096
echo ""
echo -e "${GREEN}OpenCode is starting!${NC}"
echo -e "Access the web interface at: ${CYAN}http://localhost:$PORT${NC}"
echo ""
echo -e "${BLUE}Useful commands:${NC}"
echo -e " ${CYAN}docker logs -f $CONTAINER_NAME${NC} - View logs"
echo -e " ${CYAN}docker stop $CONTAINER_NAME${NC} - Stop container"