mirror of
https://github.com/farcasclaudiu/learn-build-apps-copilot-agent.git
synced 2026-06-28 15:01:30 +03:00
Initial commit
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
{
|
||||
"name": "OctoFit Tracker Multi-tier Application Codespace",
|
||||
"image": "mcr.microsoft.com/devcontainers/base:jammy",
|
||||
"features": {
|
||||
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
|
||||
"ghcr.io/devcontainers/features/github-cli:1": {},
|
||||
"ghcr.io/devcontainers/features/node:1": {
|
||||
"version": "lts",
|
||||
"pnpmVersion": "latest",
|
||||
"nvmVersion": "latest"
|
||||
}
|
||||
},
|
||||
"postCreateCommand": "sudo chmod +x ./.devcontainer/post_create.sh && ./.devcontainer/post_create.sh",
|
||||
"postStartCommand": "sudo chmod +x ./.devcontainer/post_start.sh && ./.devcontainer/post_start.sh",
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
"extensions": [
|
||||
"github.copilot",
|
||||
"markdown-lint.markdownlinter",
|
||||
"ms-vscode.vscode-typescript-next",
|
||||
"dbaeumer.vscode-eslint"
|
||||
],
|
||||
"settings": {
|
||||
"chat.agent.enabled": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"forwardPorts": [
|
||||
5173,
|
||||
8000,
|
||||
27017
|
||||
],
|
||||
"portsAttributes": {
|
||||
"5173": {
|
||||
"label": "octofit-tracker-frontend",
|
||||
"requireLocalPort": true
|
||||
},
|
||||
"8000": {
|
||||
"label": "octofit-tracker-api",
|
||||
"requireLocalPort": true
|
||||
},
|
||||
"27017": {
|
||||
"label": "octofit-tracker-mongodb",
|
||||
"requireLocalPort": true
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable
+11
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
# This script is run after the container is created.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
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
|
||||
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
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y mongodb-org
|
||||
sudo mkdir -p /usr/local/etc/vscode-dev-containers
|
||||
sudo cp --force ./.devcontainer/welcome-message.txt /usr/local/etc/vscode-dev-containers/first-run-notice.txt
|
||||
Executable
+97
@@ -0,0 +1,97 @@
|
||||
#!/bin/bash
|
||||
# This script is run after the container starts up.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
die() {
|
||||
echo "ERROR: $@" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
: "${CODESPACE_NAME:?CODESPACE_NAME environment variable not set. This script should be run in a GitHub Codespace environment.}"
|
||||
|
||||
echo "Setting multi-tier application port visibility..."
|
||||
gh cs ports visibility 8000:public -c "$CODESPACE_NAME" || die "Failed to set 8000 public"
|
||||
gh cs ports visibility 5173:public -c "$CODESPACE_NAME" || die "Failed to set 5173 public"
|
||||
gh cs ports visibility 27017:private -c "$CODESPACE_NAME" || die "Failed to set 27017 private"
|
||||
|
||||
echo "Preparing MongoDB data dir..."
|
||||
sudo mkdir -p /data/db || die "mkdir failed"
|
||||
sudo chmod 777 /data/db || die "chmod failed"
|
||||
|
||||
LOGFILE=/tmp/mongod.log
|
||||
MAX_START_TRIES=3
|
||||
READY_CHECK_RETRIES=15
|
||||
READY_CHECK_INTERVAL=1
|
||||
|
||||
is_running() {
|
||||
ps aux | grep '[m]ongod' >/dev/null 2>&1
|
||||
}
|
||||
|
||||
mongod_pid() {
|
||||
pgrep -x mongod || true
|
||||
}
|
||||
|
||||
start_mongod() {
|
||||
if is_running; then
|
||||
echo "mongod already running"
|
||||
return 0
|
||||
fi
|
||||
> "$LOGFILE"
|
||||
echo "Launching mongod (dbpath=/data/db, log=$LOGFILE)..."
|
||||
mongod --dbpath /data/db --fork --logpath "$LOGFILE"
|
||||
}
|
||||
|
||||
ready_check() {
|
||||
if grep -q "Waiting for connections" "$LOGFILE" 2>/dev/null; then
|
||||
return 0
|
||||
fi
|
||||
if command -v nc >/dev/null 2>&1; then
|
||||
nc -z 127.0.0.1 27017 2>/dev/null && return 0
|
||||
fi
|
||||
if command -v mongosh >/dev/null 2>&1; then
|
||||
mongosh --quiet --eval 'db.runCommand({ping:1})' >/dev/null 2>&1 && return 0 || true
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
wait_for_ready() {
|
||||
for ((i=1; i<=READY_CHECK_RETRIES; i++)); do
|
||||
if ready_check; then
|
||||
echo "mongod is ready (after $i checks)."
|
||||
return 0
|
||||
fi
|
||||
sleep "$READY_CHECK_INTERVAL"
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
echo "Starting MongoDB with retries..."
|
||||
for ((attempt=1; attempt<=MAX_START_TRIES; attempt++)); do
|
||||
echo "Start attempt $attempt/$MAX_START_TRIES"
|
||||
if start_mongod && wait_for_ready; then
|
||||
tail -20 "$LOGFILE" || true
|
||||
echo "MongoDB started successfully."
|
||||
break
|
||||
fi
|
||||
|
||||
if (( attempt == MAX_START_TRIES )); then
|
||||
tail -40 "$LOGFILE" || true
|
||||
die "MongoDB failed to start after $MAX_START_TRIES attempts"
|
||||
fi
|
||||
|
||||
echo "Cleaning up before next attempt..."
|
||||
cleaned_up=false
|
||||
while IFS= read -r pid; do
|
||||
if [ -n "$pid" ]; then
|
||||
kill "$pid" || true
|
||||
cleaned_up=true
|
||||
fi
|
||||
done < <(mongod_pid)
|
||||
if [ "$cleaned_up" = true ]; then
|
||||
sleep 2
|
||||
fi
|
||||
done
|
||||
|
||||
echo "post_start.sh completed successfully."
|
||||
exit 0
|
||||
@@ -0,0 +1,13 @@
|
||||
👋 Welcome to building a modern multi-tier application with GitHub Copilot agent mode!
|
||||
|
||||
You will build OctoFit Tracker using:
|
||||
- Presentation tier: React 19
|
||||
- Logic tier: Node.js + Express + TypeScript
|
||||
- Data tier: MongoDB
|
||||
|
||||
Ports used in this exercise:
|
||||
- 5173 (public)
|
||||
- 8000 (public)
|
||||
- 27017 (private)
|
||||
|
||||
📃 GitHub Copilot documentation: https://docs.github.com/en/copilot
|
||||
Reference in New Issue
Block a user