From 810854c397c828362656303b0ea2ff1d2662debf Mon Sep 17 00:00:00 2001 From: Patrik Nordwall <patrik.nordwall@gmail.com> Date: Tue, 8 Aug 2023 02:19:46 +0200 Subject: [PATCH] chore: docker-compose postgres healthcheck (#890) Co-authored-by: Peter Vlugter <59895+pvlugter@users.noreply.github.com> --- .github/workflows/integration-tests-r2dbc.yml | 4 +--- .../paradox/guide/1-event-sourced-shopping-cart.md | 2 +- .../src/main/paradox/guide/2-service-to-service.md | 8 ++++---- .../src/main/paradox/guide/3-active-active.md | 4 ++-- docker-files/docker-compose-postgres.yml | 6 ++++++ .../grpc/shopping-analytics-service-java/README.md | 2 +- .../docker-compose.yml | 6 ++++++ .../grpc/shopping-analytics-service-scala/README.md | 2 +- .../docker-compose.yml | 6 ++++++ samples/grpc/shopping-cart-service-java/README.md | 2 +- .../shopping-cart-service-java/docker-compose.yml | 6 ++++++ samples/grpc/shopping-cart-service-scala/README.md | 2 +- .../shopping-cart-service-scala/docker-compose.yml | 6 ++++++ .../replicated/shopping-cart-service-java/README.md | 2 +- .../shopping-cart-service-java/docker-compose.yml | 12 ++++++++++++ .../replicated/shopping-cart-service-scala/README.md | 2 +- .../shopping-cart-service-scala/docker-compose.yml | 12 ++++++++++++ 17 files changed, 68 insertions(+), 16 deletions(-) diff --git a/.github/workflows/integration-tests-r2dbc.yml b/.github/workflows/integration-tests-r2dbc.yml index 7bba9cd9b..057582b15 100644 --- a/.github/workflows/integration-tests-r2dbc.yml +++ b/.github/workflows/integration-tests-r2dbc.yml @@ -48,9 +48,7 @@ jobs: - name: Start DB run: |- - docker-compose -f docker-files/docker-compose-postgres.yml up -d - # TODO: could we poll the port instead of sleep? - sleep 10 + docker compose -f docker-files/docker-compose-postgres.yml up --wait docker exec -i postgres_db psql -U postgres -t < akka-projection-r2dbc/ddl-scripts/create_tables_postgres.sql - name: Run integration tests with with Scala and Java ${{ matrix.jdkVersion }} diff --git a/akka-distributed-cluster-docs/src/main/paradox/guide/1-event-sourced-shopping-cart.md b/akka-distributed-cluster-docs/src/main/paradox/guide/1-event-sourced-shopping-cart.md index 9f79d1ae6..541608cb5 100644 --- a/akka-distributed-cluster-docs/src/main/paradox/guide/1-event-sourced-shopping-cart.md +++ b/akka-distributed-cluster-docs/src/main/paradox/guide/1-event-sourced-shopping-cart.md @@ -147,7 +147,7 @@ Before running the sample locally you will need to run a PostgreSQL instance in `docker-compose.yml`. Run it and create the needed database schema: ```shell -docker-compose up -d +docker-compose up --wait docker exec -i postgres_db psql -U postgres -t < ddl-scripts/create_tables.sql ``` diff --git a/akka-distributed-cluster-docs/src/main/paradox/guide/2-service-to-service.md b/akka-distributed-cluster-docs/src/main/paradox/guide/2-service-to-service.md index 16bac735d..605773bc7 100644 --- a/akka-distributed-cluster-docs/src/main/paradox/guide/2-service-to-service.md +++ b/akka-distributed-cluster-docs/src/main/paradox/guide/2-service-to-service.md @@ -193,7 +193,7 @@ your own workstation. Docker, a JDK and @java[maven]@scala[sbt] is all that need 1. Start a local PostgresSQL server on default port 5432. The `docker-compose.yml` included in the shopping-cart project starts everything required for running locally. ```shell - docker-compose up -d + docker-compose up --wait # creates the tables needed for Akka Persistence # as well as the offset store table for Akka Projection @@ -250,7 +250,7 @@ your own workstation. Docker, a JDK and @java[maven]@scala[sbt] is all that need 1. Start a local PostgresSQL server on default port 5432. The included `docker-compose.yml` starts everything required for running locally. ```shell - docker-compose up -d + docker-compose up --wait # creates the tables needed for Akka Persistence # as well as the offset store table for Akka Projection @@ -315,7 +315,7 @@ your own workstation. Docker, a JDK and @java[maven]@scala[sbt] is all that need 1. Start a local PostgresSQL server on default port 5432. The included `docker-compose.yml` starts everything required for running locally. Note that for convenience this service and the shopping cart service is sharing the same database, in an actual service consuming events the consuming services are expected to have their own separate databases. ```shell - docker-compose up -d + docker-compose up --wait # creates the tables needed for Akka Persistence # as well as the offset store table for Akka Projection @@ -341,7 +341,7 @@ your own workstation. Docker, a JDK and @java[maven]@scala[sbt] is all that need 1. Start a local PostgresSQL server on default port 5432. The included `docker-compose.yml` starts everything required for running locally. Note that for convenience this service and the shopping cart service is sharing the same database, in an actual service consuming events the consuming services are expected to have their own separate databases. ```shell - docker-compose up -d + docker-compose up --wait # creates the tables needed for Akka Persistence # as well as the offset store table for Akka Projection diff --git a/akka-distributed-cluster-docs/src/main/paradox/guide/3-active-active.md b/akka-distributed-cluster-docs/src/main/paradox/guide/3-active-active.md index 827fc7284..ec8a7a7a1 100644 --- a/akka-distributed-cluster-docs/src/main/paradox/guide/3-active-active.md +++ b/akka-distributed-cluster-docs/src/main/paradox/guide/3-active-active.md @@ -159,7 +159,7 @@ The complete sample can be downloaded from github, the replicated shopping cart: 1. Start two local PostgresSQL servers, on ports 5101 and 5201. The included `docker-compose.yml` starts everything required for running locally. ```shell - docker-compose up -d + docker-compose up --wait # creates the tables needed for Akka Persistence # as well as the offset store table for Akka Projection @@ -236,7 +236,7 @@ The complete sample can be downloaded from github, the replicated shopping cart: 1. Start two local PostgresSQL servers, on ports 5101 and 5201. The included `docker-compose.yml` starts everything required for running locally. ```shell - docker-compose up -d + docker-compose up --wait # creates the tables needed for Akka Persistence # as well as the offset store table for Akka Projection diff --git a/docker-files/docker-compose-postgres.yml b/docker-files/docker-compose-postgres.yml index 062c62444..366c5a10a 100644 --- a/docker-files/docker-compose-postgres.yml +++ b/docker-files/docker-compose-postgres.yml @@ -8,3 +8,9 @@ services: environment: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres + healthcheck: + test: ['CMD', 'pg_isready', "-q", "-d", "postgres", "-U", "postgres"] + interval: 5s + retries: 5 + start_period: 5s + timeout: 5s diff --git a/samples/grpc/shopping-analytics-service-java/README.md b/samples/grpc/shopping-analytics-service-java/README.md index 3bfe6b669..35ce8a2a8 100644 --- a/samples/grpc/shopping-analytics-service-java/README.md +++ b/samples/grpc/shopping-analytics-service-java/README.md @@ -3,7 +3,7 @@ 1. Start a local PostgresSQL server on default port 5432. The included `docker-compose.yml` starts everything required for running locally. Note that for convenience this service and the shopping cart service is sharing the same database, in an actual service consuming events the consuming services are expected to have their own separate databases. ```shell - docker-compose up -d + docker-compose up --wait # creates the tables needed for Akka Persistence # as well as the offset store table for Akka Projection diff --git a/samples/grpc/shopping-analytics-service-java/docker-compose.yml b/samples/grpc/shopping-analytics-service-java/docker-compose.yml index 062c62444..366c5a10a 100644 --- a/samples/grpc/shopping-analytics-service-java/docker-compose.yml +++ b/samples/grpc/shopping-analytics-service-java/docker-compose.yml @@ -8,3 +8,9 @@ services: environment: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres + healthcheck: + test: ['CMD', 'pg_isready', "-q", "-d", "postgres", "-U", "postgres"] + interval: 5s + retries: 5 + start_period: 5s + timeout: 5s diff --git a/samples/grpc/shopping-analytics-service-scala/README.md b/samples/grpc/shopping-analytics-service-scala/README.md index 316e1f174..59437c3c3 100644 --- a/samples/grpc/shopping-analytics-service-scala/README.md +++ b/samples/grpc/shopping-analytics-service-scala/README.md @@ -3,7 +3,7 @@ 1. Start a local PostgresSQL server on default port 5432. The included `docker-compose.yml` starts everything required for running locally. Note that for convenience this service and the shopping cart service is sharing the same database, in an actual service consuming events the consuming services are expected to have their own separate databases. ```shell - docker-compose up -d + docker-compose up --wait # creates the tables needed for Akka Persistence # as well as the offset store table for Akka Projection diff --git a/samples/grpc/shopping-analytics-service-scala/docker-compose.yml b/samples/grpc/shopping-analytics-service-scala/docker-compose.yml index 062c62444..366c5a10a 100644 --- a/samples/grpc/shopping-analytics-service-scala/docker-compose.yml +++ b/samples/grpc/shopping-analytics-service-scala/docker-compose.yml @@ -8,3 +8,9 @@ services: environment: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres + healthcheck: + test: ['CMD', 'pg_isready', "-q", "-d", "postgres", "-U", "postgres"] + interval: 5s + retries: 5 + start_period: 5s + timeout: 5s diff --git a/samples/grpc/shopping-cart-service-java/README.md b/samples/grpc/shopping-cart-service-java/README.md index ac7a5cc48..aa37ddc9d 100644 --- a/samples/grpc/shopping-cart-service-java/README.md +++ b/samples/grpc/shopping-cart-service-java/README.md @@ -3,7 +3,7 @@ 1. Start a local PostgresSQL server on default port 5432. The included `docker-compose.yml` starts everything required for running locally. ```shell - docker-compose up -d + docker-compose up --wait # creates the tables needed for Akka Persistence # as well as the offset store table for Akka Projection diff --git a/samples/grpc/shopping-cart-service-java/docker-compose.yml b/samples/grpc/shopping-cart-service-java/docker-compose.yml index 062c62444..366c5a10a 100644 --- a/samples/grpc/shopping-cart-service-java/docker-compose.yml +++ b/samples/grpc/shopping-cart-service-java/docker-compose.yml @@ -8,3 +8,9 @@ services: environment: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres + healthcheck: + test: ['CMD', 'pg_isready', "-q", "-d", "postgres", "-U", "postgres"] + interval: 5s + retries: 5 + start_period: 5s + timeout: 5s diff --git a/samples/grpc/shopping-cart-service-scala/README.md b/samples/grpc/shopping-cart-service-scala/README.md index fb289747b..f3324f7b8 100644 --- a/samples/grpc/shopping-cart-service-scala/README.md +++ b/samples/grpc/shopping-cart-service-scala/README.md @@ -3,7 +3,7 @@ 1. Start a local PostgresSQL server on default port 5432. The included `docker-compose.yml` starts everything required for running locally. ```shell - docker-compose up -d + docker-compose up --wait # creates the tables needed for Akka Persistence # as well as the offset store table for Akka Projection diff --git a/samples/grpc/shopping-cart-service-scala/docker-compose.yml b/samples/grpc/shopping-cart-service-scala/docker-compose.yml index 062c62444..366c5a10a 100644 --- a/samples/grpc/shopping-cart-service-scala/docker-compose.yml +++ b/samples/grpc/shopping-cart-service-scala/docker-compose.yml @@ -8,3 +8,9 @@ services: environment: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres + healthcheck: + test: ['CMD', 'pg_isready', "-q", "-d", "postgres", "-U", "postgres"] + interval: 5s + retries: 5 + start_period: 5s + timeout: 5s diff --git a/samples/replicated/shopping-cart-service-java/README.md b/samples/replicated/shopping-cart-service-java/README.md index 710f8cc85..ae4185b24 100644 --- a/samples/replicated/shopping-cart-service-java/README.md +++ b/samples/replicated/shopping-cart-service-java/README.md @@ -3,7 +3,7 @@ 1. Start two local PostgresSQL servers, on ports 5101 and 5201. The included `docker-compose.yml` starts everything required for running locally. ```shell - docker-compose up -d + docker-compose up --wait # creates the tables needed for Akka Persistence # as well as the offset store table for Akka Projection diff --git a/samples/replicated/shopping-cart-service-java/docker-compose.yml b/samples/replicated/shopping-cart-service-java/docker-compose.yml index bf9c444bc..b13c5bda8 100644 --- a/samples/replicated/shopping-cart-service-java/docker-compose.yml +++ b/samples/replicated/shopping-cart-service-java/docker-compose.yml @@ -8,6 +8,12 @@ services: environment: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres + healthcheck: + test: ['CMD', 'pg_isready', "-q", "-d", "postgres", "-U", "postgres"] + interval: 5s + retries: 5 + start_period: 5s + timeout: 5s postgres-db-2: image: postgres:latest container_name: postgres_db_2 @@ -16,3 +22,9 @@ services: environment: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres + healthcheck: + test: ['CMD', 'pg_isready', "-q", "-d", "postgres", "-U", "postgres"] + interval: 5s + retries: 5 + start_period: 5s + timeout: 5s diff --git a/samples/replicated/shopping-cart-service-scala/README.md b/samples/replicated/shopping-cart-service-scala/README.md index 1f5cd462a..4ee9342d2 100644 --- a/samples/replicated/shopping-cart-service-scala/README.md +++ b/samples/replicated/shopping-cart-service-scala/README.md @@ -3,7 +3,7 @@ 1. Start two local PostgresSQL servers, on ports 5101 and 5201. The included `docker-compose.yml` starts everything required for running locally. ```shell - docker-compose up -d + docker-compose up --wait # creates the tables needed for Akka Persistence # as well as the offset store table for Akka Projection diff --git a/samples/replicated/shopping-cart-service-scala/docker-compose.yml b/samples/replicated/shopping-cart-service-scala/docker-compose.yml index bf9c444bc..b13c5bda8 100644 --- a/samples/replicated/shopping-cart-service-scala/docker-compose.yml +++ b/samples/replicated/shopping-cart-service-scala/docker-compose.yml @@ -8,6 +8,12 @@ services: environment: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres + healthcheck: + test: ['CMD', 'pg_isready', "-q", "-d", "postgres", "-U", "postgres"] + interval: 5s + retries: 5 + start_period: 5s + timeout: 5s postgres-db-2: image: postgres:latest container_name: postgres_db_2 @@ -16,3 +22,9 @@ services: environment: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres + healthcheck: + test: ['CMD', 'pg_isready', "-q", "-d", "postgres", "-U", "postgres"] + interval: 5s + retries: 5 + start_period: 5s + timeout: 5s