mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-22 07:32:32 +01:00
feat(docker): backports docker configuration from main for testing.
This commit is contained in:
208
docker/README.md
Normal file
208
docker/README.md
Normal file
@@ -0,0 +1,208 @@
|
||||
# Docker for erupe
|
||||
|
||||
## Prerequisites
|
||||
|
||||
Before using Docker with erupe, you need to obtain the database schemas:
|
||||
|
||||
1. **Option A**: Copy the `schemas/` directory from the main branch
|
||||
2. **Option B**: Download from GitHub releases and set up the directory structure
|
||||
|
||||
The `schemas/` directory should be placed at the same level as the erupe project root, or you can modify the docker-compose.yml to point to wherever you place it.
|
||||
|
||||
Expected structure:
|
||||
|
||||
```text
|
||||
schemas/
|
||||
├── init.sql # Base schema
|
||||
├── update-schema/ # Version update schemas
|
||||
│ └── 9.2-update.sql
|
||||
├── patch-schema/ # Development patches
|
||||
│ └── *.sql
|
||||
└── bundled-schema/ # Optional demo data
|
||||
└── *.sql
|
||||
```
|
||||
|
||||
## Building the container
|
||||
|
||||
Run the following from the root of the source folder. In this example we give it the tag of dev to separate it from any other container versions.
|
||||
|
||||
```bash
|
||||
docker build . -t erupe:dev
|
||||
```
|
||||
|
||||
## Running the container in isolation
|
||||
|
||||
This is just running the container. You can do volume mounts into the container for the `config.json` to tell it to communicate to a database. You will need to do this also for other folders such as `bin` and `savedata`
|
||||
|
||||
```bash
|
||||
docker run erupe:dev
|
||||
```
|
||||
|
||||
## Docker compose
|
||||
|
||||
Docker compose allows you to run multiple containers at once. The docker compose in this folder has 4 services set up:
|
||||
|
||||
- **postgres** - PostgreSQL database server
|
||||
- **pgadmin** - Admin interface to make database changes
|
||||
- **erupe** - The game server
|
||||
- **web** - Apache web server for hosting static files
|
||||
|
||||
We automatically populate the database to the latest version on start. If you are updating, you will need to apply the new schemas manually.
|
||||
|
||||
### Configuration
|
||||
|
||||
Before we get started, you should make sure the database info matches what's in the docker-compose file for the environment variables `POSTGRES_PASSWORD`, `POSTGRES_USER` and `POSTGRES_DB`. You can set the host to be the service name `db`.
|
||||
|
||||
Here is an example of what you would put in the config.json if you were to leave the defaults. **It is strongly recommended to change the password.**
|
||||
|
||||
```json
|
||||
"Database": {
|
||||
"Host": "db",
|
||||
"Port": 5432,
|
||||
"User": "postgres",
|
||||
"Password": "password",
|
||||
"Database": "erupe"
|
||||
}
|
||||
```
|
||||
|
||||
Place this file at `./config.json` (in the project root)
|
||||
|
||||
You will need to do the same for your bins - place these in `./bin`
|
||||
|
||||
### Setting up the web hosted materials
|
||||
|
||||
Clone the Servers repo into `./docker/Servers`
|
||||
|
||||
Make sure your hosts are pointing to where this is hosted.
|
||||
|
||||
### Starting the server
|
||||
|
||||
Navigate to the `docker/` directory and run:
|
||||
|
||||
```bash
|
||||
cd docker
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
This boots the database, pgadmin, and the server in a detached state.
|
||||
|
||||
If you want all the logs and you want it to be in an attached state:
|
||||
|
||||
```bash
|
||||
docker-compose up
|
||||
```
|
||||
|
||||
### Accessing services
|
||||
|
||||
- **erupe server**: Configured ports (53310, 53312, 54001-54008, etc.)
|
||||
- **pgAdmin**: <http://localhost:5050>
|
||||
- Email: <user@pgadmin.com>
|
||||
- Password: password
|
||||
- **Web server**: <http://localhost:80>
|
||||
- **PostgreSQL**: <localhost:5432>
|
||||
|
||||
### Turning off the server safely
|
||||
|
||||
```bash
|
||||
docker-compose stop
|
||||
```
|
||||
|
||||
### Turning off the server destructively
|
||||
|
||||
```bash
|
||||
docker-compose down
|
||||
```
|
||||
|
||||
Make sure if you want to delete your data, you delete the folders that persisted:
|
||||
|
||||
- `./docker/savedata`
|
||||
- `./docker/db-data`
|
||||
|
||||
## Testing with Docker
|
||||
|
||||
For running integration tests with a database, use the test configuration:
|
||||
|
||||
```bash
|
||||
# Start test database
|
||||
docker-compose -f docker/docker-compose.test.yml up -d
|
||||
|
||||
# Run tests (from project root)
|
||||
go test ./...
|
||||
|
||||
# Stop test database
|
||||
docker-compose -f docker/docker-compose.test.yml down
|
||||
```
|
||||
|
||||
The test database:
|
||||
|
||||
- Runs on port 5433 (to avoid conflicts with development database)
|
||||
- Uses in-memory storage (tmpfs) for faster tests
|
||||
- Is ephemeral - data is lost when the container stops
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Q: My Postgres will not populate
|
||||
|
||||
**A:** Your `setup.sh` is maybe saved as CRLF, it needs to be saved as LF.
|
||||
|
||||
On Linux/Mac:
|
||||
|
||||
```bash
|
||||
dos2unix docker/init/setup.sh
|
||||
```
|
||||
|
||||
Or manually convert line endings in your editor.
|
||||
|
||||
### Q: I get "schemas not found" errors
|
||||
|
||||
**A:** Make sure you have the `schemas/` directory set up correctly. Check that:
|
||||
|
||||
1. The directory exists at `../schemas/` relative to the docker directory
|
||||
2. It contains `init.sql` and the subdirectories
|
||||
3. The volume mount in docker-compose.yml points to the correct location
|
||||
|
||||
### Q: The server starts but can't connect to the database
|
||||
|
||||
**A:** Ensure your `config.json` has the correct database settings:
|
||||
|
||||
- Host should be `db` (the service name in docker-compose)
|
||||
- Credentials must match the environment variables in docker-compose.yml
|
||||
|
||||
### Q: Container builds but `go run` fails
|
||||
|
||||
**A:** Check the logs with:
|
||||
|
||||
```bash
|
||||
docker-compose logs server
|
||||
```
|
||||
|
||||
Common issues:
|
||||
|
||||
- Missing or incorrect `config.json`
|
||||
- Missing `bin/` directory
|
||||
- Database not ready (health check should prevent this)
|
||||
|
||||
## Development Workflow
|
||||
|
||||
1. Make code changes on your host machine
|
||||
2. Restart the server container to pick up changes:
|
||||
|
||||
```bash
|
||||
docker-compose restart server
|
||||
```
|
||||
|
||||
3. View logs:
|
||||
|
||||
```bash
|
||||
docker-compose logs -f server
|
||||
```
|
||||
|
||||
For faster development, you can run the server outside Docker and just use Docker for the database:
|
||||
|
||||
```bash
|
||||
# Start only the database
|
||||
docker-compose up -d db
|
||||
|
||||
# Run server locally
|
||||
go run .
|
||||
```
|
||||
24
docker/docker-compose.test.yml
Normal file
24
docker/docker-compose.test.yml
Normal file
@@ -0,0 +1,24 @@
|
||||
# Docker Compose configuration for running integration tests
|
||||
# Usage: docker-compose -f docker/docker-compose.test.yml up -d
|
||||
services:
|
||||
test-db:
|
||||
image: postgres:15-alpine
|
||||
container_name: erupe-test-db
|
||||
environment:
|
||||
POSTGRES_USER: test
|
||||
POSTGRES_PASSWORD: test
|
||||
POSTGRES_DB: erupe_test
|
||||
ports:
|
||||
- "5433:5432" # Different port to avoid conflicts with main DB
|
||||
# Use tmpfs for faster tests (in-memory database)
|
||||
tmpfs:
|
||||
- /var/lib/postgresql/data
|
||||
# Mount schema files for initialization
|
||||
volumes:
|
||||
- ../schemas/:/schemas/
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U test -d erupe_test"]
|
||||
interval: 2s
|
||||
timeout: 2s
|
||||
retries: 10
|
||||
start_period: 5s
|
||||
71
docker/docker-compose.yml
Normal file
71
docker/docker-compose.yml
Normal file
@@ -0,0 +1,71 @@
|
||||
version: "3.9"
|
||||
# 1. docker-compose up db pgadmin
|
||||
# 2. Use pgadmin to restore db and also apply patch-schema
|
||||
# 3. Configure the config.json example. in docker you can point to the service name for the database i.e db
|
||||
# 4. In seperate terminal docker-compose up server
|
||||
# 5. If all went well happy hunting!
|
||||
services:
|
||||
db:
|
||||
image: postgres
|
||||
environment:
|
||||
# (Make sure these match config.json)
|
||||
- POSTGRES_USER=postgres
|
||||
- POSTGRES_PASSWORD=password
|
||||
- POSTGRES_DB=erupe
|
||||
ports:
|
||||
- "5432:5432"
|
||||
volumes:
|
||||
- ./db-data/:/var/lib/postgresql/data/
|
||||
- ../schemas/:/schemas/
|
||||
- ./init/setup.sh:/docker-entrypoint-initdb.d/setup.sh
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U postgres"]
|
||||
interval: 5s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
pgadmin:
|
||||
image: dpage/pgadmin4
|
||||
restart: always
|
||||
environment:
|
||||
PGADMIN_DEFAULT_EMAIL: user@pgadmin.com
|
||||
PGADMIN_DEFAULT_PASSWORD: password
|
||||
ports:
|
||||
- "5050:80"
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
server:
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
# If using prebuilt container change paths and config
|
||||
build:
|
||||
context: ../
|
||||
volumes:
|
||||
- ../config.json:/app/erupe/config.json
|
||||
- ../bin:/app/erupe/bin
|
||||
- ./savedata:/app/erupe/savedata
|
||||
ports:
|
||||
# (Make sure these match config.json)
|
||||
- "53312:53312" #Sign V1
|
||||
- "8080:8080" #Sign V2
|
||||
- "53310:53310" #Entrance
|
||||
# Channels
|
||||
- "54001:54001"
|
||||
- "54002:54002"
|
||||
- "54003:54003"
|
||||
- "54004:54004"
|
||||
- "54005:54005"
|
||||
- "54006:54006"
|
||||
- "54007:54007"
|
||||
- "54008:54008"
|
||||
web:
|
||||
image: httpd:latest
|
||||
container_name: my-apache-app
|
||||
ports:
|
||||
- '80:80'
|
||||
volumes:
|
||||
- ./Servers:/usr/local/apache2/htdocs
|
||||
depends_on:
|
||||
db:
|
||||
condition: service_healthy
|
||||
22
docker/init/setup.sh
Executable file
22
docker/init/setup.sh
Executable file
@@ -0,0 +1,22 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
echo "INIT!"
|
||||
pg_restore --username="$POSTGRES_USER" --dbname="$POSTGRES_DB" --verbose /schemas/init.sql
|
||||
|
||||
|
||||
|
||||
echo "Updating!"
|
||||
|
||||
for file in /schemas/update-schema/*
|
||||
do
|
||||
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" -1 -f $file
|
||||
done
|
||||
|
||||
|
||||
|
||||
echo "Patching!"
|
||||
|
||||
for file in /schemas/patch-schema/*
|
||||
do
|
||||
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" -1 -f $file
|
||||
done
|
||||
Reference in New Issue
Block a user