chrisvel / wreeto_official

Wreeto is an open source note-taking, knowledge management and wiki system.
https://wreeto.com
GNU Affero General Public License v3.0
387 stars 13 forks source link

wreeto can't connect to database container #17

Closed Pingumania closed 4 years ago

Pingumania commented 4 years ago

docker-compose.yml

version: "3.7"
services:
  wreeto-db:
    image: postgres:11-alpine
    container_name: wreeto-db
    restart: always
    networks:
      - internal
    environment:
      - POSTGRES_USER=wreeto
      - POSTGRES_PASSWORD=***
    volumes:
      - /opt/docker/postgres/wreeto:/var/lib/postgresql/data

  redis:
    image: redis:5.0.7
    container_name: redis
    restart: always
    networks:
      - internal

  wreeto:
    image: chrisvel/wreeto:latest
    container_name: wreeto
    depends_on:
      - wreeto-db
      - redis
    networks:
      - internal
      - proxy
    volumes:
      - /opt/docker/wreeto/docker-entrypoint.sh:/app/wreeto/docker-entrypoint.sh
      - /opt/docker/wreeto/.env:/app/wreeto/.env
    command: foreman start
    labels:
      - traefik.enable=true
      - traefik.http.routers.wreeto.entrypoints=web,web-secure
      - traefik.http.routers.wreeto.rule=Host(`wreeto.my.domain`)
      - traefik.http.routers.wreeto.tls.domains[0].main=my.domain
      - traefik.http.routers.wreeto.tls.domains[0].sans=*.my.domain
      - traefik.http.services.wreeto.loadbalancer.server.port=8383
      - traefik.http.services.wreeto.loadbalancer.server.scheme=http

networks:
  proxy:
    external: true
  internal:
    external: false

.env

OAUTH_GOOGLE_ID=
OAUTH_GOOGLE_SECRET=
POSTGRES_HOST=wreeto-db
POSTGRES_USER=wreeto
POSTGRES_PASSWORD=***
POSTGRES_DB=wreeto_db
POSTGRES_PORT=5432
RACK_ENV=development
RAILS_ENV=development
RECAPTCHA_SITE_KEY=
RECAPTCHA_SECRET_KEY=
REDIS_HOST=redis
REDIS_PASSWORD=
SMTP_USERNAME=
SMTP_PASSWORD=
WREETO_HOST=wreeto.my.domain
WREETO_PORT=8383

error

dc logs wreeto
Attaching to wreeto
wreeto              | rails aborted!
wreeto              | PG::ConnectionBad: could not connect to server: No such file or directory
wreeto              |   Is the server running locally and accepting
wreeto              |   connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
chrisvel commented 4 years ago

You must include env_file: .env in the wreeto container, otherwise Rails will not be able to find the POSTGRES_ vars included in the database.yml file: https://github.com/chrisvel/wreeto_official/blob/master/config/database.yml.

Or If you prefer you can add them to an environment: key in the docker-compose.yml file as you already did for wreeto-db.

Pingumania commented 4 years ago

if I do it like this the env variables seem to be ignored because it tries to find wreeto_dev

wreeto              | ActiveRecord::NoDatabaseError: FATAL:  database "wreeto_dev" does not exist
  wreeto:
    image: chrisvel/wreeto:latest
    container_name: wreeto
    depends_on:
      - wreeto-db
      - redis
    networks:
      - internal
      - proxy
    env_file:
      - /opt/docker/wreeto/.env
    volumes:
      - /opt/docker/wreeto/docker-entrypoint.sh:/app/wreeto/docker-entrypoint.sh
      # - /opt/docker/wreeto/.env:/app/wreeto/.env
    command: foreman start
    labels:
      - traefik.enable=true
      - traefik.http.routers.wreeto.entrypoints=web,web-secure
      - traefik.http.routers.wreeto.rule=Host(`wreeto.example.com`)
      - traefik.http.routers.wreeto.tls.domains[0].main=example.com
      - traefik.http.routers.wreeto.tls.domains[0].sans=*.example.com
      - traefik.http.services.wreeto.loadbalancer.server.port=8383
      - traefik.http.services.wreeto.loadbalancer.server.scheme=http

same with

  wreeto:
    image: chrisvel/wreeto:latest
    container_name: wreeto
    depends_on:
      - wreeto-db
      - redis
    networks:
      - internal
      - proxy
    # env_file: 
      # - /opt/docker/wreeto/.env
    environment: 
      - OAUTH_GOOGLE_ID=
      - OAUTH_GOOGLE_SECRET=
      - POSTGRES_HOST=wreeto-db
      - POSTGRES_USER=wreeto
      - POSTGRES_PASSWORD=***
      - POSTGRES_DB=wreeto_db
      - POSTGRES_PORT=5432
      - RACK_ENV=development
      - RAILS_ENV=development
      - RECAPTCHA_SITE_KEY=
      - RECAPTCHA_SECRET_KEY=
      - REDIS_HOST=redis
      - REDIS_PASSWORD=
      - SMTP_USERNAME=
      - SMTP_PASSWORD=
      - WREETO_HOST=wreeto.my.domain
      - WREETO_PORT=8383
    volumes:
      - /opt/docker/wreeto/docker-entrypoint.sh:/app/wreeto/docker-entrypoint.sh
      # - /opt/docker/wreeto/.env:/app/wreeto/.env
    command: foreman start
chrisvel commented 4 years ago

You are correct, wreeto_dev is forgotten here: https://github.com/chrisvel/wreeto_official/blob/48139da80fa791f43f8201bfdebcebd9f84a9d65/config/database.yml#L13 I will replace it with the ENV['POSTGRES_DB'] var asap.