Skip to content

Commit 525ffba

Browse files
Add docker-entrypoint.sh for command configuration
1 parent 0e285fc commit 525ffba

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

docker-entrypoint.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/sh
2+
set -e
3+
4+
# Start with the command "serve"
5+
COMMAND="serve"
6+
7+
# 1. Handle Port
8+
# If PORT env var is set, append --port <val>
9+
if [ -n "$PORT" ]; then
10+
COMMAND="$COMMAND --port $PORT"
11+
fi
12+
13+
# 2. Handle Hostname
14+
# Default to 0.0.0.0 in Docker so it is accessible outside the container,
15+
# unless explicitly overridden.
16+
if [ -n "$HOSTNAME_OVERRIDE" ]; then
17+
COMMAND="$COMMAND --hostname $HOSTNAME_OVERRIDE"
18+
else
19+
COMMAND="$COMMAND --hostname 0.0.0.0"
20+
fi
21+
22+
# 3. Handle mDNS
23+
# If MDNS=true, add the flag
24+
if [ "$MDNS" = "true" ]; then
25+
COMMAND="$COMMAND --mdns"
26+
fi
27+
28+
# 4. Handle mDNS Domain
29+
if [ -n "$MDNS_DOMAIN" ]; then
30+
COMMAND="$COMMAND --mdns-domain $MDNS_DOMAIN"
31+
fi
32+
33+
# 5. Handle CORS
34+
# Docker users often set CORS as a comma-separated string (e.g., "http://a,http://b")
35+
# We split that string into multiple --cors flags.
36+
if [ -n "$CORS" ]; then
37+
# Split string by comma
38+
IFS=',' read -ra ORIGINS <<< "$CORS"
39+
for origin in "${ORIGINS[@]}"; do
40+
# Trim whitespace and append flag
41+
COMMAND="$COMMAND --cors $(echo $origin | xargs)"
42+
done
43+
fi
44+
45+
# Execute the opencode command with constructed arguments
46+
# Pass all other arguments ($@) as well to allow manual overrides
47+
exec opencode $COMMAND "$@"

0 commit comments

Comments
 (0)