Skip to content

Commit 15d10ed

Browse files
authored
Initial commit
0 parents  commit 15d10ed

40 files changed

Lines changed: 2877 additions & 0 deletions

.devcontainer/devcontainer.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"name": "OctoFit Tracker App codespace",
3+
"image": "mcr.microsoft.com/devcontainers/base:jammy",
4+
"features": {
5+
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
6+
"ghcr.io/devcontainers/features/github-cli:1": {},
7+
"ghcr.io/devcontainers/features/node:1": {
8+
"version": "lts",
9+
"pnpmVersion": "latest",
10+
"nvmVersion": "latest"
11+
}
12+
},
13+
"postCreateCommand": "sudo chmod +x ./.devcontainer/post_create.sh && ./.devcontainer/post_create.sh",
14+
"postStartCommand": "sudo chmod +x ./.devcontainer/post_start.sh && ./.devcontainer/post_start.sh",
15+
"customizations": {
16+
"vscode": {
17+
"extensions": [
18+
"github.copilot", // GitHub Copilot + Copilot Chat
19+
"markdown-lint.markdownlinter",
20+
"ms-python.python", // Python extension
21+
"ms-python.vscode-pylance", // Pylance extension for Python
22+
"ms-python.debugpy" // Debugpy extension for Python
23+
],
24+
"settings": {
25+
"chat.agent.enabled": true,
26+
}
27+
}
28+
},
29+
"forwardPorts": [
30+
3000, // React default port
31+
8000, // Django default port
32+
27017 // MongoDB default port
33+
],
34+
"portAttributes": {
35+
"3000": { // React port attributes
36+
"label": "octofit-tracker",
37+
"requireLocalPort": true
38+
},
39+
"8000": { // Django port attributes
40+
"label": "octofit-api",
41+
"requireLocalPort": true
42+
}
43+
}
44+
}

.devcontainer/post_create.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
# This script is run after the container is created.
3+
# It is used to install any additional dependencies or perform any setup tasks.
4+
5+
wget -qO - https://pgp.mongodb.com/server-6.0.asc | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/mongodb-server-6.0.gpg > /dev/null
6+
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
7+
sudo apt-get update
8+
sudo apt-get install -y python3-venv
9+
sudo apt-get install -y mongodb-org
10+
sudo mkdir -p /usr/local/etc/vscode-dev-containers
11+
sudo cp --force ./.devcontainer/welcome-message.txt /usr/local/etc/vscode-dev-containers/first-run-notice.txt

