go-vikunja / vikunja

Mirror of vikunja from https://code.vikunja.io/api
GNU Affero General Public License v3.0
906 stars 63 forks source link

VIKUNJA_DATABASE_HOST value not taken into account #31

Closed YasserAntonio closed 2 years ago

YasserAntonio commented 2 years ago

Fresh install of vikunja/api:0.18.1 on raspb3 armv7-32

here is my docker-compose ( in a swarm with traffic) :

version: '3'

services:
  api:
    image: vikunja/api:0.18.1
    dns: 192.168.1.24
    environment:
      VIKUNJA_DATABASE_HOST: db
      VIKUNJA_DATABASE_PASSWORD: supersecret
      VIKUNJA_DATABASE_TYPE: mysql
      VIKUNJA_DATABASE_USER: vikunja
      VIKUNJA_DATABASE_DATABASE: vikunja
    volumes:
      - /home/pi/vikunja/files:/app/vikunja/files
    networks:
      - traefik-local
    deploy:
      labels:
        - "traefik.enable=true"
        - "traefik.http.routers.vikunja-api.rule=Host(`vikunja.ln`) && PathPrefix(`/api/v1`, `/dav/`, `/.well-known/`)"
        - "traefik.http.routers.vikunja-api.entrypoints=http"
      placement:
        constraints:
          - 'node.hostname == Hestia'

  frontend:
    image: vikunja/frontend:0.18.1
    dns: 192.168.1.24
    networks:
      - traefik-local
    deploy:
      labels:
        - "traefik.enable=true"
        - "traefik.http.routers.vikunja-frontend.rule=Host(`vikunja.ln`)"
        - "traefik.http.routers.vikunja-frontend.entrypoints=web"
        - "traefik.http.services.vikunja-frontend.loadbalancer.server.port=80"
      placement:
        constraints:
          - 'node.hostname == Hestia'

  db:
    image: linuxserver/mariadb:alpine-10.5.12-r0-ls36
    environment:
      - PUID=1000
      - PGID=1000
      - MYSQL_ROOT_PASSWORD=supersecret
      - TZ=Europe/Paris
      - MYSQL_DATABASE=vikunja #optional
      - MYSQL_USER=vikunja
      - MYSQL_PASSWORD=supersecret
    volumes:
      - /home/pi/vikunja/mariadb:/config
    deploy:
      placement:
        constraints:
          - 'node.hostname == Polymatheia'

networks:
  traefik-local:
    external: true

but keep having this log :

vikunja_api.1.z8bze8ch30o4@Hestia    | 2022-06-18T19:33:09.634767604Z: CRITICAL ▶ migration/Migrate 002 Migration failed: dial tcp 10.0.0.121:3306: connect: connection refused
vikunja_api.1.ayomtho5b9e5@Hestia    | usermod: no changes
vikunja_api.1.ayomtho5b9e5@Hestia    | 2022/06/18 19:33:17 Config File "config" Not Found in "[/app/vikunja /etc/vikunja /app/vikunja/.config/vikunja]"
vikunja_api.1.ayomtho5b9e5@Hestia    | 2022/06/18 19:33:17 Using default config.
vikunja_api.1.ayomtho5b9e5@Hestia    | 2022-06-18T19:33:17.430681988Z: CRITICAL ▶ migration/Migrate 002 Migration failed: dial tcp 10.0.0.121:3306: connect: connection refused
vikunja_api.1.yyk6pw0ev60c@Hestia    | usermod: no changes
vikunja_api.1.yyk6pw0ev60c@Hestia    | 2022/06/18 19:33:25 Config File "config" Not Found in "[/app/vikunja /etc/vikunja /app/vikunja/.config/vikunja]"
vikunja_api.1.yyk6pw0ev60c@Hestia    | 2022/06/18 19:33:25 Using default config.
vikunja_api.1.yyk6pw0ev60c@Hestia    | 2022-06-18T19:33:25.281242778Z: CRITICAL ▶ migration/Migrate 002 Migration failed: dial tcp 10.0.0.121:3306: connect: connection refused
vikunja_api.1.mziqxeyvocwk@Hestia    | usermod: no changes
vikunja_api.1.mziqxeyvocwk@Hestia    | 2022/06/18 19:33:33 Config File "config" Not Found in "[/app/vikunja /etc/vikunja /app/vikunja/.config/vikunja]"
vikunja_api.1.mziqxeyvocwk@Hestia    | 2022/06/18 19:33:33 Using default config.
vikunja_api.1.mziqxeyvocwk@Hestia    | 2022-06-18T19:33:33.520797942Z: CRITICAL ▶ migration/Migrate 002 Migration failed: dial tcp 10.0.0.121:3306: connect: connection refused

