Skip to content

Commit 1148dfb

Browse files
authored
Merge pull request #156 from CodeForPhilly/138-one-step-development-setup
138 one step development setup
2 parents 71508c4 + af06d70 commit 1148dfb

File tree

8 files changed

+293
-85
lines changed

8 files changed

+293
-85
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,5 @@ node_modules/
7272
*.ipr
7373
*.iml
7474
*.iws
75+
76+
.quarkus/

README.md

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,38 @@ If you are interested in getting involved with the project, check out [our page
4444

4545
## Local Development Setup
4646

47+
Clone this repository:
4748
```bash
4849
git clone https://github.com/CodeForPhilly/benefit-decision-toolkit.git
50+
```
4951

52+
Go to the project's root directory:
53+
```bash
5054
cd benefit-decision-toolkit
5155
```
5256

53-
You can find instructions to work on each app within the project in their respective directories, which are linked above.
57+
To setup using the pre-defined [Devbox](https://www.jetify.com/docs/devbox/) configuration:
58+
*Note that this installs Devbox and Nix (if they aren't already installed).
59+
```bash
60+
bin/install-devbox && devbox run setup
61+
```
62+
63+
If you don't want to use devbox/nix, then you can install system dependencies (e.g. JDK, Node, Maven) manually (see devbox.json for the list) and run:
64+
```bash
65+
bin/setup
66+
```
67+
68+
If using devbox, then run the shell to load dependencies:
69+
```bash
70+
devbox shell
71+
# Consider using direnv and/or the VS Code extensions (Devbox and Direnv) to automate this step.
72+
```
73+
74+
Then start apps as needed, e.g.:
75+
```bash
76+
cd builder-frontend && npm run dev
77+
```
78+
79+
You can find additional instructions to work on each app within the project in their respective directories, which are linked above.
5480

55-
Note that for the frontend apps, you will need an environment variable file from a teammate. Please do not commit this file to the repo.
81+
Note that for the frontend apps, you will need a .env file from a teammate. Please do not commit this file to the repo.

bin/functions

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
# Colors for output
6+
RED='\033[0;31m'
7+
GREEN='\033[0;32m'
8+
YELLOW='\033[1;33m'
9+
BLUE='\033[0;34m'
10+
NC='\033[0m' # No Color
11+
12+
# Function to print colored output
13+
print_status() {
14+
printf "${BLUE}[INFO]${NC} %s\n" "$1"
15+
}
16+
17+
print_success() {
18+
printf "${GREEN}[SUCCESS]${NC} %s\n" "$1"
19+
}
20+
21+
print_warning() {
22+
printf "${YELLOW}[WARNING]${NC} %s\n" "$1"
23+
}
24+
25+
print_error() {
26+
printf "${RED}[ERROR]${NC} %s\n" "$1"
27+
}
28+
29+
# Function to check if a command exists
30+
command_exists() {
31+
command -v "$1" >/dev/null 2>&1
32+
}
33+
34+
ask_user() {
35+
local prompt="$1"
36+
local default="${2:-n}"
37+
38+
if [[ "$default" == "y" ]]; then
39+
prompt_suffix="[Y/n]"
40+
else
41+
prompt_suffix="[y/N]"
42+
fi
43+
44+
while true; do
45+
read -p "$prompt $prompt_suffix: " -r answer
46+
answer=${answer:-$default}
47+
48+
case "$answer" in
49+
[Yy] | [Yy][Ee][Ss]) return 0 ;;
50+
[Nn] | [Nn][Oo]) return 1 ;;
51+
*) echo "Please answer yes or no." ;;
52+
esac
53+
done
54+
}

bin/install-devbox

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
# Check if we're in the right directory
10+
# TODO: actually check the directory as well as the devbox.json?
11+
if [ ! -f "devbox.json" ]; then
12+
print_error "Please run this script from the root of the benefit-decision-toolkit project"
13+
exit 1
14+
fi
15+
16+
print_status "🔍 Checking for existing devbox installation..."
17+
18+
if ! command_exists devbox; then
19+
print_warning "Devbox not found. Installing devbox..."
20+
if command_exists curl; then
21+
curl -fsSL https://get.jetify.com/devbox/install.sh | bash
22+
print_success "Devbox installed"
23+
else
24+
print_error "curl not found. Please install devbox manually: https://www.jetify.com/devbox/docs/contributor-quickstart/"
25+
exit 1
26+
fi
27+
else
28+
print_status "devbox already installed."
29+
fi
30+
31+
print_status "📦 Setting up devbox environment..."
32+
if [ -f "devbox.json" ]; then
33+
devbox install
34+
print_success "Devbox environment initialized"
35+
else
36+
print_error "devbox.json not found"
37+
exit 1
38+
fi

