From 5bd287dfa9fed285c3855980695f65a8fa7eeaf3 Mon Sep 17 00:00:00 2001 From: Thomas Hilzendegen Date: Thu, 13 Jun 2024 09:43:15 +0200 Subject: [PATCH] refactor(docker): improve compose setup --- CONTRIBUTING.md | 1 - docs/development-getting-started.md | 4 +- .../Dockerfile | 4 +- src/docker/docker-compose.yml | 134 +++++++++--------- 4 files changed, 71 insertions(+), 72 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7f096947a..bc408cb6d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -88,7 +88,6 @@ The following is the list of supported scopes: - **statistics** - **interceptor** - **protocols** -- _TBD_ There are currently a few exceptions to the "use package name" rule: diff --git a/docs/development-getting-started.md b/docs/development-getting-started.md index bba3554f4..344929904 100644 --- a/docs/development-getting-started.md +++ b/docs/development-getting-started.md @@ -7,8 +7,8 @@ _Note:_ The containers in this repository are intended for **demo and example** encouraged to create your own host applications tailored and configured to your specific needs and to build and use your own container images. -A docker compose file is provided to build all the docker images (`src/docker/docker-compose.yml`). You can build the images -with the `docker compose build` command. An environment variable `RABBITMQ_ERLANG_COOKIE` needs to be set. +A docker compose file is provided to build all the docker images (`src/docker/docker-compose.yml`). You can build the +images with the `docker compose build` command. ## First time Development & Test-Setup diff --git a/src/docker/Thinktecture.Relay.Server.Docker/Dockerfile b/src/docker/Thinktecture.Relay.Server.Docker/Dockerfile index b53a9bc5b..fa24846a7 100644 --- a/src/docker/Thinktecture.Relay.Server.Docker/Dockerfile +++ b/src/docker/Thinktecture.Relay.Server.Docker/Dockerfile @@ -58,8 +58,8 @@ COPY --chown=relay --from=build /app . EXPOSE 5000 ENV ASPNETCORE_URLS=http://+:5000 -ENV RabbitMq__ClusterHosts=relay_transport_rabbitmq1,relay_transport_rabbitmq2 +ENV RabbitMq__ClusterHosts=relay-transport-rabbitmq-1,relay-transport-rabbitmq-2 ENV BodyStore__StoragePath=/var/bodystore -ENV Authentication__Authority=http://relayidentityprovider:5002/realms/relayserver +ENV Authentication__Authority=http://relay-identityprovider:5002/realms/relayserver ENTRYPOINT ["dotnet", "Thinktecture.Relay.Server.Docker.dll"] diff --git a/src/docker/docker-compose.yml b/src/docker/docker-compose.yml index 5fcdd3657..c7e476087 100644 --- a/src/docker/docker-compose.yml +++ b/src/docker/docker-compose.yml @@ -5,55 +5,55 @@ x-defaults: &defaults x-rabbit-defaults: &rabbit-defaults <<: *defaults image: rabbitmq:management-alpine - secrets: + configs: - source: erlang-cookie target: /var/lib/rabbitmq/.erlang.cookie mode: 0600 x-rabbit-env: &rabbit-env RABBITMQ_DEFAULT_USER: guest RABBITMQ_DEFAULT_PASS: guest - RABBITMQ_SERVER_START_ARGS: -rabbit cluster_nodes {['rabbit@relay_transport_rabbitmq1','rabbit@relay_transport_rabbitmq2'],disc} cluster_name rabbit@relay_transport + RABBITMQ_SERVER_START_ARGS: -rabbit cluster_nodes {['rabbit@relay-transport-rabbitmq-1','rabbit@relay-transport-rabbitmq-2'],disc} cluster_name rabbit@relayserver x-db-connection: &db-connection DatabaseType: ${RELAYSERVER_DATABASE_TYPE:-PostgreSql} # PostgreSql or SqlServer - ConnectionStrings__PostgreSql: host=relay_persistence_postgresql;database=relayserver;username=relayserver;password= - ConnectionStrings__SqlServer: Server=relay_persistence_sqlserver;Database=relayserver;User Id=sa;Password= + ConnectionStrings__PostgreSql: host=relay-persistence-postgresql;database=relayserver;username=relayserver;password= + ConnectionStrings__SqlServer: Server=relay-persistence-sqlserver;Database=relayserver;User Id=sa;Password= x-logging: &logging Serilog__MinimumLevel__Default: Verbose Serilog__MinimumLevel__Override__Microsoft: Warning Serilog__MinimumLevel__Override__System: Warning Serilog__WriteTo__0__Name: Seq - Serilog__WriteTo__0__Args__ServerUrl: http://relay_logging_seq + Serilog__WriteTo__0__Args__ServerUrl: http://relay-logging-seq -secrets: +configs: erlang-cookie: - environment: RABBITMQ_ERLANG_COOKIE + content: VEhJUyBJUyBUSElOS1RFQ1RVUkUh services: - relay_transport_rabbitmq1: + relay-transport-rabbitmq-1: <<: *rabbit-defaults - container_name: relay_transport_rabbitmq1 + container_name: relay-transport-rabbitmq-1 ports: - "5672:5672" - "15672:15672" environment: <<: *rabbit-env - RABBITMQ_NODENAME: rabbit@relay_transport_rabbitmq1 - relay_transport_rabbitmq2: + RABBITMQ_NODENAME: rabbit@relay-transport-rabbitmq-1 + relay-transport-rabbitmq-2: <<: *rabbit-defaults - container_name: relay_transport_rabbitmq2 + container_name: relay-transport-rabbitmq-2 ports: - "5673:5672" - "15673:15672" environment: <<: *rabbit-env - RABBITMQ_NODENAME: rabbit@relay_transport_rabbitmq2 + RABBITMQ_NODENAME: rabbit@relay-transport-rabbitmq-2 - relay_logging_seq: + relay-logging-seq: <<: *defaults image: datalust/seq - container_name: relay_logging_seq + container_name: relay-logging-seq ports: - "5341:80" environment: @@ -61,10 +61,10 @@ services: volumes: - seq-data:/data - relay_persistence_postgresql: + relay-persistence-postgresql: <<: *defaults image: postgres:15-alpine - container_name: relay_persistence_postgresql + container_name: relay-persistence-postgresql ports: - "5432:5432" environment: @@ -81,10 +81,10 @@ services: timeout: 60s retries: 10 start_period: 10s - relay_persistence_sqlserver: + relay-persistence-sqlserver: <<: *defaults image: mcr.microsoft.com/mssql/server:2022-latest - container_name: relay_persistence_sqlserver + container_name: relay-persistence-sqlserver user: root platform: linux/amd64 ports: @@ -104,50 +104,50 @@ services: timeout: 60s retries: 10 start_period: 10s - relay_server_migrations: + relay-server-migrations: <<: *defaults - image: relay_server + image: relay-server build: context: .. dockerfile: ./docker/Thinktecture.Relay.Server.Docker/Dockerfile - container_name: relay_server_migrations + container_name: relay-server-migrations environment: <<: [*db-connection, *logging] Serilog__Properties__System: Migration depends_on: - relay_persistence_postgresql: + relay-persistence-postgresql: condition: service_healthy - relay_persistence_sqlserver: + relay-persistence-sqlserver: condition: service_healthy entrypoint: ["dotnet", "Thinktecture.Relay.Server.Docker.dll", "migrate-only=true"] - relay_management: + relay-management-api: <<: *defaults - image: relay_management + image: relay-management-api build: context: .. dockerfile: ./docker/Thinktecture.Relay.ManagementApi.Docker/Dockerfile - container_name: relay_management + container_name: relay-management-api ports: - "5004:5000" environment: <<: [*db-connection, *logging] depends_on: - - relay_server_migrations + - relay-server-migrations - relay_tenant_seed: + relay-seed: <<: *defaults image: curlimages/curl - container_name: relay_tenant_seed + container_name: relay-seed depends_on: - - relay_server_migrations - - relay_management - command: [ "sh", "-c", "sleep 5 && curl -H \"Accept: application/json\" -H \"Content-Type: application/json\" -H \"Api-Key: write-key\" --data-raw '{ \"name\": \"TestTenant1\", \"credentials\": [{ \"plainTextValue\": \"\" }]}' http://relay_management:5000/management/tenants && curl -H \"Accept: application/json\" -H \"Content-Type: application/json\" -H \"Api-Key: write-key\" --data-raw '{ \"name\": \"TestTenant2\", \"credentials\": [{ \"plainTextValue\": \"\" }]}' http://relay_management:5000/management/tenants" ] + - relay-server-migrations + - relay-management-api + command: [ "sh", "-c", "sleep 5 && curl -H \"Accept: application/json\" -H \"Content-Type: application/json\" -H \"Api-Key: write-key\" --data-raw '{ \"name\": \"TestTenant1\", \"credentials\": [{ \"plainTextValue\": \"\" }]}' http://relay-management-api:5000/management/tenants && curl -H \"Accept: application/json\" -H \"Content-Type: application/json\" -H \"Api-Key: write-key\" --data-raw '{ \"name\": \"TestTenant2\", \"credentials\": [{ \"plainTextValue\": \"\" }]}' http://relay-management-api:5000/management/tenants" ] - relay_identityprovider: + relay-identityprovider: <<: *defaults image: quay.io/keycloak/keycloak:24.0 - container_name: relayidentityprovider # this should also be named relay_identityprovider, but Keycloak does not support underscores in host names 🤦 See https://stackoverflow.com/a/76991211/199861 + container_name: relay-identityprovider ports: - "5002:5002" volumes: @@ -160,85 +160,85 @@ services: KC_HOSTNAME_DEBUG: true command: [ "start-dev", "--http-port=5002", "--import-realm" ] - relay_server_a: + relay-server-a: <<: *defaults - image: relay_server - container_name: relay_server_a + image: relay-server + container_name: relay-server-a ports: - "5010:5000" environment: <<: [*db-connection, *logging] Serilog__Properties__System: RelayServerA - RabbitMq__Uri: amqp://guest:guest@relay_transport_rabbitmq1 + RabbitMq__Uri: amqp://guest:guest@relay-transport-rabbitmq-1 volumes: - relay-bodystore:/var/bodystore depends_on: - - relay_server_migrations - - relay_identityprovider - relay_server_b: + - relay-server-migrations + - relay-identityprovider + relay-server-b: <<: *defaults - image: relay_server - container_name: relay_server_b + image: relay-server + container_name: relay-server-b ports: - "5011:5000" environment: <<: [*db-connection, *logging] Serilog__Properties__System: RelayServerB - RabbitMq__Uri: amqp://guest:guest@relay_transport_rabbitmq2 + RabbitMq__Uri: amqp://guest:guest@relay-transport-rabbitmq-2 volumes: - relay-bodystore:/var/bodystore depends_on: - - relay_server_migrations - - relay_identityprovider + - relay-server-migrations + - relay-identityprovider - relay_connector_a1: + relay-connector-a1: <<: *defaults - image: relay_connector + image: relay-connector build: context: .. dockerfile: ./docker/Thinktecture.Relay.Connector.Docker/Dockerfile - container_name: relay_connector_a1 + container_name: relay-connector-a1 environment: <<: *logging Serilog__Properties__System: Connector_A1 - RelayConnector__RelayServerBaseUri: http://relay_server_a:5000 + RelayConnector__RelayServerBaseUri: http://relay-server-a:5000 RelayConnector__TenantName: TestTenant1 depends_on: - - relay_server_a - relay_connector_a2: + - relay-server-a + relay-connector-a2: <<: *defaults - image: relay_connector - container_name: relay_connector_a2 + image: relay-connector + container_name: relay-connector-a2 environment: <<: *logging Serilog__Properties__System: Connector_A2 - RelayConnector__RelayServerBaseUri: http://relay_server_a:5000 + RelayConnector__RelayServerBaseUri: http://relay-server-a:5000 RelayConnector__TenantName: TestTenant1 depends_on: - - relay_connector_a1 + - relay-connector-a1 - relay_connector_b1: + relay-connector-b1: <<: *defaults - image: relay_connector - container_name: relay_connector_b1 + image: relay-connector + container_name: relay-connector-b1 environment: <<: *logging Serilog__Properties__System: Connector_B1 - RelayConnector__RelayServerBaseUri: http://relay_server_b:5000 + RelayConnector__RelayServerBaseUri: http://relay-server-b:5000 RelayConnector__TenantName: TestTenant2 depends_on: - - relay_server_b - relay_connector_b2: + - relay-server-b + relay-connector-b2: <<: *defaults - image: relay_connector - container_name: relay_connector_b2 + image: relay-connector + container_name: relay-connector-b2 environment: <<: *logging Serilog__Properties__System: Connector_B2 - RelayConnector__RelayServerBaseUri: http://relay_server_b:5000 + RelayConnector__RelayServerBaseUri: http://relay-server-b:5000 RelayConnector__TenantName: TestTenant2 depends_on: - - relay_connector_b1 + - relay-connector-b1 volumes: seq-data: