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

Dockerize gateway #6

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,25 @@ cd federated-rails-app

docker-compose up --build
```
Setup db:

Articles and users servers would be acceptable for http://localhost:3001 and http://localhost:3000.
Gateway - http://localhost:4000

Setup db (on first launch):
```bash
cd federated-rails-app

docker-compose exec users rails db:create db:migrate db:seed
docker-compose exec articles rails db:create db:migrate db:seed
```
Compose graphql schema:

Compose graphql supergraph schema (if not exists, **before** building container):
```bash
cd gateway

npm install -g @apollo/rover
rover supergraph compose --config ./supergraph-config.yaml > supergraph.graphql
```
Launch gateway with `node index.js`

### Reproduce
Create api-only rails applications (as much as you need):
Expand Down
2 changes: 2 additions & 0 deletions articles/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@ class Application < Rails::Application
# Middleware like session, flash, cookies can be added back manually.
# Skip views, helpers and assets when generating a new resource.
config.api_only = true
config.hosts << 'articles'
config.hosts << 'localhost'
end
end
32 changes: 14 additions & 18 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,40 @@ services:
build:
context: ./users
dockerfile: Dockerfile
depends_on:
- users_database
ports:
- "3000:3000"
volumes:
- users_app:/app
- users_gem_cache:/usr/local/bundle/gems
environment:
RAILS_ENV: development

users_database:
image: nouchka/sqlite3:latest
volumes:
- users_db_data:/root/db

articles:
build:
context: ./articles
dockerfile: Dockerfile
depends_on:
- articles_database
ports:
- "3001:3000"
volumes:
- articles_app:/app
- articles_gem_cache:/usr/local/bundle/gems
environment:
RAILS_ENV: development

articles_database:
image: nouchka/sqlite3:latest
gateway:
build:
context: ./gateway
dockerfile: Dockerfile
ports:
- "4000:4000"
depends_on:
- articles
- users
volumes:
- articles_db_data:/root/db
- gateway:/app
environment:
USERS_HOST: users:3000
ARTICLES_HOST: articles:3000

volumes:
users_app:
users_gem_cache:
users_db_data:
articles_app:
articles_gem_cache:
articles_db_data:
gateway:
18 changes: 18 additions & 0 deletions gateway/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM node:14-alpine

RUN mkdir -p /home/node/app/node_modules && chown -R node:node /home/node/app

WORKDIR /home/node/app

COPY package*.json ./
COPY index.js ./

USER node

RUN npm install

COPY --chown=node:node . .

EXPOSE 4000

CMD [ "node", "index.js" ]
165 changes: 0 additions & 165 deletions gateway/example_supergraph.graphql

This file was deleted.

Loading