"10.0.0.121:3306" should be "db:3306" no ?

still I can't make the api contact the db, I tried with postresql too just in case , same behavior :s

any idea how to solve this please ?

kolaente commented 2 years ago

It looks like the api container is only in the traefik-local docker network but the db container is not. Without much understanding of docker swarm or the dns option you have in your config, that looks like the two containers won't be able to talk to each other. You should at least put the api and db container in the same docker network, similar to the traefik example in the docs.

"10.0.0.121:3306" should be "db:3306" no ?

The db driver might resolve the dns name to the IP.

YasserAntonio commented 2 years ago

I updated my docker-compose to make it closer to the traefik2 exemple by removing as you suggested the dns and by adding the default network on api and front end, it didn't worked.(in the exemple provided there is no network in the db service) I added the defaults network to the db service but still having the same issue.

here is the updated docker-compose :

version: '3'

services:
  api:
    image: vikunja/api:0.18.1
    environment:
      VIKUNJA_DATABASE_HOST: db
      VIKUNJA_DATABASE_PASSWORD: supersecret
      VIKUNJA_DATABASE_TYPE: mysql
      VIKUNJA_DATABASE_USER: vikunja
      VIKUNJA_DATABASE_DATABASE: vikunja
    volumes:
      - /home/pi/vikunja/files:/app/vikunja/files
    networks:
      - traefik-local
      - default
    depends_on:
      - db
    deploy:
      labels:
        - "traefik.enable=true"
        - "traefik.http.routers.vikunja-api.rule=Host(`vikunja.ln`) && PathPrefix(`/api/v1`, `/dav/`, `/.well-known/`)"
        - "traefik.http.routers.vikunja-api.entrypoints=http"
      placement:
        constraints:
          - 'node.hostname == Hestia'

  frontend:
    image: vikunja/frontend:0.18.1
    networks:
      - traefik-local
      - default
    deploy:
      labels:
        - "traefik.enable=true"
        - "traefik.http.routers.vikunja-frontend.rule=Host(`vikunja.ln`)"
        - "traefik.http.routers.vikunja-frontend.entrypoints=web"
        - "traefik.http.services.vikunja-frontend.loadbalancer.server.port=80"
      placement:
        constraints:
          - 'node.hostname == Hestia'

  db:
    image: linuxserver/mariadb:alpine-10.5.12-r0-ls36
    environment:
      - PUID=1000
      - PGID=1000
      - MYSQL_ROOT_PASSWORD=supersecret
      - TZ=Europe/Paris
      - MYSQL_DATABASE=vikunja #optional
      - MYSQL_USER=vikunja
      - MYSQL_PASSWORD=supersecret
    volumes:
      - /home/pi/vikunja/mariadb:/config
   networks:
      - default
    deploy:
      placement:
        constraints:
          - 'node.hostname == Polymatheia'

networks:
  traefik-local:
    external: true

but I still have the same issue :

