diff --git a/.github/workflows/quest.yml b/.github/workflows/quest.yml index 4cf090e..14785e7 100644 --- a/.github/workflows/quest.yml +++ b/.github/workflows/quest.yml @@ -22,9 +22,9 @@ jobs: ruby-version: "3.3" - name: Install dependencies run: | - docker network create infranet - gem install dip - dip bundle install + gem install dip -v 8.0.0.rc + dip infra up + dip provision - name: Run linter run: dip rubocop @@ -43,8 +43,8 @@ jobs: ruby-version: "3.3" - name: Install dependencies run: | - docker network create infranet - gem install dip + gem install dip -v 8.0.0.rc + dip infra up dip provision - name: Run tests run: dip rspec --format RspecJunitFormatter --out test-results/rspec.xml --format documentation diff --git a/.github/workflows/voyage.yml b/.github/workflows/voyage.yml index f4e1233..1152a67 100644 --- a/.github/workflows/voyage.yml +++ b/.github/workflows/voyage.yml @@ -22,9 +22,9 @@ jobs: ruby-version: "3.3" - name: Install dependencies run: | - docker network create infranet gem install dip - dip bundle install + dip provision + dip infra up - name: Run linter run: dip rubocop @@ -43,8 +43,8 @@ jobs: ruby-version: "3.3" - name: Install dependencies run: | - docker network create infranet gem install dip dip provision + dip infra up - name: Run tests run: dip rspec --format RspecJunitFormatter --out test-results/rspec.xml --format documentation diff --git a/README.md b/README.md index c42ce3e..69ca6ed 100644 --- a/README.md +++ b/README.md @@ -8,29 +8,25 @@ These are example applications that use: ## How to run 1. Install [Dip](https://github.com/bibendi/dip) -2. Start [Kafka](./infra/) broker `cd infra && dip up` -3. Start [Quest](./quest/) application `cd quest && dip up` -4. Start [Voyage](./voyage/) application `cd voyage && dip up` +2. Start [Quest](./quest/) application `cd quest && dip infra up && dip up` +3. Start [Voyage](./voyage/) application `cd voyage && dip infra up && dip up` ## Test case -1. Create an order in Quest app +1. Create an order in the Quest app ```shell -curl --location http://localhost:3000/api/v1/orders \ ---form '[order]name=Foo' \ ---form '[order]qty=3' \ ---form '[order]price=42' +curl -L http://quest.lvh.me/api/v1/orders -F '[order]name=Foo' -F '[order]qty=3' -F '[order]price=42' ``` -2. Send the order to Vayage app through Outbox pattern +2. Send the order to the Voyage app with Outbox pattern ```shell -curl --request POST --location http://localhost:3000/api/v1/orders//completion +curl -X POST -L http://quest.lvh.me/api/v1/orders/ORDER-ID/completion ``` -3. Show the imported order +3. Show the imported order in the Voyage app ```shell -curl --location http://localhost:3001/api/v1/orders +curl -L http://voyage.lvh.me/api/v1/orders/ORDER-ID ``` diff --git a/infra/dip.yml b/infra/dip.yml deleted file mode 100644 index 8e2905b..0000000 --- a/infra/dip.yml +++ /dev/null @@ -1,22 +0,0 @@ -version: '7.5' - -compose: - files: - - docker-compose.yml - -interaction: - bash: - description: Open a Bash shell - service: kafka - command: bash - - kafka: - description: Kafka scripts, see more at https://kafka.apache.org/documentation - service: kafka - subcommands: - topics: - command: kafka-topics.sh --bootstrap-server kafka:9092 - consumer: - command: kafka-console-consumer.sh --bootstrap-server kafka:9092 - consumer-groups: - command: kafka-consumer-groups.sh --bootstrap-server kafka:9092 diff --git a/infra/docker-compose.yml b/infra/docker-compose.yml deleted file mode 100644 index 693f912..0000000 --- a/infra/docker-compose.yml +++ /dev/null @@ -1,40 +0,0 @@ -services: - zookeeper: - image: bitnami/zookeeper:3.9 - environment: - ALLOW_ANONYMOUS_LOGIN: "yes" - volumes: - - zookeeper:/bitnami - ports: - - 2181 - networks: - - default - - infranet - - kafka: - image: bitnami/kafka:3.6 - depends_on: - - zookeeper - environment: - ALLOW_PLAINTEXT_LISTENER: "yes" - KAFKA_ENABLE_KRAFT: "no" - KAFKA_CFG_ZOOKEEPER_CONNECT: zookeeper:2181 - KAFKA_CFG_LISTENERS: PLAINTEXT://:9092,CONTROLLER://:9093,EXTERNAL://:9094 - KAFKA_CFG_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092,EXTERNAL://localhost:9094 - KAFKA_CFG_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,CONTROLLER:PLAINTEXT,EXTERNAL:PLAINTEXT - volumes: - - kafka:/data - ports: - - 9092 - - 9094 - networks: - - default - - infranet - -volumes: - zookeeper: - kafka: - -networks: - infranet: - name: infranet diff --git a/quest/.dockerdev/docker-compose.yml b/quest/.dockerdev/docker-compose.yml index a70720f..28a89c6 100644 --- a/quest/.dockerdev/docker-compose.yml +++ b/quest/.dockerdev/docker-compose.yml @@ -5,7 +5,7 @@ x-environments: &environments BUNDLE_APP_CONFIG: ../.bundle DATABASE_URL: postgres://postgres:keepinsecret@postgres:5432 REDIS_URL: redis://redis:6379 - KAFKA_BROKERS: kafka.infranet:9092 + BROKER_URL: kafka:9092 x-ruby: &ruby build: @@ -34,11 +34,12 @@ x-ruby: &ruby - bundle:/usr/local/bundle networks: - default - - infranet + - postgres-net + - kafka-net + extra_hosts: + - "voyage.lvh.me:host-gateway" x-rails-deps: &rails-deps - postgres: - condition: service_healthy redis: condition: service_healthy @@ -59,8 +60,16 @@ services: puma: <<: *rails command: bundle exec puma + environment: + <<: *environments + VIRTUAL_HOST: quest.lvh.me + networks: + - default + - nginx-net + - postgres-net + - kafka-net ports: - - '3000:3000' + - 3000 sidekiq: <<: *rails @@ -74,22 +83,8 @@ services: <<: *rails command: bundle exec outbox start - postgres: - image: postgres:16-bookworm - volumes: - - postgres:/var/lib/postgresql/data - - .psqlrc:/root/.psqlrc:ro - - ../log:/var/log/psql_history - ports: - - 5432 - environment: - POSTGRES_PASSWORD: keepinsecret - healthcheck: - test: pg_isready -U postgres -h 127.0.0.1 - interval: 10s - redis: - image: redis:7-bookworm + image: redis:7 environment: ALLOW_EMPTY_PASSWORD: "yes" volumes: @@ -102,11 +97,16 @@ services: volumes: bundle: - postgres: redis: rails_cache: networks: - infranet: - name: infranet + nginx-net: + name: ${DIP_INFRA_NETWORK_NGINX} + external: true + postgres-net: + name: ${DIP_INFRA_NETWORK_POSTGRES} + external: true + kafka-net: + name: ${DIP_INFRA_NETWORK_KAFKA} external: true diff --git a/quest/.gitignore b/quest/.gitignore index 03a0e2b..2ad759b 100644 --- a/quest/.gitignore +++ b/quest/.gitignore @@ -17,7 +17,11 @@ vendor/bundle /tmp/* !/log/.keep !/tmp/.keep -!/tmp/*/.keep + +# Ignore pidfiles, but keep the directory. +/tmp/pids/* +!/tmp/pids/ +!/tmp/pids/.keep # Ignore uploaded files in development. /public/storage diff --git a/quest/config/environments/development.rb b/quest/config/environments/development.rb index 73fd67a..387fa34 100644 --- a/quest/config/environments/development.rb +++ b/quest/config/environments/development.rb @@ -74,4 +74,6 @@ level: config.log_level, formatter: config.rails_semantic_logger.format ) + + config.hosts << ENV["VIRTUAL_HOST"] if ENV["VIRTUAL_HOST"] end diff --git a/quest/config/kafka_producer.yml b/quest/config/kafka_producer.yml index b30683a..6a9599f 100644 --- a/quest/config/kafka_producer.yml +++ b/quest/config/kafka_producer.yml @@ -11,7 +11,7 @@ default: &default sasl_username: <%= ENV.fetch('KAFKA_SASL_DSN'){ 'SCRAM-SHA-512:kafka_login:kafka_password' }.split(':').second %> sasl_password: <%= ENV.fetch('KAFKA_SASL_DSN'){ 'SCRAM-SHA-512:kafka_login:kafka_password' }.split(':').last %> kafka: - servers: <%= ENV.fetch('KAFKA_BROKERS'){ 'localhost:9092' } %> + servers: <%= ENV.fetch('BROKER_URL'){ 'localhost:9092' } %> max_retries: <%= ENV.fetch('QUEST__KAFKA__PRODUCER__MAX_RETRIES') { 2 }%> required_acks: <%= ENV.fetch('QUEST__KAFKA__PRODUCER_REQUIRED_ACKS') { -1 }%> ack_timeout: <%= ENV.fetch('QUEST__KAFKA__PRODUCER_ACK_TIMEOUT') { 1 }%> diff --git a/quest/dip.yml b/quest/dip.yml index b78479f..0cc603e 100644 --- a/quest/dip.yml +++ b/quest/dip.yml @@ -8,6 +8,14 @@ compose: - ./.dockerdev/docker-compose.yml - ./.dockerdev/docker-compose.local.yml +infra: + nginx: + git: https://github.com/bibendi/dip-nginx.git + postgres: + git: https://github.com/bibendi/dip-postgres.git + kafka: + git: https://github.com/bibendi/dip-kafka.git + interaction: bash: description: Open a Bash shell diff --git a/quest/tmp/pids/.keep b/quest/tmp/pids/.keep new file mode 100644 index 0000000..e69de29 diff --git a/voyage/.dockerdev/docker-compose.yml b/voyage/.dockerdev/docker-compose.yml index 1894751..a1ba2cf 100644 --- a/voyage/.dockerdev/docker-compose.yml +++ b/voyage/.dockerdev/docker-compose.yml @@ -5,7 +5,7 @@ x-environments: &environments BUNDLE_APP_CONFIG: ../.bundle DATABASE_URL: postgres://postgres:keepinsecret@postgres:5432 REDIS_URL: redis://redis:6379 - KAFKA_BROKERS: kafka.infranet:9092 + BROKER_URL: kafka:9092 x-ruby: &ruby build: @@ -34,11 +34,12 @@ x-ruby: &ruby - bundle:/usr/local/bundle networks: - default - - infranet + - postgres-net + - kafka-net + extra_hosts: + - "quest.lvh.me:host-gateway" x-rails-deps: &rails-deps - postgres: - condition: service_healthy redis: condition: service_healthy @@ -59,8 +60,16 @@ services: puma: <<: *rails command: bundle exec puma + environment: + <<: *environments + VIRTUAL_HOST: voyage.lvh.me + networks: + - default + - nginx-net + - postgres-net + - kafka-net ports: - - '3001:3000' + - 3000 sidekiq: <<: *rails @@ -70,32 +79,18 @@ services: <<: *rails command: bundle exec schked start - kafka-consumer: - <<: *rails - depends_on: - <<: *rails-deps - command: bundle exec kafka_consumer - outbox: <<: *rails command: bundle exec outbox start - postgres: - image: postgres:16-bookworm - volumes: - - postgres:/var/lib/postgresql/data - - .psqlrc:/root/.psqlrc:ro - - ../log:/var/log/psql_history - ports: - - 5432 - environment: - POSTGRES_PASSWORD: keepinsecret - healthcheck: - test: pg_isready -U postgres -h 127.0.0.1 - interval: 10s + consumer: + <<: *rails + depends_on: + <<: *rails-deps + command: bundle exec kafka_consumer redis: - image: redis:7-bookworm + image: redis:7 environment: ALLOW_EMPTY_PASSWORD: "yes" volumes: @@ -108,11 +103,16 @@ services: volumes: bundle: - postgres: redis: rails_cache: networks: - infranet: - name: infranet + nginx-net: + name: ${DIP_INFRA_NETWORK_NGINX} + external: true + postgres-net: + name: ${DIP_INFRA_NETWORK_POSTGRES} + external: true + kafka-net: + name: ${DIP_INFRA_NETWORK_KAFKA} external: true diff --git a/voyage/.gitignore b/voyage/.gitignore index 03a0e2b..2ad759b 100644 --- a/voyage/.gitignore +++ b/voyage/.gitignore @@ -17,7 +17,11 @@ vendor/bundle /tmp/* !/log/.keep !/tmp/.keep -!/tmp/*/.keep + +# Ignore pidfiles, but keep the directory. +/tmp/pids/* +!/tmp/pids/ +!/tmp/pids/.keep # Ignore uploaded files in development. /public/storage diff --git a/voyage/config/environments/development.rb b/voyage/config/environments/development.rb index 73fd67a..387fa34 100644 --- a/voyage/config/environments/development.rb +++ b/voyage/config/environments/development.rb @@ -74,4 +74,6 @@ level: config.log_level, formatter: config.rails_semantic_logger.format ) + + config.hosts << ENV["VIRTUAL_HOST"] if ENV["VIRTUAL_HOST"] end diff --git a/voyage/config/kafka_consumer.yml b/voyage/config/kafka_consumer.yml index d04d963..85777c0 100644 --- a/voyage/config/kafka_consumer.yml +++ b/voyage/config/kafka_consumer.yml @@ -7,7 +7,7 @@ default: &default client_id: voyage shutdown_timeout: 120 kafka: - servers: <%= ENV.fetch('KAFKA_BROKERS'){ 'kafka:9092' } %> + servers: <%= ENV.fetch('BROKER_URL'){ 'kafka:9092' } %> kafka_options: auto.offset.reset: 'latest' consumer_groups: diff --git a/voyage/dip.yml b/voyage/dip.yml index b9a1773..8714526 100644 --- a/voyage/dip.yml +++ b/voyage/dip.yml @@ -8,6 +8,17 @@ compose: - ./.dockerdev/docker-compose.yml - ./.dockerdev/docker-compose.local.yml +infra: + nginx: + #git: https://github.com/bibendi/dip-nginx.git + path: ~/Code/bibendi/dip-nginx + postgres: + #git: https://github.com/bibendi/dip-postgres.git + path: ~/Code/bibendi/dip-postgres + kafka: + #git: https://github.com/bibendi/dip-kafka.git + path: ~/Code/bibendi/dip-kafka + interaction: bash: description: Open a Bash shell diff --git a/voyage/tmp/pids/.keep b/voyage/tmp/pids/.keep new file mode 100644 index 0000000..e69de29