.devcontainer/post_start.sh

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#!/bin/bash
2+
# This script is run after the container starts up.
3+
4+
set -euo pipefail
5+
6+
die() {
7+
echo "ERROR: $@" >&2
8+
exit 1
9+
}
10+
11+
# Ensure CODESPACE_NAME is set
12+
: "${CODESPACE_NAME:?CODESPACE_NAME environment variable not set. This script should be run in a GitHub Codespace environment.}"
13+
14+
# Port visibility setup
15+
echo "Setting port visibility..."
16+
gh cs ports visibility 8000:public -c "$CODESPACE_NAME" || die "Failed to set 8000 public"
17+
gh cs ports visibility 3000:public -c "$CODESPACE_NAME" || die "Failed to set 3000 public"
18+
19+
echo "Preparing MongoDB data dir..."
20+
sudo mkdir -p /data/db || die "mkdir failed"
21+
sudo chmod 777 /data/db || die "chmod failed"
22+
23+
LOGFILE=/tmp/mongod.log
24+
MAX_START_TRIES=3 # How many times to attempt (re)starting mongod
25+
READY_CHECK_RETRIES=15 # How many readiness checks per start attempt
26+
READY_CHECK_INTERVAL=1 # Seconds between readiness checks
27+
is_running() {
28+
pgrep -x mongod >/dev/null 2>&1
29+
}
30+
31+
start_mongod() {
32+
if is_running; then
33+
echo "mongod already running"
34+
return 0
35+
fi
36+
# Clean old log (keep last one for inspection)
37+
> "$LOGFILE"
38+
echo "Launching mongod (dbpath=/data/db, log=$LOGFILE)..."
39+
mongod --dbpath /data/db --fork --logpath "$LOGFILE"
40+
}
41+
42+
ready_check() {
43+
# Success if log shows ready OR port is open
44+
if grep -q "Waiting for connections" "$LOGFILE" 2>/dev/null; then
45+
return 0
46+
fi
47+
if command -v nc >/dev/null 2>&1; then
48+
if nc -z 127.0.0.1 27017 2>/dev/null; then
49+
return 0
50+
fi
51+
fi
52+
# If mongo/mongosh client exists, try a ping (quietly)
53+
if command -v mongosh >/dev/null 2>&1; then
54+
mongosh --quiet --eval 'db.runCommand({ping:1})' >/dev/null 2>&1 && return 0 || true
55+
elif command -v mongo >/dev/null 2>&1; then
56+
mongo --quiet --eval 'db.runCommand({ping:1})' >/dev/null 2>&1 && return 0 || true
57+
fi
58+
return 1
59+
}
60+
61+
wait_for_ready() {
62+
for ((i=1; i<=READY_CHECK_RETRIES; i++)); do
63+
if ready_check; then
64+
echo "mongod is ready (after $i checks)."
65+
return 0
66+
fi
67+
sleep "$READY_CHECK_INTERVAL"
68+
done
69+
return 1
70+
}
71+
72+
echo "Starting MongoDB with retries..."
73+
for ((attempt=1; attempt<=MAX_START_TRIES; attempt++)); do
74+
echo "Start attempt $attempt/$MAX_START_TRIES"
75+
if start_mongod; then
76+
if wait_for_ready; then
77+
tail -20 "$LOGFILE" || true
78+
echo "MongoDB started successfully."
79+
break
80+
else
81+
echo "Readiness check failed for attempt $attempt."
82+
fi
83+
else
84+
echo "mongod launch command failed on attempt $attempt."
85+
fi
86+
87+
if (( attempt == MAX_START_TRIES )); then
88+
tail -40 "$LOGFILE" || true
89+
die "MongoDB failed to start after $MAX_START_TRIES attempts"
90+
fi
91+
92+
echo "Cleaning up before next attempt..."
93+
if is_running; then
94+
pkill -x mongod || true
95+
sleep 2
96+
fi
97+
done
98+
99+
echo "post_start.sh completed successfully."
100+
exit 0

.devcontainer/welcome-message.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
👋 Welcome to building a multi-tier fitness tracker application with GitHub Copilot agent mode!
2+
We are thrilled that you are here and we hope you are excited to explore the capabilities of Copilot!
3+
🏋🏽🔥💪🏼🎧 As the gym teacher of Mergington High School you have been tasked with building a fitness app for your students.
4+
📃 GitHub Copilot documentation: https://docs.github.com/en/copilot