vikunja_api.1.rtrpoco5hkos@Hestia    | usermod: no changes
vikunja_api.1.rtrpoco5hkos@Hestia    | 2022/06/18 20:48:10 Config File "config" Not Found in "[/app/vikunja /etc/vikunja /app/vikunja/.config/vikunja]"
vikunja_api.1.rtrpoco5hkos@Hestia    | 2022/06/18 20:48:10 Using default config.
vikunja_api.1.rtrpoco5hkos@Hestia    | 2022-06-18T20:48:10.089124251Z: CRITICAL ▶ migration/Migrate 002 Migration failed: dial tcp 10.0.0.121:3306: connect: connection refused
vikunja_api.1.euiyixqj7hxd@Hestia    | usermod: no changes
vikunja_api.1.euiyixqj7hxd@Hestia    | 2022/06/18 20:48:18 Config File "config" Not Found in "[/app/vikunja /etc/vikunja /app/vikunja/.config/vikunja]"
vikunja_api.1.euiyixqj7hxd@Hestia    | 2022/06/18 20:48:18 Using default config.
vikunja_api.1.euiyixqj7hxd@Hestia    | 2022-06-18T20:48:18.178238724Z: CRITICAL ▶ migration/Migrate 002 Migration failed: dial tcp 10.0.0.121:3306: connect: connection refused

I checked that mariadb:10 was running and it was.

YasserAntonio commented 2 years ago

just In case you need the mariadb log to be sure too :

vikunja_db.1.okah5iy3ppar@Polymatheia    | [s6-init] making user provided files available at /var/run/s6/etc...exited 0.
vikunja_db.1.okah5iy3ppar@Polymatheia    | [s6-init] ensuring user provided files have correct perms...exited 0.
vikunja_db.1.okah5iy3ppar@Polymatheia    | [fix-attrs.d] applying ownership & permissions fixes...
vikunja_db.1.okah5iy3ppar@Polymatheia    | [fix-attrs.d] done.
vikunja_db.1.okah5iy3ppar@Polymatheia    | [cont-init.d] executing container initialization scripts...
vikunja_db.1.okah5iy3ppar@Polymatheia    | [cont-init.d] 01-envfile: executing... 
vikunja_db.1.okah5iy3ppar@Polymatheia    | [cont-init.d] 01-envfile: exited 0.
vikunja_db.1.okah5iy3ppar@Polymatheia    | [cont-init.d] 10-adduser: executing... 
vikunja_db.1.okah5iy3ppar@Polymatheia    | 
vikunja_db.1.okah5iy3ppar@Polymatheia    | -------------------------------------
vikunja_db.1.okah5iy3ppar@Polymatheia    |           _         ()
vikunja_db.1.okah5iy3ppar@Polymatheia    |          | |  ___   _    __
vikunja_db.1.okah5iy3ppar@Polymatheia    |          | | / __| | |  /  \ 
vikunja_db.1.okah5iy3ppar@Polymatheia    |          | | \__ \ | | | () |
vikunja_db.1.okah5iy3ppar@Polymatheia    |          |_| |___/ |_|  \__/
vikunja_db.1.okah5iy3ppar@Polymatheia    | 
vikunja_db.1.okah5iy3ppar@Polymatheia    | 
vikunja_db.1.okah5iy3ppar@Polymatheia    | Brought to you by linuxserver.io
vikunja_db.1.okah5iy3ppar@Polymatheia    | -------------------------------------
vikunja_db.1.okah5iy3ppar@Polymatheia    | 
vikunja_db.1.okah5iy3ppar@Polymatheia    | To support LSIO projects visit:
vikunja_db.1.okah5iy3ppar@Polymatheia    | https://www.linuxserver.io/donate/
vikunja_db.1.okah5iy3ppar@Polymatheia    | -------------------------------------
vikunja_db.1.okah5iy3ppar@Polymatheia    | GID/UID
vikunja_db.1.okah5iy3ppar@Polymatheia    | -------------------------------------
vikunja_db.1.okah5iy3ppar@Polymatheia    | 
vikunja_db.1.okah5iy3ppar@Polymatheia    | User uid:    1000
vikunja_db.1.okah5iy3ppar@Polymatheia    | User gid:    1000
vikunja_db.1.okah5iy3ppar@Polymatheia    | -------------------------------------
vikunja_db.1.okah5iy3ppar@Polymatheia    | 
vikunja_db.1.okah5iy3ppar@Polymatheia    | [cont-init.d] 10-adduser: exited 0.
vikunja_db.1.okah5iy3ppar@Polymatheia    | [cont-init.d] 30-config: executing... 
vikunja_db.1.okah5iy3ppar@Polymatheia    | [cont-init.d] 30-config: exited 0.
vikunja_db.1.okah5iy3ppar@Polymatheia    | [cont-init.d] 40-initialise-db: executing... 
vikunja_db.1.okah5iy3ppar@Polymatheia    | [cont-init.d] 40-initialise-db: exited 0.
vikunja_db.1.okah5iy3ppar@Polymatheia    | [cont-init.d] 90-custom-folders: executing... 
vikunja_db.1.okah5iy3ppar@Polymatheia    | [cont-init.d] 90-custom-folders: exited 0.
vikunja_db.1.okah5iy3ppar@Polymatheia    | [cont-init.d] 99-custom-files: executing... 
vikunja_db.1.okah5iy3ppar@Polymatheia    | [custom-init] no custom files found exiting...
vikunja_db.1.okah5iy3ppar@Polymatheia    | [cont-init.d] 99-custom-files: exited 0.
vikunja_db.1.okah5iy3ppar@Polymatheia    | [cont-init.d] done.
vikunja_db.1.okah5iy3ppar@Polymatheia    | [services.d] starting services
vikunja_db.1.okah5iy3ppar@Polymatheia    | [services.d] done.
kolaente commented 2 years ago

