Skip to content

Convert to Battleships #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 34 additions & 63 deletions .gitpod/automations.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
services:
postgres:
name: "PostgreSQL Database"
description: "PostgreSQL database for Gitpod Flix (Port: 5432)"
description: "PostgreSQL database for Battleship Game (Port: 5432)"
triggeredBy:
- postDevcontainerStart
- postEnvironmentStart
Expand All @@ -24,23 +24,30 @@ services:
postgres:15

ready: |
if docker exec postgres pg_isready -U gitpod; then
echo "PostgreSQL is ready and accepting connections"
exit 0
else
# First check if PostgreSQL is accepting connections
if ! docker exec postgres pg_isready -U gitpod; then
echo "PostgreSQL not ready"
exit 1
fi

# Then check if the game_state table exists
if ! docker exec postgres psql -U gitpod -d gitpodflix -c "SELECT 1 FROM game_state LIMIT 1" >/dev/null 2>&1; then
echo "Running migrations..."
docker exec postgres psql -U gitpod -d gitpodflix -f /docker-entrypoint-initdb.d/02_create_game_state.sql
fi

echo "PostgreSQL is ready and accepting connections"
exit 0

stop: |
echo "Stopping PostgreSQL container..."
docker stop postgres || true
echo "Removing PostgreSQL container..."
docker rm -f postgres || true

catalog:
name: "Catalog Service"
description: "Movie catalog API service (Port: 3001)"
name: "Game Server"
description: "Battleship game API service (Port: 3001)"
triggeredBy:
- postDevcontainerStart
- postEnvironmentStart
Expand All @@ -50,56 +57,40 @@ services:
PORT=3001 npx nodemon src/index.ts
ready: |
if curl -s http://localhost:3001/health > /dev/null; then
echo "Catalog service is ready"
echo "Game server is ready"
exit 0
else
echo "Catalog service not ready"
echo "Game server not ready"
exit 1
fi
stop: |
pkill -f "node.*catalog" || true

gitpod-flix:
name: "Gitpod Flix"
description: "Streaming platform frontend (Port: 3000)"
frontend:
name: "Game Frontend"
description: "Battleship game frontend (Port: 3000)"
triggeredBy:
- postDevcontainerStart
- postEnvironmentStart
commands:
start: |
cd /workspaces/gitpodflix-demo/frontend

# Wait for vite to be available
echo "Waiting for vite to be available..."
for i in {1..30}; do
if command -v vite >/dev/null 2>&1 || [ -f "node_modules/.bin/vite" ]; then
echo "✓ vite is available"
break
fi
if [ $i -eq 30 ]; then
echo "✗ Timeout waiting for vite"
exit 1
fi
echo "Waiting for vite... attempt $i/30"
sleep 2
done

PORT=3000 npm run dev
ready: |
if curl -s http://localhost:3000 > /dev/null; then
echo "Gitpod Flix is ready"
echo "Frontend is ready"
exit 0
else
echo "Gitpod Flix not ready"
echo "Frontend not ready"
exit 1
fi
stop: |
pkill -f "node.*frontend" || true

tasks:
seedDatabase:
name: "Seed Database"
description: "Seed the database with sample movies in a dramatic sequence"
name: "Initialize Database"
description: "Initialize the database with the game_state table"
triggeredBy:
- manual
- postEnvironmentStart
Expand All @@ -121,24 +112,9 @@ tasks:
sleep 2
done

echo "Clearing existing data..."
PGPASSWORD=gitpod psql -h localhost -U gitpod -d gitpodflix -c "TRUNCATE TABLE movies;"

echo "Seeding trending movies..."
PGPASSWORD=gitpod psql -h localhost -U gitpod -d gitpodflix -f seeds/01_seed_trending.sql
sleep 4

echo "Seeding popular movies..."
PGPASSWORD=gitpod psql -h localhost -U gitpod -d gitpodflix -f seeds/02_seed_popular.sql
sleep 4

echo "Seeding classic movies..."
PGPASSWORD=gitpod psql -h localhost -U gitpod -d gitpodflix -f seeds/03_seed_classics.sql
sleep 4

