Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add dip infra #2

Merged
merged 2 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/quest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
10 changes: 5 additions & 5 deletions .github/workflows/voyage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
20 changes: 8 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<ORDER-UUID>/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
```
22 changes: 0 additions & 22 deletions infra/dip.yml

This file was deleted.

40 changes: 0 additions & 40 deletions infra/docker-compose.yml

This file was deleted.

46 changes: 23 additions & 23 deletions quest/.dockerdev/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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
6 changes: 5 additions & 1 deletion quest/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions quest/config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,6 @@
level: config.log_level,
formatter: config.rails_semantic_logger.format
)

config.hosts << ENV["VIRTUAL_HOST"] if ENV["VIRTUAL_HOST"]
end
2 changes: 1 addition & 1 deletion quest/config/kafka_producer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }%>
Expand Down
10 changes: 9 additions & 1 deletion quest/dip.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '7.5'
version: '8.0.0.rc'

environment:
WORK_DIR: /app/${DIP_WORK_DIR_REL_PATH}
Expand All @@ -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
Expand Down
Empty file added quest/tmp/pids/.keep
Empty file.
56 changes: 28 additions & 28 deletions voyage/.dockerdev/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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
Loading
Loading