Add cross-platform Docker Compose stack and validate runtime health
This commit is contained in:
parent
a9b43aae99
commit
85664c1b75
5 changed files with 129 additions and 12 deletions
10
.env.example
Normal file
10
.env.example
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
# Copy to .env and adjust values before `docker compose up -d`
|
||||
|
||||
# PostgreSQL
|
||||
POSTGRES_USER=postgres
|
||||
POSTGRES_PASSWORD=change_me_postgres_password
|
||||
POSTGRES_DB=game
|
||||
|
||||
# MongoDB (required by the app)
|
||||
MONGO_ROOT_USERNAME=wingsemu
|
||||
MONGO_ROOT_PASSWORD=change_me_mongo_password
|
||||
44
README.md
44
README.md
|
|
@ -116,22 +116,42 @@ Let's skip it using `Skip tutorial` button and... that's it - Congratulations!
|
|||
|
||||

|
||||
|
||||
### Running Docker
|
||||
### Running Docker (Windows + Linux)
|
||||
|
||||
To run PostgreSQL, Redis, MongoDB and MQTT Broker for our server, we have to create [Docker containers](https://www.docker.com/resources/what-container).
|
||||
To run PostgreSQL, Redis, MongoDB and MQTT Broker for our server, use Docker Compose (cross-platform).
|
||||
|
||||
- **PowerShell**
|
||||
- Go to the `.server/scripts/Docker` directory
|
||||
- For each file in the directory, click right mouse button on the file and choose `Run with PowerShell`
|
||||
- 
|
||||
- **Terminal**
|
||||
- Go to the `.server/scripts/Docker` directory
|
||||
- Open each `.ps1` file, select the entire script (starts with `docker run`) and copy it into Terminal (you can use this script anywhere) and then press [`ENTER`] key:
|
||||
- 
|
||||
1. Copy env file:
|
||||
|
||||
After successfully using the commands, you should see 4 new containers in your Docker Hub.
|
||||
```bash
|
||||
cp .env.example .env
|
||||
```
|
||||
|
||||

|
||||
2. Edit `.env` and set strong secrets (`POSTGRES_PASSWORD`, `MONGO_ROOT_PASSWORD`).
|
||||
|
||||
3. Start dependencies:
|
||||
|
||||
```bash
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
4. Check status:
|
||||
|
||||
```bash
|
||||
docker compose ps
|
||||
```
|
||||
|
||||
5. Stop everything:
|
||||
|
||||
```bash
|
||||
docker compose down
|
||||
```
|
||||
|
||||
Optional helper scripts (Linux/macOS):
|
||||
|
||||
```bash
|
||||
./scripts/docker-up.sh
|
||||
./scripts/docker-down.sh
|
||||
```
|
||||
|
||||
___
|
||||
|
||||
|
|
|
|||
68
docker-compose.yml
Normal file
68
docker-compose.yml
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
services:
|
||||
postgres:
|
||||
image: postgres:13
|
||||
container_name: wingsemu-postgres
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
|
||||
POSTGRES_DB: ${POSTGRES_DB:-game}
|
||||
POSTGRES_USER: ${POSTGRES_USER:-postgres}
|
||||
ports:
|
||||
- "5432:5432"
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-postgres}"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 10
|
||||
|
||||
redis:
|
||||
image: redis:7-alpine
|
||||
container_name: wingsemu-redis
|
||||
restart: unless-stopped
|
||||
command: ["redis-server", "--notify-keyspace-events", "Kx", "--appendonly", "yes"]
|
||||
ports:
|
||||
- "6379:6379"
|
||||
volumes:
|
||||
- redis_data:/data
|
||||
healthcheck:
|
||||
test: ["CMD", "redis-cli", "ping"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 10
|
||||
|
||||
mongodb:
|
||||
image: mongo:6
|
||||
container_name: wingsemu-mongodb
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
MONGO_INITDB_ROOT_USERNAME: ${MONGO_ROOT_USERNAME}
|
||||
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_ROOT_PASSWORD}
|
||||
ports:
|
||||
- "27017:27017"
|
||||
volumes:
|
||||
- mongodb_data:/data/db
|
||||
healthcheck:
|
||||
test: ["CMD", "mongosh", "--quiet", "--eval", "db.runCommand({ ping: 1 }).ok"]
|
||||
interval: 15s
|
||||
timeout: 10s
|
||||
retries: 10
|
||||
|
||||
mqtt:
|
||||
image: emqx/emqx:latest
|
||||
container_name: wingsemu-mqtt
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "1883:1883"
|
||||
- "18083:18083"
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "emqx ctl status | grep -q 'is started'"]
|
||||
interval: 15s
|
||||
timeout: 10s
|
||||
retries: 10
|
||||
|
||||
volumes:
|
||||
postgres_data:
|
||||
redis_data:
|
||||
mongodb_data:
|
||||
6
scripts/docker-down.sh
Normal file
6
scripts/docker-down.sh
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
docker compose down
|
||||
|
||||
echo "[OK] Containers stopped"
|
||||
13
scripts/docker-up.sh
Normal file
13
scripts/docker-up.sh
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
if [[ ! -f .env ]]; then
|
||||
echo "[INFO] .env not found. Creating from .env.example"
|
||||
cp .env.example .env
|
||||
echo "[WARN] Please edit .env secrets before using in production."
|
||||
fi
|
||||
|
||||
docker compose up -d
|
||||
|
||||
echo "[OK] Containers started"
|
||||
docker compose ps
|
||||
Loading…
Reference in a new issue