Skip to content

Commit

Permalink
ft(dev): dev setup
Browse files Browse the repository at this point in the history
  • Loading branch information
siddhantprateek committed Jul 25, 2023
1 parent df4240e commit 49ce7ab
Show file tree
Hide file tree
Showing 7 changed files with 271 additions and 12 deletions.
File renamed without changes.
145 changes: 145 additions & 0 deletions .docker/docker-compose.dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
version: '3.4'

services:
postgres:
image: postgres:13-alpine
restart: always
container_name: postgres
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=dev
- POSTGRES_DB=heimdb
ports:
- '5432:5432'
networks:
- backend
volumes:
- postgres-data:/var/lib/postgresql/data
mongo:
image: mongo
ports:
- 27017:27017
environment:
- MONGO_INITDB_ROOT_USERNAME:root
- MONGO_INITDB_ROOT_PASSWORD:root
networks:
- backend
volumes:
- mongo-data:/data/db

mongo-express:
image: mongo-express
restart: always
ports:
- 8081:8081
networks:
- backend
depends_on:
- mongo
environment:
- ME_CONFIG_MONGODB_ADMINUSERNAME:root
- ME_CONFIG_MONGODB_ADMINPASSWORD:root
- ME_CONFIG_MONGODB_URL:mongodb://root:root@mongo:27017/
grafana:
image: grafana/grafana:latest
container_name: grafana
ports:
- "3000:3000"
volumes:
- grafana_data:/var/lib/grafana
environment:
- GF_AUTH_BASIC_ENABLED=false
- GF_AUTH_ANONYMOUS_ENABLED=true
- GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
networks:
- monitoring
restart: unless-stopped
prometheus:
image: prom/prometheus:latest
container_name: prometheus
ports:
- "9090:9090"
command: --config.file=/etc/prometheus/prometheus.yaml
volumes:
- ./prometheus.yaml:/etc/prometheus/prometheus.yaml
- prometheus_data:/prometheus
networks:
- monitoring
restart: unless-stopped

consul:
container_name: consul-badger
image: hashicorp/consul:latest
restart: always
ports:
- "8500:8500"
- "8600:8600/tcp"
- "8600:8600/udp"
networks:
- consul
command: agent -server -ui -node=server-1 -bootstrap-expect=1 -client=0.0.0.0

rabbitmq:
container_name: rabbitmq
image: rabbitmq:3-management
hostname: my-rabbit
ports:
- 15672:15672
- 5672:5672
db:
image: mongo:latest
ports:
- "27017:27017"
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: example
networks:
- backend
backend:
# build:
# context: .
# dockerfile: Dockerfile
image: siddhantprateek/landate-backend:latest
container_name: landate-gateway
environment:
API_ACCESS_KEY: "all horses do not were spider mask"
API_GATEWAY_PORT: 8000
STORAGE_SERVICE_PORT: 8001
AUTH_SERVICE_PORT: 8002
DOCUMENT_SERVICE_PORT: 8003
MONGO_URI: mongodb://root:example@db:27017
POSTGRES_URI: postgresql://postgres:dev@postgres:5432/heimdb?sslmode=disable
DB_HOST: localhost
DB_PORT: 5432
DB_USER: postgres
DB_PASSWORD: dev
DB_NAME: heimdb
ports:
- 8000:8000
depends_on:
- db
- consul
- postgres
networks:
- backend
- monitoring
- consul
restart: always


networks:
monitoring:
consul:
driver: bridge
backend:
driver: bridge



volumes:
grafana_data:
prometheus_data:
mongo-data:
driver: local
postgres-data:
driver: local
117 changes: 117 additions & 0 deletions .docker/docker-compose.prod.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
version: '3.4'

