Skip to content

Commit c746ee8

Browse files
committed
Overhaul env management to rely on .env
Goal is to make it straightforward to manage local dev environment variables whether using devbox, devbox with direnv, devcontainer, or none of the above.
1 parent 50b7fc0 commit c746ee8

File tree

20 files changed

+106
-35
lines changed

20 files changed

+106
-35
lines changed

.devcontainer/Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ COPY --chown=${DEVBOX_USER}:${DEVBOX_USER} devbox.json devbox.json
99
COPY --chown=${DEVBOX_USER}:${DEVBOX_USER} devbox.lock devbox.lock
1010

1111

12-
1312
RUN devbox run -- echo "Installed Packages." && nix-store --gc && nix-store --optimise
1413

1514
RUN devbox shellenv --init-hook >> ~/.profile

.devcontainer/devcontainer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"dockerfile": "./Dockerfile",
55
"context": ".."
66
},
7+
"postCreateCommand": "devbox run setup",
78
"customizations": {
89
"vscode": {
910
"settings": {},
@@ -13,4 +14,4 @@
1314
}
1415
},
1516
"remoteUser": "devbox"
16-
}
17+
}

.env.example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
QUARKUS_GOOGLE_CLOUD_PROJECT_ID="demo-bdt-dev"
2+
QUARKUS_GOOGLE_CLOUD_FIREBASE_AUTH_EMULATOR_HOST="localhost:9099"
3+
QUARKUS_GOOGLE_CLOUD_STORAGE_HOST_OVERRIDE="http://127.0.0.1:9199"
4+
GCS_BUCKET_NAME="demo-bdt-dev.appspot.com"
5+
FIRESTORE_EMULATOR_HOST="127.0.0.1:8080"
6+

.envrc

Lines changed: 0 additions & 9 deletions
This file was deleted.

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ node_modules/
6565
# dotenv environment variables file
6666
.env
6767

68+
.envrc
69+
6870
# dataconnect generated files
6971
.dataconnect
7072
# IntelliJ
@@ -74,3 +76,5 @@ node_modules/
7476
*.iws
7577

7678
.quarkus/
79+
80+
bin/devbox-init-hook
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ set -e
1010
# IMPORTANT: don't use this script for environment variables; use .env instead.
1111

1212
# e.g. disable mise in devbox shell
13-
command -v mise >/dev/null && mise --quiet deactivate || true
13+
# command -v mise >/dev/null && mise deactivate || true
1414

bin/ensure-root-env-file

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6+
7+
source "$SCRIPT_DIR/functions"
8+
9+
print_status "🔍 Checking for existing root .env..."
10+
if [ -f ".env.example" ] && [ ! -f ".env" ]; then
11+
cp ".env.example" ".env"
12+
print_success "✓ Created root .env from .env.example"
13+
elif [ -f ".env" ]; then
14+
print_status "○ Using existing root .env"
15+
else
16+
print_error "⚠ Error: Root .env.example not found"
17+
exit 1
18+
fi

bin/install-devbox

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@ else
2828
print_status "devbox already installed."
2929
fi
3030

31+
bin/ensure-root-env-file
32+
33+
print_status "🔍 Checking for existing bin/devbox-init-hook..."
34+
if [ -f "bin/devbox-init-hook.example" ] && [ ! -f "bin/devbox-init-hook" ]; then
35+
cp "bin/devbox-init-hook.example" "bin/devbox-init-hook"
36+
chmod +x "bin/devbox-init-hook"
37+
print_success "✓ Created bin/devbox-init-hook from example"
38+
elif [ -f "bin/devbox-init-hook" ]; then
39+
print_status "○ bin/devbox-init-hook already exists"
40+
else
41+
print_error "⚠ Error: bin/devbox-init-hook.example not found."
42+
exit 1
43+
fi
44+
3145
print_status "📦 Setting up devbox environment..."
3246
if [ -f "devbox.json" ]; then
3347
devbox install

bin/load-root-env

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
set -a
6+
[ -f .env ] && source .env
7+
set +a

bin/setup

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ source "$SCRIPT_DIR/functions"
1111

1212
print_status "🚀 Starting Benefit Decision Toolkit Developer Setup..."
1313

14+
echo ""
15+
1416
if [[ "$DEVBOX_SHELL_ENABLED" != "1" ]]; then
1517
if ask_user "This project is configured to use devbox (https://www.jetify.com/devbox) to manage system dependencies. Do you want to use devbox? (default=yes)" "y"; then
1618
echo ""
@@ -88,10 +90,33 @@ cd ..
8890

8991
print_status "Finished installing backend dependencies."
9092

93+
echo ""
94+
95+
print_status "Setting up environment files..."
96+
97+
bin/ensure-root-env-file
98+
99+
SERVICES=("builder-frontend" "screener-frontend" "builder-api" "screener-api" "library-api")
100+
for service in "${SERVICES[@]}"; do
101+
if [ -f "$service/.env.example" ] && [ ! -f "$service/.env" ]; then
102+
cp "$service/.env.example" "$service/.env"
103+
print_success "✓ Created $service/.env from .env.example"
104+
elif [ -f "$service/.env" ]; then
105+
print_status "$service/.env already exists"
106+
else
107+
print_error "⚠ Error: $service/.env.example not found"
108+
exit 1
109+
fi
110+
done
111+
112+
echo ""
113+
91114
print_success "🎉 Developer setup completed successfully!"
92115
echo ""
93116
echo "📋 Next Steps:"
94-
echo "1. Ask a teammate to help you setup .env files in builder-frontend and screener-frontend."
117+
echo "1. Environment Configuration:"
118+
echo " a. If you plan to use devbox and develop against local emulators, then you are good to go!"
119+
echo " b. If not using devbox and/or plan to develop against real Firebase services, then you might need help from a teammate to finish setting up your environment."
95120
echo "2. If using devbox, then:"
96121
echo " a. Run 'devbox shell' within the project root directory to load dependencies. (https://www.jetify.com/docs/devbox/cli_reference/devbox_shell/)"
97122
echo " b. Consider using the direnv integration to load dependencies automatically. (https://www.jetify.com/docs/devbox/ide_configuration/direnv/)"

0 commit comments

Comments
 (0)