smartcommunitylab / smartcampus.gamification

8 stars 10 forks source link

Connection to mongodb fails #183

Open nicokant opened 1 year ago

nicokant commented 1 year ago

Hi, I'm trying to setup the project using Docker, but I keep getting the same error:

com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=localhost:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused (Connection refused)}}]

The docker image is built on the master branch, the docker compose is the following:

version: "3.9"

volumes:
  mongo-data:

services:
  mongo:
    image: mongo:3.6.2-jessie
    ports:
      - 27017:27017
    volumes:
      - mongo-data:/data/db

  gamification-engine:
    image: ghcr.io/nicokant/smartcampus-gamification:latest    # remote image built on github
    ports:
      - "8010:8010"
      - "7777:7777"
    depends_on:
      - mongo
    links:
      - mongo:mongodb
    env_file: 
      - ./gamification.env
    volumes:
      - ./logs:/app/game-engine.web/logs
      - ./engine-config:/app/config

the gamification.env instead is the following:


# SERVER CONFS
#
SERVER_PORT=8010
SERVER_CONTEXTPATH=/gamification
GAMIFICATION_REVERSEPROXY=
SPRING_PROFILE=sec
# LOG PATH
LOG_PATH=/app/game-engine.web/logs
STATS_LOGGER_LEVEL=INFO
USERS_FILE=/app/config/users.yml
#
# Actuators stuff.
#
MANAGEMENT_CONTEXT=/manage
MANAGEMENT_PORT=9000
MANAGEMENT_SECURITY_ENABLED=false

#
# DB SETTINGS
#
MONGO_HOST=mongo
MONGO_PORT=27017
MONGO_DBNAME=gamification
#MONGO_USERNAME=
#MONGO_PWD=
#MONGO_AUTHDB=

#
# Platform security
#
#Parent Space
AAC_ROLES_CONTEXT=COMPONENTS/GAMIFICATION
AAC_ROLES_ROLE=ROLE_PROVIDER
AAC_URL=http://localhost:8080/aac
AAC_CLIENTID=8f5d78cf-56b6-4217-b3f0-bdc126a99258
AAC_CLIENTSECRET=2bb738cc-718b-44d4-aace-5d62680971f2

#
# PERSISTENCE TASK CONFIGURATIONS
#
# Use to activate task persistence (default value false)
TASK_PERSISTENCE_ACTIVATE=false

#
# RABBITMQ CONFIGURATIONS
#
# RABBITMQ_ENABLED=false
# RABBITMQ_HOST=localhost
# RABBITMQ_VIRTUALHOST=playgo
# RABBITMQ_PORT=5672
# RABBITMQ_USER=user
# RABBITMQ_PASSWORD=password
# RABBITMQ_PNGEXCHANGENAME=ge-notifications
# RABBITMQ_PNGROUTINGKEYPREFIX=game
# # comma separated list
# RABBITMQ_GAMEIDS=

It's strange that it keeps trying to connect to localhost:27017 while gamification.env set the HOST to mongo

How can I solve this? Thank you!

nicokant commented 1 year ago

I seems to be hardcoded, is there a way to read from environment variables at run time? https://github.com/smartcommunitylab/smartcampus.gamification/blob/40dec44f114e07074b9dda9a9db253c330b34bf4/game-engine.tools/game-statistic/src/main/java/it/smartcommunitylab/gamification/game_statistics/App.java#L37

nicokant commented 1 year ago

It seems that gamification.env is missing an example variable:

SPRING_DATA_MONGODB_URI=mongodb://mongo:27017/gamification