Can you exec into the api container and check if the db is reachable from there?

YasserAntonio commented 2 years ago

the api container keeps rebooting :s not enough time to bash in it and try to ping db

kolaente commented 2 years ago

Try overriding the command or entrypoint to get enough time for a shell.

YasserAntonio commented 2 years ago

I did it by adding a sleep 160 command here is the result :

CONTAINER ID   IMAGE                           COMMAND                  CREATED              STATUS              PORTS      NAMES
2a0611705eaf   vikunja/api:0.18.1              "sleep 160"              About a minute ago   Up About a minute   3456/tcp   vikunja_api.1.hcum2gjb69ht8s4e8rfeb0ljq
5f15db437bc4   vikunja/frontend:0.18.1         "/docker-entrypoint.…"   About a minute ago   Up About a minute   80/tcp     vikunja_frontend.1.znvezhlf7oiafi0mc5bzxakpb
ee9a24fcae0e   registry.ln:5000/heracles:1.0   "uvicorn main:app --…"   35 hours ago         Up 35 hours                    heracles_app.1.qxq4q1vlwhsw00khbryj8myl9
pi@Hestia:~ $ docker exec -it 2a0611705eaf sh
/app/vikunja # ping db
PING db (10.0.0.121): 56 data bytes
64 bytes from 10.0.0.121: seq=0 ttl=64 time=0.425 ms
64 bytes from 10.0.0.121: seq=1 ttl=64 time=0.401 ms
64 bytes from 10.0.0.121: seq=2 ttl=64 time=0.376 ms
64 bytes from 10.0.0.121: seq=3 ttl=64 time=0.388 ms
YasserAntonio commented 2 years ago

same for 10.0.0.121

 /app/vikunja # ping 10.0.0.121
PING 10.0.0.121 (10.0.0.121): 56 data bytes
64 bytes from 10.0.0.121: seq=0 ttl=64 time=0.692 ms
64 bytes from 10.0.0.121: seq=1 ttl=64 time=0.425 ms
64 bytes from 10.0.0.121: seq=2 ttl=64 time=0.376 ms
kolaente commented 2 years ago

Can you connect to the MySQL port? Either with telnet or the MySQL console client?

If you replace the api container with something else entirely like debian and exec into that, is the behaviour the same?

kolaente commented 2 years ago

The ping time is really fast btw, are you sure the db container really is on a separate host?

If you check the IP of the db container with docker inspect is that the same as returned by ping?

