Skip to content

Commit

Permalink
WIP - automatically start docker DB
Browse files Browse the repository at this point in the history
  • Loading branch information
DanVanAtta committed Nov 24, 2023
1 parent 70b40d0 commit d0a6c27
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 68 deletions.
21 changes: 0 additions & 21 deletions .build/setup-database

This file was deleted.

13 changes: 13 additions & 0 deletions .docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: '3'
services:
database:
image: postgres:10
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
volumes:
- ./init.sql:/docker-entrypoint-initdb.d/01-init.sql
ports:
- 5432:5432

5 changes: 5 additions & 0 deletions .docker/init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
create user lobby_user password 'lobby';
create database lobby_db owner lobby_user;

create user error_report_user password 'error_report';
create database error_report owner error_report_user;
34 changes: 19 additions & 15 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,30 @@ on:
jobs:
build:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:10
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: postgres
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
# services:
# postgres:
# image: postgres:10
# env:
# POSTGRES_USER: postgres
# POSTGRES_PASSWORD: postgres
# POSTGRES_DB: postgres
# ports:
# - 5432:5432
# options: >-
# --health-cmd pg_isready
# --health-interval 10s
# --health-timeout 5s
# --health-retries 5
steps:
- uses: actions/checkout@v4
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 11
- uses: isbang/[email protected]
with:
compose-file: ".docker/docker-compose.yml"
- name: Run Build Checks
run: ./verify
run: ./verify --exclude-task composeUp

7 changes: 7 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ plugins {
id 'com.github.ben-manes.versions' version '0.50.0'
id 'io.franzbecker.gradle-lombok' version '5.0.0' apply false
id 'com.diffplug.spotless' version '6.22.0' apply false
id 'com.avast.gradle.docker-compose' version '0.17.5'
}

apply plugin: 'eclipse'
apply plugin: 'docker-compose'


ext {
schemasDir = file('config/triplea/schemas')
Expand Down Expand Up @@ -206,6 +209,7 @@ subprojects {
description = 'Runs integration tests.'
group = 'verification'

dependsOn(":composeUp")
dependsOn(":spitfire-server:database:flywayMigrateLobbyDb")
dependsOn(":spitfire-server:database:flywayMigrateErrorReportDb")

Expand All @@ -223,4 +227,7 @@ subprojects {
// - 'check' should run ALL validations, tests, spotlessChecks, everything..
check.dependsOn testAll

dockerCompose {
useComposeFiles = ['.docker/docker-compose.yml' ]
}
}
39 changes: 13 additions & 26 deletions docs/development/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,18 @@ For more detailed steps on building the project with CLI, see:
IDE setup has the needed configurations for the project to compile. There are checked in launchers that
IDEA should automatically find. Look in 'run configurations' to launch the game-client.

## Running all tests locally before PR (CLI)
## Running build checks locally (CLI)

Verify will run all checks (including additional custom checks):
```
./game-app/run/check
./verify
```

## Run Tests
Tests are split between those that need a database (which runs on docker), vs those that do not.

```
./gradlew test
```

## Run Tests that need a running database

```
./gradlew testWithDatabase
```
- `./gradlew test`: Runs all tests that do not require database
- `./gradlew testWithDatabase`: Runs tests that require a local database
- `./gradlew allTest`: Runs all tests


## Run Formatting
Expand All @@ -68,7 +63,7 @@ from IDE. Everything can also be formatted from CLI:
./gradew spotlessApply
```

PR builds will fail if the code is not formatted with spotless.
PR builds will fail if the code is not formatted.


## Code Conventions (Style Guide)
Expand All @@ -84,24 +79,16 @@ Please be sure to check these out so that you can fit the general style of the p
Local database is needed to run the servers (lobby).

```bash
# requires docker to be installed
./spitfire-server/database/start_docker_db
## start database
./gradlew composeUp
```

This will launch a postgres database on docker and will install the latest
TripleA schema with a small sample dataset for local testing.

After the database is launched you can:
- run the full set of tests
- launch a local lobby

### Launch local lobby

Lobby can be launched via the checked-in run configurations from IDE, or from CLI:
```bash
./gradlew :spitfire-server:dropwizard-server:run
```

To connect to local lobby, from the game client:
- 'settings > testing > local lobby'
- play online
Expand Down Expand Up @@ -134,7 +121,7 @@ The deployment code is inside of the '[/infrastructure](./infrastructure)' folde
We use [ansible](https://www.ansible.com/) to execute deployments.

You can test out deployment code by first launching a virtual machine and then running a deployment
against that virtual machine. See '[infrastructure/vagrant/README.md](./infrastructure/vagrant/README.md)'
against that virtual machine. See '[infrastructure/vagrant/REAMDE.md](./infrastructure/vagrant/REAMDE.md)'
for more information.

# Pitfalls and Pain Points to be aware of
Expand Down Expand Up @@ -177,7 +164,7 @@ In short:

### Google formatter does not work

IDEA needs a tweak to overcome a JDk9 problem. See the IDE setup for the needed config that needs
to be added to your vmoptions file.
IDEA needs a tweak to overcome a JDk9 problem. The google java format plugin should show a warning dialog about
this if it is a problem.


2 changes: 0 additions & 2 deletions spitfire-server/dropwizard-server/README.md

This file was deleted.

2 changes: 2 additions & 0 deletions spitfire-server/dropwizard-server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ ext {
releasesDir = file("$buildDir/releases")
}

run.dependsOn rootProject.composeUp

jar {
manifest {
attributes 'Main-Class': mainClassName
Expand Down
7 changes: 3 additions & 4 deletions verify
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ function checkDependency {
fi
}

# Installs python
# Installs docker & docker-compose using pip
# Adds current user to 'docker' group (allows for sudo-less docker)
# Installs Docker and dependencies
# Docker is installed through python, we install python & pip first, then docker.
# Last, we add current user to the 'docker' group to enable sudo-less docker.
function installDocker {
echo "Installing python and pip, a dependency of docker"
if hash yum; then
Expand Down Expand Up @@ -49,7 +49,6 @@ set -o pipefail
set -eu

checkDependency "docker" || installDocker
"$scriptDir/.build/setup-database"
"$scriptDir/gradlew" check $@
"$scriptDir/.build/find-unused-dbunit-datasets"
"$scriptDir/.build/code-convention-checks/check-custom-style" spitfire-server

0 comments on commit d0a6c27

Please sign in to comment.