Skip to content

Commit

Permalink
Merge pull request #4 from isel-leic-daw/feature/main/use-docker-compose
Browse files Browse the repository at this point in the history
gh-2: adds docker compose to the github action tests
  • Loading branch information
pmhsfelix authored Oct 3, 2022
2 parents 9e01907 + 2d37f02 commit 5ad883e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ jobs:
with:
java-version: 17
- name: Build with Gradle
run: code/tic-tac-tow-service/gradlew -p code/tic-tac-tow-service ktlint
run: code/tic-tac-tow-service/gradlew -p code/tic-tac-tow-service check
15 changes: 15 additions & 0 deletions code/tic-tac-tow-service/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ tasks.withType<Test> {
useJUnitPlatform()
}

task<Exec>("dbTestsUp") {
commandLine("docker-compose", "up", "-d", "--build", "--force-recreate", "db-tests")
}

task<Exec>("dbTestsWait") {
commandLine("docker", "exec", "db-tests", "/app/bin/wait-for-postgres.sh", "localhost")
dependsOn("dbTestsUp")
}

task<Exec>("dbTestsDown") {
commandLine("docker-compose", "down")
}

// from https://pinterest.github.io/ktlint/install/integrations/#custom-gradle-integration-with-kotlin-dsl
val outputDir = "${project.buildDir}/reports/ktlint/"
val inputFiles = project.fileTree(mapOf("dir" to "src", "include" to "**/*.kt"))
Expand All @@ -66,4 +79,6 @@ val ktlintCheck by tasks.creating(JavaExec::class) {

tasks.named("check") {
dependsOn(ktlintCheck)
dependsOn("dbTestsWait")
finalizedBy("dbTestsDown")
}
3 changes: 3 additions & 0 deletions code/tic-tac-tow-service/tests/Dockerfile-db-test
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ WORKDIR /app
COPY sql/create-schema.sql /docker-entrypoint-initdb.d/1_create.sql
COPY sql/insert-test-data.sql /docker-entrypoint-initdb.d/2_insert-test-data.sql

COPY --chown=postgres:postgres ./tests/scripts/wait-for-postgres.sh ./bin/wait-for-postgres.sh
RUN chmod +x ./bin/wait-for-postgres.sh

EXPOSE 5432
17 changes: 17 additions & 0 deletions code/tic-tac-tow-service/tests/scripts/wait-for-postgres.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh
# wait-for-postgres.sh host cmd

set -e

host="$1"
shift
cmd="$@"

>&2 echo "waiting for postgres on $host"
until pg_isready -h $host; do
>&2 echo "Postgres is unavailable - sleeping"
sleep 1
done

>&2 echo "Postgres is up - executing command '$cmd'"
exec $cmd

0 comments on commit 5ad883e

Please sign in to comment.