YasserAntonio commented 2 years ago

Yes they are on different hosts, I have a good switch.

Okey I inspected the db's swarm ip (10.0.53.3) and it was different from the one used by the api which is the one set with db (10.0.0.121).

I used an phpmyadmin container deployed in the same compose with the same network and I had no issue to connect to the db with the right ip (10.0.53.3).

Thus my issue is that the value VIKUNJA_DATABASE_HOST: db is not good (10.0.0.121) instead of (10.0.53.3).

I tried to set VIKUNJA_DATABASE_HOST: 10.0.53.3 but at each deployment the ip changes which make this turnaround irrelevant.

Any idea how to solve this ?

YasserAntonio commented 2 years ago

I made it work by setting a hostname to the db service, still pretty weird I never had to do that on other deployments with a db and another service, adding db as the hostname was already enought. Here is the working compose ( with phpmyadmin) :

version: '3'

services:
  api:
    image: vikunja/api:0.18.1
    environment:
      VIKUNJA_DATABASE_HOST: db_vikunja
      VIKUNJA_DATABASE_PASSWORD: supersecret
      VIKUNJA_DATABASE_TYPE: mysql
      VIKUNJA_DATABASE_USER: vikunja
      VIKUNJA_DATABASE_DATABASE: vikunja
      VIKUNJA_SERVICE_ENABLEREGISTRATION: 1
    volumes:
      - /home/pi/vikunja/files:/app/vikunja/files
    networks:
      - traefik-local
      - db-local
    depends_on:
      - db
    deploy:
      labels:
        - "traefik.enable=true"
        - "traefik.http.routers.vikunja-api.rule=Host(`vikunja.ln`) && PathPrefix(`/api/v1`, `/dav/`, `/.well-known/`)"
        - "traefik.http.services.vikunja-api.loadbalancer.server.port=3456"
      placement:
        constraints:
          - 'node.hostname == Hestia'

  frontend:
    image: vikunja/frontend:0.18.1
    networks:
      - traefik-local
      - db-local
    deploy:
      labels:
        - "traefik.enable=true"
        - "traefik.http.routers.vikunja-frontend.rule=Host(`vikunja.ln`)"
        - "traefik.http.routers.vikunja-frontend.entrypoints=web"
        - "traefik.http.services.vikunja-frontend.loadbalancer.server.port=80"
      placement:
        constraints:
          - 'node.hostname == Hestia'

  db:
    image: linuxserver/mariadb:alpine-10.5.12-r0-ls36
    hostname: db_vikunja
    environment:
      - PUID=1000
      - PGID=1000
      - MYSQL_ROOT_PASSWORD=supersecret
      - TZ=Europe/Paris
      - MYSQL_DATABASE=vikunja #optional
      - MYSQL_USER=vikunja
      - MYSQL_PASSWORD=supersecret
    volumes:
      - /home/pi/vikunja/mariadb:/config
    networks:
      - db-local
    deploy:
      placement:
        constraints:
          - 'node.hostname == Polymatheia'

  db-client:
    image: linuxserver/phpmyadmin:5.2.0
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=Europe/Paris
      - PMA_ARBITRARY=1 #optional
    networks:
      - traefik-local
      - db-local
    volumes:
      - /home/pi/phpmyadmin/config:/config
    depends_on:
      - db
    cap_add:
     ["all"]
    deploy:
      labels:
        - "traefik.enable=true"
        - "traefik.http.routers.vikunja-db-client.rule=Host(`vikunja-db-client.ln`)"
        - "traefik.http.routers.vikunja-db-client.entrypoints=web"
        - "traefik.http.services.vikunja-db-client.loadbalancer.server.port=80"
      placement:
        constraints:
          - 'node.hostname == Hestia'

networks:
  traefik-local:
    external: true
  db-local:
    driver: overlay
kolaente commented 2 years ago

Huh interesting. Glad you figured it out in the end.

Closing as configuration-related, does not seem to be a bug in Vikunja.