Skip to content

Commit

Permalink
setup common API gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
Harshjosh361 committed Oct 16, 2024
1 parent aa25615 commit d371857
Show file tree
Hide file tree
Showing 3 changed files with 198 additions and 1 deletion.
137 changes: 137 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
services:
# User Service
mongo-user:
image: mongo:latest
container_name: mongo-user
ports:
- "27018:27017"
networks:
- app-network

goapp-user:
build: ./user-service # Path to the user service Dockerfile
container_name: goapp-user
ports:
- "8080:8080"
depends_on:
- mongo-user
environment:
- MONGO_URI=mongodb://mongo-user:27017/
networks:
- app-network

# Product Service
mongo-product:
image: mongo:latest
container_name: mongo-product
ports:
- "27019:27017"
networks:
- app-network

goapp-product:
build: ./product-service # Path to the product service Dockerfile
container_name: goapp-product
ports:
- "8081:8081"
depends_on:
- mongo-product
environment:
- MONGO_URI=mongodb://mongo-product:27017/
networks:
- app-network

#payment-service
mongo-payment:
image: mongo:latest
container_name: mongo-payment
ports:
- "27021:27017"
networks:
- app-network

goapp-payment:
build: ./payment-service # Path to the payment service Dockerfile
container_name: goapp-payment
ports:
- "8082:8082"
depends_on:
- mongo-payment
environment:
- MONGO_URI=mongodb://mongo-payment:27017/
networks:
- app-network
#order-service
mongo-order:
image: mongo:latest
container_name: mongo-order
ports:
- "27022:27017"
networks:
- app-network

goapp-order:
build: ./order-service # Path to the order service Dockerfile
container_name: goapp-order
ports:
- "8083:8083"
depends_on:
- mongo-order
environment:
- MONGO_URI=mongodb://mongo-order:27017/
networks:
- app-network

#notification service
goapp-notification:
build: ./notification-service # Path to the notification service Dockerfile
container_name: goapp-notification
ports:
- "8084:8084"
env_file:
- ./notification-service/.env #Relative patch to twilio credentials
networks:
- app-network

#cart service
mongo-cart:
image: mongo:latest
container_name: mongo-cart
ports:
- "27023:27017"
networks:
- app-network

goapp-cart:
build: ./cart-service # Path to the cart service Dockerfile
container_name: goapp-cart
ports:
- "8085:8085"
depends_on:
- mongo-cart
environment:
- MONGO_URI=mongodb://mongo-cart:27017/
networks:
- app-network

# NGINX Gateway
nginx-gateway:
image: nginx:latest
container_name: nginx-gateway
ports:
- "82:80"
volumes:
- /home/harsh/EcommerceApi/nginx/api_gateway.conf:/etc/nginx/nginx.conf # Correct path
depends_on:
- goapp-user
- goapp-product
- goapp-payment
- goapp-order
- goapp-notification
- goapp-cart
networks:
- app-network

networks:
app-network:
driver: bridge
60 changes: 60 additions & 0 deletions nginx/api_gateway.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
events {
worker_connections 1024; #max no. of connections
}
http {
upstream user-service {
server goapp-user:8080; # Change to your user service port
}

upstream product-service {
server goapp-product:8081; # Change to your product service port
}

upstream payment-service {
server goapp-payment:8082; # Change to your payment service port
}

upstream order-service {
server goapp-order:8083; # Change to your order service port
}

upstream notification-service {
server goapp-notification:8084; # Change to your notification service port
}

upstream cart-service {
server goapp-cart:8085; # Change to your cart service port
}

server {
listen 80;

location /users/ {
proxy_pass http://user-service;
}

location /products/ {
proxy_pass http://product-service;
}

location /payment/ {
proxy_pass http://payment-service;
}

location /orders/ {
proxy_pass http://order-service;
}

location /notification/ {
proxy_pass http://notification-service;
}

location /cart/ {
proxy_pass http://cart-service;
}

access_log /var/log/nginx/api_gateway_access.log;
error_log /var/log/nginx/api_gateway_error.log;
}
}

2 changes: 1 addition & 1 deletion product-service/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
image: mongo:latest
restart: always
ports:
- "27018:27017"
- "27019:27017"

goapp:
build: .
Expand Down

0 comments on commit d371857

Please sign in to comment.