bin/setup

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#!/usr/bin/env bash
2+
3+
# Benefit Decision Toolkit - One-Step Developer Setup Script
4+
# This script streamlines setup of a development environment for the Benefit Decision Toolkit
5+
6+
set -e # Exit on any error
7+
8+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9+
10+
source "$SCRIPT_DIR/functions"
11+
12+
print_status "🚀 Starting Benefit Decision Toolkit Developer Setup..."
13+
14+
if [[ "$DEVBOX_SHELL_ENABLED" != "1" ]]; then
15+
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
16+
echo ""
17+
echo "Devbox instructions:"
18+
echo ""
19+
echo "1. If you already have devbox installed, then run:"
20+
echo " \$ devbox run setup"
21+
echo ""
22+
echo "2. If you don't already have devbox installed (or you're not sure), then run:"
23+
echo " \$ bin/install-devbox && devbox run setup"
24+
echo ""
25+
exit 0
26+
else
27+
print_warning "Setup won't use devbox; system dependencies are the developer's responsibility. See devbox.json for the list of dependencies needed."
28+
sleep 2
29+
fi
30+
fi
31+
32+
print_status "📦 Installing frontend dependencies..."
33+
34+
if ! command_exists npm; then
35+
print_error "npm not found. Please install node manually or use devbox to manage dependencies."
36+
exit 1
37+
fi
38+
39+
print_status "Installing builder-frontend dependencies..."
40+
cd builder-frontend
41+
if [ -f "package.json" ]; then
42+
npm install
43+
print_success "builder-frontend dependencies installed"
44+
else
45+
print_error "package.json not found in builder-frontend"
46+
exit 1
47+
fi
48+
cd ..
49+
50+
print_status "Installing screener-frontend dependencies..."
51+
cd screener-frontend
52+
if [ -f "package.json" ]; then
53+
npm install
54+
print_success "screener-frontend dependencies installed"
55+
else
56+
print_error "package.json not found in screener-frontend"
57+
exit 1
58+
fi
59+
cd ..
60+
61+
print_status "Finished installing frontend dependencies."
62+
63+
print_status "📦 Installing backend dependencies..."
64+
65+
if ! command_exists mvn; then
66+
print_error "mvn not found. Please install maven manually or use devbox to manage dependendcies."
67+
exit 1
68+
fi
69+
70+
print_status "Installing library-api dependencies..."
71+
cd library-api
72+
mvn clean package
73+
print_success "library-api dependencies installed"
74+
cd ..
75+
76+
print_status "Installing builder-api dependencies..."
77+
cd builder-api
78+
# TODO: are the tests important to run here? (one of them was failing for me)
79+
mvn clean package -DskipTests
80+
print_success "builder-api dependencies installed"
81+
cd ..
82+
83+
print_status "Installing screener-api dependencies..."
84+
cd screener-api
85+
mvn clean package
86+
print_success "screener-api dependencies installed"
87+
cd ..
88+
89+
print_status "Finished installing backend dependencies."
90+
91+
print_success "🎉 Developer setup completed successfully!"
92+
echo ""
93+
echo "📋 Next Steps:"
94+
echo "1. Ask a teammate to help you setup .env files in builder-frontend and screener-frontend."
95+
echo "2. If using devbox, then:"
96+
echo " a. Run 'devbox shell' within the project root directory to load dependencies. (https://www.jetify.com/docs/devbox/cli_reference/devbox_shell/)"
97+
echo " b. Consider using the direnv integration to load dependencies automatically. (https://www.jetify.com/docs/devbox/ide_configuration/direnv/)"
98+
echo " c. If you use VS Code, then consider installing the Devbox and Direnv extensions."
99+
echo "3. Run the web apps locally using 'npm run dev' from within builder-frontend and screener-frontend directories."
100+
echo "4. Run the library-api application using 'quarkus dev' within the library-api directory."
101+
echo ""
102+
print_status "Happy coding! 🚀"

bin/teardown

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
3+
# NOTE: this is maybe temporary... for helping to test project setup
4+
5+
echo -n "Removing all maven dependencies"
6+
rm -rf ~/.m2/repository
7+
echo "...done"
8+
9+
echo -n "Removing all npm dependencies"
10+
rm -rf builder-frontend/node_modules screener-frontend/node_modules
11+
echo "...done"
12+
13+
echo -n "Removing devbox"
14+
rm /usr/local/bin/devbox
15+
rm -rf ~/.cache/devbox
16+
rm -rf ~/.local/share/devbox
17+
echo "...done"
18+
19+
echo -n "Removing nix"
20+
rm -rf /nix ~/.nix-channels ~/.nix-defexpr ~/.nix-profile
21+
echo "...done"

devbox.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44
"maven@latest",
55
"quarkus@latest",
66
"jdk21@latest",
7-
"google-cloud-sdk@latest",
8-
"podman@latest",
9-
"docker@latest",
10-
"firebase-tools@latest"
7+
"nodejs@20",
8+
"firebase-tools@latest",
9+
"google-cloud-sdk@latest"
1110
],
1211
"shell": {
1312
"init_hook": [
14-
"echo 'Welcome to devbox!' > /dev/null"
13+
"echo 'Welcome to devbox!'",
14+
"command -v mise >/dev/null && mise deactivate || true"
1515
],
1616
"scripts": {
17-
"test": [
18-
"echo \"Error: no test specified\" && exit 1"
17+
"setup": [
18+
"bin/setup"
1919
]
2020
}
2121
}

0 commit comments

Comments
 (0)