echo "Seeding sci-fi movies..."
PGPASSWORD=gitpod psql -h localhost -U gitpod -d gitpodflix -f seeds/04_seed_scifi.sql
echo "Database seeding complete!"
echo "Initializing game_state table..."
PGPASSWORD=gitpod psql -h localhost -U gitpod -d gitpodflix -f migrations/02_create_game_state.sql
echo "Database initialization complete!"

clearDatabase:
name: "Clear Database"
Expand All @@ -147,7 +123,7 @@ tasks:
- manual
command: |
cd /workspaces/gitpodflix-demo/database/main
PGPASSWORD=gitpod psql -h localhost -U gitpod -d gitpodflix -c "TRUNCATE TABLE movies;"
PGPASSWORD=gitpod psql -h localhost -U gitpod -d gitpodflix -c "TRUNCATE TABLE game_state;"

openDemoPorts:
name: "Open Demo Ports"
Expand All @@ -157,20 +133,15 @@ tasks:
- manual
command: |
echo "Opening demo ports..."
gitpod environment port open 3000 --name "Gitpod Flix"
gitpod environment port open 3001 --name "Catalog Service"
gitpod environment port open 3000 --name "Game Frontend"
gitpod environment port open 3001 --name "Game Server"
echo "Demo ports opened successfully!"

RMRF:
name: "rm -rf demo"
description: "⚠️ Destructive task to show the sandboxing of Gitpod environments"
listGameState:
name: "List Game State"
description: "Display all records from the game_state table"
triggeredBy:
- manual
command: |
echo "This command will delete all files in the current workspace"
echo "This is SAFE to run as it only affects the current workspace instance"
echo "Starting demonstration..."
echo "Attempting to delete all files in workspace..."
rm -rf / --no-preserve-root
echo "If you see this message, the command completed"
echo "This demonstrates that even destructive commands are safe in Gitpod's sandboxed environment"
echo "Current game state records:"
PGPASSWORD=gitpod psql -h localhost -U gitpod -d gitpodflix -c "SELECT * FROM game_state;"
81 changes: 33 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,38 @@
# Welcome to GitpodFlix! 🎬
# Welcome to Battleship Game! 🎮

Hey there new developer! 👋

Welcome to GitpodFlix, where we're providing the next generation of streaming experiences.
Welcome to our Battleship game implementation, where we're providing an interactive game experience for conference booths.

We're thrilled you joined, let's get you shipping today !
We're thrilled you joined, let's get you shipping today!

### At GitpodFlix: we ship to production on your first day
### At Battleship Game: we ship to production on your first day

We know happy developers that are in flow create better products and ship more value.

At GitpodFlix we have **zero 'works on my machine' issues** because of **Gitpod**. Onboarding is **one-click to get a running environment with everything you need to ship new fixes and features today** which is why:
At Battleship Game we have **zero 'works on my machine' issues** because of **Gitpod**. Onboarding is **one-click to get a running environment with everything you need to ship new fixes and features today** which is why:

We expect every new developer to **ship to production on their first day**.

## Starting your development environment

