Skip to content

Commit f7fa46a

Browse files
author
GitHub Copilot CLI
committed
fix(review): harden env parsing and align startup diagnostics
1 parent 282ade4 commit f7fa46a

6 files changed

Lines changed: 30 additions & 25 deletions

File tree

.devcontainer/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ RUN --mount=type=cache,target=/tmp/npm-cache \
5151
# 並列処理完了待ち
5252
wait && \
5353
# ECC ajv依存関係修正(既知の問題対応)
54-
ECC_DIR=$(npm list -g ecc-universal 2>/dev/null | head -n1 | awk '{print $1}')/node_modules/ecc-universal && \
54+
ECC_DIR="$(npm root -g 2>/dev/null)/ecc-universal" && \
5555
if [ -d "$ECC_DIR" ]; then \
5656
cd "$ECC_DIR" && npm install ajv 2>/dev/null || true; \
5757
fi && \

.devcontainer/entrypoint.sh

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,8 @@
22

33
echo "🔧 OpenCode ECC DevContainer エントリーポイント"
44

5-
is_valid_tailscale_key() {
6-
local key
7-
key=$(echo "$1" | tr -d '"' | tr -d '[:space:]')
8-
[[ "$key" =~ ^tskey-auth- ]] || return 1
9-
[[ "$key" == "your-tailscale-auth-key-here" ]] && return 1
10-
[[ "$key" == "tskey-auth-xxxxxxxxxxxxxxxxx" ]] && return 1
11-
[[ "$key" =~ ^tskey-auth-[xX]+$ ]] && return 1
12-
return 0
13-
}
14-
15-
# Tailscale daemon 起動
16-
if is_valid_tailscale_key "$TAILSCALE_AUTH_KEY"; then
17-
echo "🌐 Tailscale daemon 起動中..."
18-
sudo tailscaled --statedir=/var/lib/tailscale --socket=/run/tailscale/tailscaled.sock &
19-
fi
5+
# tailscaled startup is centrally handled by .devcontainer/startup.sh
6+
# to keep daemon flags and lifecycle behavior consistent.
207

218
# メインプロセス実行
229
exec "$@"

.devcontainer/lib/common.sh

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,29 @@ resolve_env_template_file() {
5353
load_env_file() {
5454
local env_file="$1"
5555
[[ -f "$env_file" ]] || return 1
56-
# shellcheck disable=SC1090
57-
set -a
58-
source "$env_file" 2>/dev/null || true
59-
set +a
56+
57+
# Parse KEY=VALUE lines only to avoid executing arbitrary shell code.
58+
local line key value
59+
while IFS= read -r line || [[ -n "$line" ]]; do
60+
line="${line%$'\r'}"
61+
[[ -z "${line//[[:space:]]/}" ]] && continue
62+
[[ "$line" =~ ^[[:space:]]*# ]] && continue
63+
64+
if [[ "$line" =~ ^[[:space:]]*([A-Za-z_][A-Za-z0-9_]*)[[:space:]]*=(.*)$ ]]; then
65+
key="${BASH_REMATCH[1]}"
66+
value="${BASH_REMATCH[2]}"
67+
value=$(echo "$value" | sed -E 's/^[[:space:]]+|[[:space:]]+$//g')
68+
69+
if [[ "$value" =~ ^\"(.*)\"$ ]]; then
70+
value="${BASH_REMATCH[1]}"
71+
elif [[ "$value" =~ ^\'(.*)\'$ ]]; then
72+
value="${BASH_REMATCH[1]}"
73+
fi
74+
75+
export "$key=$value"
76+
fi
77+
done < "$env_file"
78+
6079
return 0
6180
}
6281

.devcontainer/setup.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ chmod -R 755 ~/.opencode 2>/dev/null || true
8585

8686
# ajv 依存関係エラー修正(既知の問題)
8787
echo " 🔧 ajv 依存関係修正中..."
88-
ECC_PATH=$(npm list -g ecc-universal 2>/dev/null | head -n1 | awk '{print $1}' || echo "")
89-
if [[ -n "$ECC_PATH" ]] && [[ -d "$ECC_PATH/node_modules/ecc-universal" ]]; then
90-
cd "$ECC_PATH/node_modules/ecc-universal"
88+
ECC_DIR="$(npm root -g 2>/dev/null)/ecc-universal"
89+
if [[ -d "$ECC_DIR" ]]; then
90+
cd "$ECC_DIR"
9191
echo " ECCディレクトリ: $(pwd)"
9292
npm install ajv 2>/dev/null || echo " ajv インストール試行"
9393
cd - > /dev/null

.devcontainer/validate-setup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ if [[ -f "/workspace/.env" ]]; then
5757
if [[ -n "$TAILSCALE_AUTH_KEY" && "$TAILSCALE_AUTH_KEY" != "your-tailscale-auth-key-here" && "$TAILSCALE_AUTH_KEY" != "tskey-auth-xxxxxxxxxxxxxxxxx" ]]; then
5858
run_test "TAILSCALE_AUTH_KEY 設定確認" "test -n '$TAILSCALE_AUTH_KEY'"
5959
else
60-
echo -e "${YELLOW}🔍 [${TESTS_TOTAL}+1] TAILSCALE_AUTH_KEY 設定確認 (オプション)${NC}"
60+
echo -e "${YELLOW}🔍 [$((TESTS_TOTAL+1))] TAILSCALE_AUTH_KEY 設定確認 (オプション)${NC}"
6161
echo -e "${YELLOW} ⚠️ SKIP(ローカルモード許容)${NC}"
6262
fi
6363
run_test "ECC_PROFILE 設定確認" "test -n '$ECC_PROFILE'"

scripts/diagnose-devcontainer.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ if [ -f ".env" ]; then
6262

6363
if [ -n "$TAILSCALE_AUTH_KEY" ] && [ "$TAILSCALE_AUTH_KEY" != "your-auth-key-here" ] && [ "$TAILSCALE_AUTH_KEY" != "tskey-auth-xxxxxxxxxxxxxxxxx" ]; then
6464
echo " ✅ TAILSCALE_AUTH_KEY 設定済み"
65-
echo " キー: ${TAILSCALE_AUTH_KEY:0:15}..."
6665
else
6766
echo " ⚠️ TAILSCALE_AUTH_KEY 未設定またはテンプレート値"
6867
echo " 設定コマンド: ./scripts/setup-tailscale.sh"

0 commit comments

Comments
 (0)