mirror of
https://github.com/jasonxu114514/opencode2api.git
synced 2026-12-06 00:03:11 +00:00
feat: publish container images to GHCR
This commit is contained in:
1 parent
cc71ba8aff
commit
948ef0be11
6 files changed
+222
-103
No files matched your search
+24
-46
@@ -1,57 +1,35 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
app_dir=${APP_DIR:-/app}
|
||||
state_dir=${STATE_DIR:-/var/lib/opencode2api}
|
||||
config_path=${CONFIG_PATH:-$app_dir/config.json}
|
||||
config_path=${CONFIG_PATH:-$state_dir/config.json}
|
||||
config_seed_path=${CONFIG_SEED_PATH:-}
|
||||
listen_address=${LISTEN_ADDRESS:-0.0.0.0:8080}
|
||||
webui_listen_address=${WEBUI_LISTEN_ADDRESS:-0.0.0.0:8081}
|
||||
binary_path=$state_dir/opencode2api
|
||||
fingerprint_path=$state_dir/source.sha256
|
||||
|
||||
mkdir -p "$state_dir"
|
||||
if [ "$(id -u)" = "0" ]; then
|
||||
mkdir -p "$state_dir"
|
||||
chown opencode2api:opencode2api "$state_dir"
|
||||
exec su-exec opencode2api:opencode2api "$0" "$@"
|
||||
fi
|
||||
|
||||
if [ -f "$config_path" ]; then
|
||||
active_config=$config_path
|
||||
else
|
||||
generated_config=$state_dir/config.json
|
||||
if [ ! -f "$generated_config" ]; then
|
||||
cp "$app_dir/config.example.json" "$generated_config"
|
||||
if [ "$#" -gt 0 ]; then
|
||||
exec "$@"
|
||||
fi
|
||||
|
||||
if [ ! -f "$config_path" ]; then
|
||||
mkdir -p "$(dirname "$config_path")"
|
||||
if [ -n "$config_seed_path" ] && [ -f "$config_seed_path" ]; then
|
||||
cp "$config_seed_path" "$config_path"
|
||||
printf '%s\n' "Initialized $config_path from $config_seed_path."
|
||||
else
|
||||
cp /app/config.example.json "$config_path"
|
||||
printf '%s\n' \
|
||||
"config.json not found; created $config_path. Set API keys or enable anonymous mode, and change the WebUI password before use."
|
||||
fi
|
||||
active_config=$generated_config
|
||||
printf '%s\n' "config.json not found; using a persistent generated copy. Set real API keys or enable anonymous mode, and change the WebUI password before use."
|
||||
fi
|
||||
|
||||
source_fingerprint() {
|
||||
{
|
||||
go version
|
||||
go env GOOS GOARCH CGO_ENABLED
|
||||
find "$app_dir" \
|
||||
-path "$app_dir/.git" -prune -o \
|
||||
-type f \( -name '*.go' -o -name 'go.mod' -o -name 'go.sum' -o -path "$app_dir/webui/*" \) -print \
|
||||
| LC_ALL=C sort \
|
||||
| while IFS= read -r source_file; do
|
||||
sha256sum "$source_file"
|
||||
done
|
||||
} | sha256sum | awk '{print $1}'
|
||||
}
|
||||
|
||||
current_fingerprint=$(source_fingerprint)
|
||||
stored_fingerprint=""
|
||||
if [ -f "$fingerprint_path" ]; then
|
||||
stored_fingerprint=$(cat "$fingerprint_path")
|
||||
fi
|
||||
|
||||
if [ ! -x "$binary_path" ] || [ "$current_fingerprint" != "$stored_fingerprint" ]; then
|
||||
printf '%s\n' "Source changed or no cached binary exists; building opencode2api..."
|
||||
temporary_binary=$state_dir/opencode2api.new
|
||||
cd "$app_dir"
|
||||
go build -trimpath -o "$temporary_binary" ./
|
||||
mv "$temporary_binary" "$binary_path"
|
||||
printf '%s\n' "$current_fingerprint" > "$fingerprint_path"
|
||||
printf '%s\n' "Build completed and cached in the persistent Docker volume."
|
||||
else
|
||||
printf '%s\n' "Source is unchanged; starting the cached opencode2api binary."
|
||||
fi
|
||||
|
||||
exec "$binary_path" -config "$active_config" -listen "$listen_address" -web-listen "$webui_listen_address"
|
||||
exec /usr/local/bin/opencode2api \
|
||||
-config "$config_path" \
|
||||
-listen "$listen_address" \
|
||||
-web-listen "$webui_listen_address"
|
||||
Reference in new issue
Block a user