diff --git a/.env.example b/.env.dev.example similarity index 100% rename from .env.example rename to .env.dev.example diff --git a/.env.prod.example b/.env.prod.example new file mode 100644 index 0000000..c2a5185 --- /dev/null +++ b/.env.prod.example @@ -0,0 +1,10 @@ +MONGO_USERNAME=root +MONGO_PASSWORD=example_password +MONGO_DB=ecfmp_test +MONGO_HOST=mongodb +MONGO_PORT=27017 +AUTH_JWT_PUBLIC_KEY_FILE='./docker/dev_public_key.pub' +AUTH_JWT_PRIVATE_KEY_FILE='./docker/dev_private_key.pem' +AUTH_JWT_AUDIENCE='ecfmp-discord-dev' +LOG_LEVEL="FATAL" +DISCORD_BOT_TOKEN="abc" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 48f2669..1897e0f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -59,7 +59,7 @@ jobs: submodules: true - name: Copy env file - run: cp .env.example .env + run: cp .env.dev.example .env - name: Build Protobuf run: make protobuf diff --git a/docker-compose-ci.yml b/docker-compose-ci.yml index 0391026..32d805e 100644 --- a/docker-compose-ci.yml +++ b/docker-compose-ci.yml @@ -20,8 +20,7 @@ services: MONGO_USERNAME: root MONGO_PASSWORD: example_password MONGO_DB: ecfmp_test - MONGO_HOST: mongodb - MONGO_PORT: 27017 + MONGO_HOST: mongodb://mongodb:27017 AUTH_JWT_PUBLIC_KEY_FILE: './docker/dev_public_key.pub' AUTH_JWT_PRIVATE_KEY_FILE: './docker/dev_private_key.pem' AUTH_JWT_AUDIENCE: 'ecfmp-discord-dev' @@ -44,8 +43,7 @@ services: MONGO_USERNAME: root MONGO_PASSWORD: example_password MONGO_DB: ecfmp_test - MONGO_HOST: mongodb - MONGO_PORT: 27017 + MONGO_HOST: mongodb://mongodb:27017 AUTH_JWT_PUBLIC_KEY_FILE: './app/docker/dev_public_key.pub' AUTH_JWT_PRIVATE_KEY_FILE: './app/docker/dev_private_key.pem' AUTH_JWT_AUDIENCE: 'ecfmp-discord-dev' diff --git a/docker-compose.yml b/docker-compose.yml index 3afb799..24a009b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,8 +13,7 @@ services: MONGO_USERNAME: root MONGO_PASSWORD: example_password MONGO_DB: ecfmp - MONGO_HOST: mongodb - MONGO_PORT: 27017 + MONGO_HOST: mongodb://mongodb:27017 AUTH_JWT_PUBLIC_KEY_FILE: "./docker/dev_public_key.pub" AUTH_JWT_AUDIENCE: "ecfmp-discord-dev" LOG_LEVEL: "TRACE" @@ -47,6 +46,7 @@ services: volumes: mongodb_data: + networks: default: name: ecfmp diff --git a/internal/db/mongo.go b/internal/db/mongo.go index c747cc5..4ee40d2 100644 --- a/internal/db/mongo.go +++ b/internal/db/mongo.go @@ -23,17 +23,14 @@ type Mongo struct { * Create a new mongo connection */ func NewMongo() (*Mongo, error) { - mongoUri := fmt.Sprintf( - "mongodb://%s:%s@%s:%s", - os.Getenv("MONGO_USERNAME"), - os.Getenv("MONGO_PASSWORD"), - os.Getenv("MONGO_HOST"), - os.Getenv("MONGO_PORT"), - ) - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() - client, err := mongo.Connect(ctx, options.Client().ApplyURI(mongoUri), options.Client().SetMaxPoolSize(10), options.Client().SetMaxConnIdleTime(5*time.Second)) + + auth := options.Credential{ + Username: os.Getenv("MONGO_USERNAME"), + Password: os.Getenv("MONGO_PASSWORD"), + } + client, err := mongo.Connect(ctx, options.Client().ApplyURI(os.Getenv("MONGO_HOST")).SetAuth(auth).SetMaxPoolSize(10).SetMaxConnIdleTime(5*time.Second)) if err != nil { log.Errorf("Failed to connect to mongo: %v", err) return nil, err