services:
postgres:
image: postgres:13-alpine
restart: always
container_name: postgres
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=dev
- POSTGRES_DB=heimdb
ports:
- '5432:5432'
networks:
- backend
volumes:
- postgres-data:/var/lib/postgresql/data
grafana:
image: grafana/grafana:latest
container_name: grafana
ports:
- "3000:3000"
volumes:
- grafana_data:/var/lib/grafana
environment:
- GF_AUTH_BASIC_ENABLED=false
- GF_AUTH_ANONYMOUS_ENABLED=true
- GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
networks:
- monitoring
restart: unless-stopped
prometheus:
image: prom/prometheus:latest
container_name: prometheus
ports:
- "9090:9090"
command: --config.file=/etc/prometheus/prometheus.yaml
volumes:
- ./prometheus.yaml:/etc/prometheus/prometheus.yaml
- prometheus_data:/prometheus
networks:
- monitoring
restart: unless-stopped

consul:
container_name: consul-badger
image: hashicorp/consul:latest
restart: always
ports:
- "8500:8500"
- "8600:8600/tcp"
- "8600:8600/udp"
networks:
- consul
command: agent -server -ui -node=server-1 -bootstrap-expect=1 -client=0.0.0.0

rabbitmq:
container_name: rabbitmq
image: rabbitmq:3-management
hostname: my-rabbit
ports:
- 15672:15672
- 5672:5672
db:
image: mongo:latest
ports:
- "27017:27017"
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: example
networks:
- backend
backend:
image: siddhantprateek/landate-backend:latest
container_name: landate-gateway
environment:
API_ACCESS_KEY: "all horses do not were spider mask"
API_GATEWAY_PORT: 8000
STORAGE_SERVICE_PORT: 8001
AUTH_SERVICE_PORT: 8002
DOCUMENT_SERVICE_PORT: 8003
MONGO_URI: mongodb://root:example@db:27017
POSTGRES_URI: postgresql://postgres:dev@postgres:5432/heimdb?sslmode=disable
DB_HOST: localhost
DB_PORT: 5432
DB_USER: postgres
DB_PASSWORD: dev
DB_NAME: heimdb
ports:
- 8000:8000
depends_on:
- db
- consul
- postgres
networks:
- backend
- monitoring
- consul
restart: always


networks:
monitoring:
consul:
driver: bridge
backend:
driver: bridge



volumes:
grafana_data:
prometheus_data:
mongo-data:
driver: local
postgres-data:
driver: local
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func GetEnvConfig(VARIABLE_NAME string) string {
err := godotenv.Load()
err := godotenv.Load(".dev.env") // for production leave it empty
if err != nil {
fmt.Println("Error loading .env file:", err)
}
Expand Down
7 changes: 4 additions & 3 deletions consul/consul.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ type Service struct {
}

const (
ttl = time.Second * 8 // time to leave
serviceAddress = "consul:8500"
ttl = time.Second * 8 // time to leave
// serviceAddress = "consul:8500" // for production
serviceAddress = "localhost"
)

/*
Expand All @@ -40,7 +41,7 @@ servicePort: int - Port number on which the service is running.
*/
func NewService(serviceID, serviceName, serviceTag string, servicePort int) *Service {
client, err := api.NewClient(&api.Config{
Address: serviceAddress,
// Address: serviceAddress,
})
if err != nil {
log.Fatal(err)
Expand Down
8 changes: 4 additions & 4 deletions storage/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ func DBConnect() {
if err != nil {
log.Fatal("Unable to parse port string to int")
}

_ = fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%d sslmode=disable TimeZone=Asia/Shanghai",
// dsn: URI for local development
dsn := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%d sslmode=disable TimeZone=Asia/Shanghai",
config.GetEnvConfig("DB_HOST"),
config.GetEnvConfig("DB_USER"),
config.GetEnvConfig("DB_PASSWORD"),
config.GetEnvConfig("DB_NAME"),
DB_PORT)
postgresURI := config.GetEnvConfig("POSTGRES_URI")
db, err := gorm.Open(postgres.Open(postgresURI), &gorm.Config{
// postgresURI := config.GetEnvConfig("POSTGRES_URI") // for production
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{
Logger: logger.Default.LogMode(logger.Info),
})
if err != nil {
Expand Down
4 changes: 0 additions & 4 deletions yarn.lock

This file was deleted.

0 comments on commit 49ce7ab

Please sign in to comment.