Skip to content

Commit 6a921ca

Browse files
committed
feat: Update so the env vars are passed in via file to the features.
1 parent 2f868ef commit 6a921ca

4 files changed

Lines changed: 58 additions & 26 deletions

File tree

‎features/bridge/devcontainer-feature.json‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "bridge",
3-
"version": "1.1.0",
3+
"version": "1.2.0",
44
"name": "Bridge Tunnel Client",
55
"description": "Connects to the bridge server running on a Vercel Sandbox to forward inbound requests to local applications and intercept outbound traffic via iptables.",
66
"entrypoint": "/usr/local/bin/bridge-entrypoint.sh",
@@ -34,6 +34,11 @@
3434
"type": "string",
3535
"description": "Version of bridge CLI to install (e.g., 'v1.0.0' or 'edge')",
3636
"default": "edge"
37+
},
38+
"envFile": {
39+
"type": "string",
40+
"description": "Path to env file containing VERCEL_AUTOMATION_BYPASS_SECRET (relative to workspace)",
41+
"default": ".env.development.local"
3742
}
3843
},
3944
"containerEnv": {

‎features/bridge/install.sh‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ install_bridge() {
7777

7878
# Write environment configuration
7979
write_env_config() {
80+
local env_file="${ENVFILE:-.env.development.local}"
81+
8082
# Write to /etc/environment for system-wide availability (read by PAM)
8183
# Feature options are available as uppercase versions without special chars
8284
{
@@ -85,6 +87,7 @@ write_env_config() {
8587
echo "SANDBOX_NAME=${SANDBOXNAME:-}"
8688
echo "SYNC_SOURCE=${SYNCSOURCE:-.}"
8789
echo "SYNC_TARGET=${SYNCTARGET:-}"
90+
echo "BRIDGE_ENV_FILE=${env_file}"
8891
} >> /etc/environment
8992

9093
# Also write to /etc/profile.d for shell login sessions
@@ -94,19 +97,41 @@ export FUNCTION_URL="${FUNCTIONURL:-}"
9497
export SANDBOX_NAME="${SANDBOXNAME:-}"
9598
export SYNC_SOURCE="${SYNCSOURCE:-.}"
9699
export SYNC_TARGET="${SYNCTARGET:-}"
100+
export BRIDGE_ENV_FILE="${env_file}"
97101
EOF
98102
}
99103

104+
# Helper to read a value from an env file
105+
# Usage: read_env_var ENV_FILE VAR_NAME
106+
read_env_var() {
107+
local file="$1" var="$2"
108+
if [ -f "$file" ]; then
109+
grep -m1 "^${var}=" "$file" | sed "s/^${var}=//" | sed 's/^"//;s/"$//'
110+
fi
111+
}
112+
100113
# Create entrypoint script
101114
create_entrypoint() {
102115
cat > /usr/local/bin/bridge-entrypoint.sh << 'EOF'
103116
#!/bin/bash
104117
# Source profile in case env vars aren't inherited
105118
[ -f /etc/profile.d/bridge.sh ] && source /etc/profile.d/bridge.sh
106119
120+
# Read VERCEL_AUTOMATION_BYPASS_SECRET from env file if not already set
121+
if [ -z "$VERCEL_AUTOMATION_BYPASS_SECRET" ] && [ -n "$BRIDGE_ENV_FILE" ]; then
122+
# Try workspace-relative path first, then absolute
123+
for candidate in "/workspaces/${BRIDGE_ENV_FILE}" "${BRIDGE_ENV_FILE}"; do
124+
if [ -f "$candidate" ]; then
125+
VERCEL_AUTOMATION_BYPASS_SECRET=$(grep -m1 '^VERCEL_AUTOMATION_BYPASS_SECRET=' "$candidate" | sed 's/^VERCEL_AUTOMATION_BYPASS_SECRET=//' | sed 's/^"//;s/"$//')
126+
export VERCEL_AUTOMATION_BYPASS_SECRET
127+
break
128+
fi
129+
done
130+
fi
131+
107132
# Run bridge intercept as root (required for iptables), passing env vars explicitly
108133
if [ -n "$SANDBOX_URL" ]; then
109-
sudo -E /usr/local/bin/bridge intercept &
134+
sudo -E VERCEL_AUTOMATION_BYPASS_SECRET="$VERCEL_AUTOMATION_BYPASS_SECRET" /usr/local/bin/bridge intercept &
110135
fi
111136
112137
exec "$@"

‎features/vercel-cli/devcontainer-feature.json‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
{
22
"id": "vercel-cli",
3-
"version": "1.2.0",
3+
"version": "1.3.0",
44
"name": "Vercel CLI",
5-
"description": "Installs the Vercel CLI with automatic token passthrough from VERCEL_TOKEN environment variable or env file.",
5+
"description": "Installs the Vercel CLI with automatic token passthrough from env file.",
66
"options": {
77
"version": {
88
"type": "string",
99
"description": "Vercel CLI version to install (e.g., 'latest', '50.8.1')",
1010
"default": "latest"
1111
},
12-
"envFileVar": {
12+
"envFile": {
1313
"type": "string",
14-
"description": "Name of environment variable containing the path to env file with VERCEL_TOKEN",
15-
"default": "VERCEL_ENV_FILE"
14+
"description": "Path to env file containing VERCEL_TOKEN (relative to workspace)",
15+
"default": ".env.development.local"
1616
}
1717
},
1818
"installsAfter": [

‎features/vercel-cli/install.sh‎

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
set -e
33

44
VERSION="${VERSION:-latest}"
5-
ENVFILEVAR="${ENVFILEVAR:-VERCEL_ENV_FILE}"
5+
ENVFILE="${ENVFILE:-.env.development.local}"
66

77
# Remove yarn repository if it exists (often has expired GPG keys causing apt-get update to fail)
88
rm -f /etc/apt/sources.list.d/yarn.list 2>/dev/null || true
@@ -13,7 +13,6 @@ echo "Installing Vercel CLI (version: $VERSION)..."
1313
if ! command -v node &> /dev/null; then
1414
echo "Node.js is required but not installed. Installing Node.js..."
1515
if command -v apt-get &> /dev/null; then
16-
# Remove yarn repository if it exists (often has expired GPG keys)
1716
rm -f /etc/apt/sources.list.d/yarn.list 2>/dev/null || true
1817
apt-get update
1918
apt-get install -y curl
@@ -45,28 +44,32 @@ echo "Vercel CLI installed at: $VERCEL_BIN"
4544
# Move the original binary to a different name
4645
mv "$VERCEL_BIN" "${VERCEL_BIN}-bin"
4746

48-
# Create wrapper script for vercel
49-
cat > "$VERCEL_BIN" << EOF
47+
# Create wrapper script for vercel that reads VERCEL_TOKEN from env file every time
48+
cat > "$VERCEL_BIN" << 'WRAPPER'
5049
#!/bin/bash
51-
# Vercel CLI wrapper - auto-passes VERCEL_TOKEN if set or from env file
50+
# Vercel CLI wrapper - reads VERCEL_TOKEN from env file on every invocation
5251
53-
# Get env file path from environment variable
54-
ENV_FILE_PATH="\${$ENVFILEVAR:-}"
55-
56-
# If VERCEL_TOKEN not set, try to source from env file
57-
if [ -z "\$VERCEL_TOKEN" ] && [ -n "\$ENV_FILE_PATH" ] && [ -f "\$ENV_FILE_PATH" ]; then
58-
set -a
59-
source "\$ENV_FILE_PATH"
60-
set +a
52+
# If VERCEL_TOKEN not already set, read it from the env file
53+
if [ -z "$VERCEL_TOKEN" ]; then
54+
# Try workspace-relative path first, then absolute
55+
for candidate in "/workspaces/${ENVFILE}" "${ENVFILE}"; do
56+
if [ -f "$candidate" ]; then
57+
VERCEL_TOKEN=$(grep -m1 '^VERCEL_TOKEN=' "$candidate" | sed 's/^VERCEL_TOKEN=//' | sed 's/^"//;s/"$//')
58+
break
59+
fi
60+
done
6161
fi
6262
6363
# Use token if available
64-
if [ -n "\$VERCEL_TOKEN" ]; then
65-
exec "\$(dirname "\$0")/vercel-bin" --token "\$VERCEL_TOKEN" "\$@"
64+
if [ -n "$VERCEL_TOKEN" ]; then
65+
exec "$(dirname "$0")/vercel-bin" --token "$VERCEL_TOKEN" "$@"
6666
else
67-
exec "\$(dirname "\$0")/vercel-bin" "\$@"
67+
exec "$(dirname "$0")/vercel-bin" "$@"
6868
fi
69-
EOF
69+
WRAPPER
70+
71+
# Inject the env file path into the wrapper
72+
sed -i "s|\${ENVFILE}|${ENVFILE}|g" "$VERCEL_BIN"
7073
chmod +x "$VERCEL_BIN"
7174

7275
# Create wrapper script for vc (symlink to vercel wrapper)
@@ -82,5 +85,4 @@ echo "Usage:"
8285
echo " vercel whoami"
8386
echo " vc dev"
8487
echo ""
85-
echo "Token will be read from env file path in \$$ENVFILEVAR"
86-
echo "Or set VERCEL_TOKEN environment variable to auto-authenticate."
88+
echo "Token will be read from ${ENVFILE} on every invocation."

0 commit comments

Comments
 (0)