.github/TROUBLESHOOTING.md

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
# Workshop Troubleshooting Guide
2+
3+
## Quick Fix for GitHub Actions Failures
4+
5+
If your GitHub Actions validation is failing for any workshop step, use the troubleshooting prompt to automatically diagnose and fix the issue.
6+
7+
### How to Use
8+
9+
1. **Open GitHub Copilot Chat** in VS Code
10+
2. **Select "Agent" mode** from the dropdown (not "Ask" or "Edit")
11+
3. **Run the fix command** with your step number:
12+
13+
```prompt
14+
/fix-step 2
15+
```
16+
17+
Replace `2` with the step number you're stuck on (2, 3, 4, or 5).
18+
19+
### Available Commands
20+
21+
- `/fix-step 2` - Fix Step 2: Application Initial Setup (requirements.txt)
22+
- `/fix-step 3` - Fix Step 3: Django Project Setup (settings.py, populate_db.py)
23+
- `/fix-step 4` - Fix Step 4: Django REST Framework (codespace URLs)
24+
- `/fix-step 5` - Fix Step 5: React Frontend (component API endpoints)
25+
26+
### What the Prompt Does
27+
28+
The troubleshooting prompt will automatically:
29+
30+
1. **Diagnose** - Check what files exist and what's missing
31+
2. **Compare** - Verify file contents against GitHub Actions requirements
32+
3. **Fix** - Create or update files to meet validation criteria
33+
4. **Verify** - Confirm all checks will pass
34+
5. **Report** - Tell you what was wrong and what was fixed
35+
36+
### Common Issues by Step
37+
38+
#### Step 2 Issues
39+
-`requirements.txt` missing or in wrong location
40+
-`Django==4.1` not in requirements.txt
41+
-**Fix**: Creates file with all required packages
42+
43+
#### Step 3 Issues
44+
- ❌ Django project not created in correct directory
45+
-`settings.py` missing MongoDB configuration
46+
-`populate_db.py` management command doesn't exist
47+
-**Fix**: Creates Django project, configures MongoDB, adds data population script
48+
49+
#### Step 4 Issues
50+
- ❌ Codespace URL not in `settings.py` ALLOWED_HOSTS
51+
- ❌ API root in `urls.py` not using codespace URL format
52+
-**Fix**: Updates both files with proper codespace URL configuration
53+
54+
#### Step 5 Issues
55+
- ❌ React components missing API endpoint URLs
56+
- ❌ Components not fetching from `-8000.app.github.dev` domain
57+
- ❌ Wrong endpoint paths in component files
58+
-**Fix**: Updates all 5 components with correct API URLs
59+
60+
### Example Usage
61+
62+
```
63+
User: /fix-step 3
64+
65+
Copilot Agent Mode:
66+
- Checking Step 3 validation requirements...
67+
- Found issue: settings.py missing 'djongo' configuration
68+
- Found issue: populate_db.py doesn't exist
69+
- Creating management command structure...
70+
- Updating settings.py with MongoDB configuration...
71+
- Creating populate_db.py with test data...
72+
- Verifying fixes against validation criteria...
73+
- ✅ All Step 3 checks will now pass!
74+
- Committing changes to build-octofit-app branch...
75+
76+
Ready to push! Your changes should pass GitHub Actions validation.
77+
```
78+
79+
### Tips
80+
81+
- **Wait for completion** - Agent mode may take a minute to analyze and fix issues
82+
- **Press Continue** - Allow agent mode to execute commands when prompted
83+
- **Keep changes** - Don't cancel or undo files created by the agent
84+
- **Push after fixing** - Remember to push your changes after the fix completes
85+
- **Re-run if needed** - You can run the fix command multiple times
86+
87+
### When to Use This
88+
89+
Use the fix-step prompt when:
90+
- ⚠️ GitHub Actions workflow fails validation
91+
- ⚠️ Mona reports validation errors in the issue comments
92+
- ⚠️ You're not sure what's missing or incorrect
93+
- ⚠️ You want to quickly verify your work meets requirements
94+
95+
### Manual Verification
96+
97+
After running the fix prompt, you can manually verify:
98+
99+
**Step 2:**
100+
```bash
101+
cat octofit-tracker/backend/requirements.txt | grep "Django==4.1"
102+
```
103+
104+
**Step 3:**
105+
```bash
106+
grep -i "octofit_db" octofit-tracker/backend/octofit_tracker/settings.py
107+
grep -i "djongo" octofit-tracker/backend/octofit_tracker/settings.py
108+
cat octofit-tracker/backend/octofit_tracker/management/commands/populate_db.py
109+
```
110+
111+
**Step 4:**
112+
```bash
113+
grep "8000.app.github.dev" octofit-tracker/backend/octofit_tracker/settings.py
114+
grep "8000.app.github.dev" octofit-tracker/backend/octofit_tracker/urls.py
115+
```
116+
117+
**Step 5:**
118+
```bash
119+
grep "8000.app.github.dev/api/activities" octofit-tracker/frontend/src/components/Activities.js
120+
grep "8000.app.github.dev/api/leaderboard" octofit-tracker/frontend/src/components/Leaderboard.js
121+
grep "8000.app.github.dev/api/teams" octofit-tracker/frontend/src/components/Teams.js
122+
grep "8000.app.github.dev/api/users" octofit-tracker/frontend/src/components/Users.js
123+
grep "8000.app.github.dev/api/workouts" octofit-tracker/frontend/src/components/Workouts.js
124+
```
125+
126+
### Still Having Issues?
127+
128+
If the automatic fix doesn't resolve your issue:
129+
130+
1. **Check the branch** - Ensure you're on `build-octofit-app` branch
131+
2. **Verify file paths** - Files must be in exact locations specified
132+
3. **Check for typos** - Validation is case-insensitive but requires exact strings
133+
4. **Review the step instructions** - Re-read the step requirements in `.github/steps/`
134+
5. **Check GitHub Actions logs** - Review the actual error messages in the Actions tab
135+
136+
### Need More Help?
137+
138+
- Review step instructions: `.github/steps/[1-6]-*.md`
139+
- Check instruction files: `.github/instructions/*.md`
140+
- Review other prompts: `.github/prompts/*.prompt.md`
141+
- Ask Copilot: "What did I miss in Step X?"
142+
143+
---
144+
145+
**Remember**: This troubleshooting prompt is designed to save you time by automatically fixing common validation issues. Let agent mode do the heavy lifting!
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
applyTo: "octofit-tracker/backend/**"
3+
---
4+
# Octofit-tracker Fitness App Django backend Guidelines
5+
6+
## Django Backend App structure
7+
8+
### settings.py
9+
10+
Should always contain the following:
11+
12+
```python
13+
import os
14+
ALLOWED_HOSTS = ['localhost', '127.0.0.1']
15+
if os.environ.get('CODESPACE_NAME'):
16+
ALLOWED_HOSTS.append(f"{os.environ.get('CODESPACE_NAME')}-8000.app.github.dev")
17+
```
18+
19+
## serializers.py
20+
21+
```text
22+
serializers should convert ObjectId fields to strings
23+
```
24+
25+
## REST API Endpoints
26+
27+
```text
28+
use curl to test the endpoints
29+
```
30+
31+
### urls.py
32+
33+
Should always use the codespace environment variable for the URL
34+
35+
```python
36+
import os
37+
codespace_name = os.environ.get('CODESPACE_NAME')
38+
if codespace_name:
39+
base_url = f"https://{codespace_name}-8000.app.github.dev"
40+
else:
41+
base_url = "http://localhost:8000"
42+
43+
urlpatterns = [
44+
path('admin/', admin.site.urls),
45+
path('api/', api_root, name='api-root'),
46+
path('api/', include(router.urls)),
47+
]
48+
```
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
applyTo: "octofit-tracker/frontend/**"
3+
---
4+
# Octofit-tracker Fitness App React frontend Guidelines
5+
6+
## REACT Frontend App structure
7+
8+
Make sure in all commands we point to the `octofit-tracker/frontend` directory
9+
10+
```bash
11+
npx create-react-app octofit-tracker/frontend --template cra-template --use-npm
12+
13+
npm install bootstrap --prefix octofit-tracker/frontend
14+
15+
# Add the Bootstrap CSS import at the very top of src/index.js:
16+
sed -i "1iimport 'bootstrap/dist/css/bootstrap.min.css';" octofit-tracker/frontend/src/index.js
17+
18+
npm install react-router-dom --prefix octofit-tracker/frontend
19+
20+
```
21+
22+
## Images for the OctoFit Tracker App
23+
24+
The image to use for the app is in the root of this repository docs/octofitapp-small.png

0 commit comments

Comments
 (0)