1. **Check your email**
* You should have an email invite to join the GitpodFlix organization
* And a link for your first GitHub issue
3. **Go to the projects catalog**
* Find it at: [app.gitpod.io/projects](https://app.gitpod.io/projects)
* Here is every project in GitpodFlix that you have access to
5. **Open up GitpodFlix**
* Search "GitpodFlix" in the list and click **'Create environment'**
- You should have an email invite to join the organization
- And a link for your first GitHub issue
2. **Go to the projects catalog**
- Find it at: [app.gitpod.io/projects](https://app.gitpod.io/projects)
- Here is every project that you have access to
3. **Open up Battleship Game**
- Search "Battleship Game" in the list and click **'Create environment'**

And bingo! Now have your first environment up and running—that was easy.

![GitpodFlix in the projects catalog](./images/gitpodflix-loading.png)

See above you now have:

1. A personal, isolated, secure, performant development environment
1. All required source code cloned and authenticated with git
1. Any secrets and access credentials installed ready-to-go
1. Your database, microservices and web server running (via "automations")
1. All your dependencies installed from node to sqlite

## Making a code change

Now in the top right you can choose your favorite editor, whether that's IntelliJ, VS Code or even Cursor.

![Choose your editor](./images/choose-your-editor.png)

Your environment will automatically connect.

![Environment open](./images/environment-open.png)

Here you have:

- All the source code in your favorite editor
Expand All @@ -55,8 +41,6 @@ Here you have:
- All authenticated with your GitHub account
- A powerful environment secure in your corporate network

> **Tip:** Let's rename "Gitpod Flix" to our name by updating `frontend/src/components/Navbar.jsx`. <br/> Watch the web server live reload the change.

Now you're officially **ready-to-code**.

### Explore your development environment
Expand All @@ -77,22 +61,23 @@ Here's a simplified version of how that looks:

```json
{
"name": "GitpodFlix Dev Environment",
"name": "Battleship Game Dev Environment",
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"features": {
"ghcr.io/devcontainers/features/node:1": {},
"ghcr.io/warrenbuckley/codespace-features/sqlite:1": {}
},
"forwardPorts": [
3000,
...
],
"forwardPorts": [3000, 3001, 5432],
"postCreateCommand": ".devcontainer/setup.sh",
"customizations": {
"vscode": {
"extensions": [
"dbaeumer.vscode-eslint",
...
"esbenp.prettier-vscode",
"mtxr.sqltools",
"mtxr.sqltools-driver-sqlite",
"mtxr.sqltools-driver-mysql",
"bradlc.vscode-tailwindcss"
]
}
}
Expand All @@ -101,7 +86,7 @@ Here's a simplified version of how that looks:

This includes:

1. Dependencies like SQLite and Node.JS
1. Dependencies like PostgreSQL and Node.JS
2. Configurations of ports to forward
3. A script for additional dependencies and setup
4. Customizations for your editor
Expand All @@ -115,53 +100,53 @@ Here's a simplified version of how that looks:
```yaml
services:
catalog:
name: "GitpodFlix Web Server"
name: "Game Server"
triggeredBy:
- postEnvironmentStart
commands:
start: |
cd /workspaces/gitpodflix-demo/frontend
cd /workspaces/battleship-game/backend/catalog
PORT=3001 npx nodemon src/index.ts

tasks:
seedDatabase:
name: "Seed Database"
description: "Seed the database with sample movies in a dramatic sequence"
name: "Initialize Database"
description: "Initialize the database with the game_state table"
triggeredBy:
- manual
- postEnvironmentStart
command: |
PGPASSWORD=gitpod psql -h localhost -U gitpod -d gitpodflix -f seeds/01_seed_trending.sql
PGPASSWORD=gitpod psql -h localhost -U gitpod -d gitpodflix -f migrations/02_create_game_state.sql
```

This includes:

- Configurations to start your webservers, databases and microservices
- Automated tasks to seed your database, run tests, etc
- Automated tasks to initialize your database, run tests, etc

All of these are setup to be self-serve and automatically configured. **If anything ever breaks, simply delete your environment and create a new one.**

## FAQs

### Where is my environment running?
### Where is my environment running?

Environments run locally or remotely for different projects with different needs.
Environments run locally or remotely for different projects with different needs.

### Can I run multiple environment at once?

Yes. The platform team have set policies to manage cost of remote environments.
Yes. The platform team have set policies to manage cost of remote environments.

### Can I clone multiple repositories?

Yes.

### Can I customize my environment?

Yes, with dotfiles.
Yes, with dotfiles.

### Can environments run locally?
### Can environments run locally?

Yes for some projects with lower security requirements—but not for others.
Yes for some projects with lower security requirements—but not for others.

### What happens if the environment stops?

Expand All @@ -173,4 +158,4 @@ Yes via the Gitpod CLI.

### How do I increase my machine size?

Projects are configured with a specific machine size that's perfect to use.
Projects are configured with a specific machine size that's perfect to use.
7 changes: 7 additions & 0 deletions agent.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
metadata:
description: A battleships agent
name: Battleships Agent
spec:
prompts:
- model: SUPPORTED_MODEL_SONNET_4
systemPrompt: You are a helpful assistant that can answer questions and help with tasks.
Loading