-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-opencode-docker.sh
More file actions
executable file
·70 lines (61 loc) · 2.56 KB
/
build-opencode-docker.sh
File metadata and controls
executable file
·70 lines (61 loc) · 2.56 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
#!/bin/bash # Shebang: specify interpreter (Bash)
# Configuration
# Image name used for both building and running containers
IMAGE_NAME="arch-opencode-base"
# Path to Dockerfile
# This points to Dockerfile in the same directory as this script
# If your Dockerfile is elsewhere, update path accordingly (e.g., "$HOME/path/to/Dockerfile")
DOCKERFILE="$(dirname "$0")/Dockerfile"
# Path to local OpenCode auth file
# Currently unused - reserved for future authentication purposes
LOCAL_AUTH_FILE="$HOME/.local/share/opencode/auth.json"
# Function to handle building the Docker image
# - Validates GH_TOKEN is set (required for some build steps)
# - Runs docker build with error checking
# - Returns non-zero exit code on failure
build_image() {
echo "🔨 Building image from $DOCKERFILE..."
# Check if GH_TOKEN environment variable is set and non-empty
# -z: Test if string is empty
# This is required for GitHub CLI operations during build
if [ -z "$GH_TOKEN" ]; then
echo "❌ Error: GH_TOKEN is not set. Cannot build."
echo " Set with: export GH_TOKEN=your_github_token"
exit 1
fi
# Build Docker image
# -t: Tag the image with IMAGE_NAME
# -f: Specify Dockerfile path
# .: Use current directory as build context
docker build -t $IMAGE_NAME -f $DOCKERFILE .
# Check exit status of previous command
# $?: Exit code of last command (0 = success)
if [ $? -ne 0 ]; then
echo "❌ Docker build failed. Exiting."
exit 1
fi
echo "✅ Build successful."
}
# ---------------------------------------------------------
# 0. Check for "rebuild" parameter
# ---------------------------------------------------------
# Usage: ./build-opencode-docker.sh rebuild
# Forces a rebuild even if image already exists
# [ "$1" == "rebuild" ]: Check first command-line argument
if [ "$1" == "rebuild" ]; then
echo "Force rebuild requested..."
build_image
exit 0 # Exit after rebuild (don't continue to auto-build check)
fi
# ---------------------------------------------------------
# 1. Auto-Build Image (if missing)
# ---------------------------------------------------------
# Check if image exists locally
# docker images -q: Quiet mode, only show image IDs
# 2> /dev/null: Redirect stderr to null (suppress warnings)
# [[ ... == "" ]]: Test if output is empty (image not found)
if [[ "$(docker images -q $IMAGE_NAME 2> /dev/null)" == "" ]]; then
echo "⚠️ Image '$IMAGE_NAME' not found locally."
build_image # Build image if not found
fi
# If image exists, script exits silently (no action needed)