k3nd0x / piglet

Simple Webapp to manage and administrate budgets in a household
https://hub.docker.com/r/k3nd0x/piglet
GNU General Public License v3.0
100 stars 1 forks source link

Piglet is "waiting for database host" #6

Closed shyonae closed 1 year ago

shyonae commented 1 year ago

Hi everyone, here's my compose:

version: "3.8"
services:
  piglet:
    restart: unless-stopped
    container_name: piglet
    depends_on:
      - database
    ports:
      - 8089:80
      - 8087:8080
    image: k3nd0x/piglet:latest
    networks:
      - shyDockerServer
    environment:
      DB_ROOT_PASSWORD: ${PIGLET_DB_ROOT_PASSWORD}
      #MYSQL_DATABASE: ${MYSQL_DATABASE} # Default 'piglet'
      #MYSQL_USER: ${MYSQL_USER} # Default 'piglet'
      #MYSQL_PASSWORD: ${MYSQL_PASSWORD}
      #MYSQL_HOST: ${MYSQL_HOST}
      #MAIL_SERVER: ${MAIL_SERVER}
      #MAIL_USER: ${MAIL_USER}
      #MAIL_PASSWORD: ${MAIL_PASSWORD}
      #MAIL_PORT: ${MAIL_PORT}
      #MAIL_ENCRYPTIONPROTOCOL: ${MAIL_ENCRYPTIONPROTOCOL}
      #DOMAIN: ${DOMAIN} # Default 'localhost'
      #SECURE_COOKIE: ${SECURE_COOKIE}
    volumes:
      - "/etc/timezone:/etc/timezone:ro"
      - "/etc/localtime:/etc/localtime:ro"
    labels:
      - swag=enable
      - swag_auth=authelia
  database:
    image: mariadb:latest
    container_name: piglet-db
    volumes:
      - ${DOCKERCONFDIR}/piglet/mysql:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: ${PIGLET_DB_ROOT_PASSWORD}

networks:
  shyDockerServer:
    driver: bridge
    external: true

And here are the container logs:

Why doesn't the Piglet main container connect? I've basically used the default compose + some networking stuff.

k3nd0x commented 1 year ago

Hi, I will test your setup and come back to you soon...

k3nd0x commented 1 year ago

I think both containers should be in one network. You only add the piglet container to your shyDockerServer Network. And the piglet db container will get an ip of the default docker network. So they cannot communicate to each other :)

shyonae commented 1 year ago

I think both containers should be in one network. You only add the piglet container to your shyDockerServer Network. And the piglet db container will get an ip of the default docker network. So they cannot communicate to each other :)

Ah you're right! I don't know how that escaped my sights, I'll try when I get home and update the issue, thanks

shyonae commented 1 year ago

It worked, but now I'm having another kind of problem, this happens when I try to create a new user:

################################# DEBUG ############################## 4
INFO:     127.0.0.1:55782 - "POST /user/register_user HTTP/1.1" 500 Internal Server Error
ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/webapp/api/routes/sendmail.py", line 61, in mail
    s = SMTP(host, int(port))
ValueError: invalid literal for int() with base 10: ''

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/uvicorn/protocols/http/h11_impl.py", line 408, in run_asgi    
    result = await app(  # type: ignore[func-returns-value]
  File "/usr/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 84, in __call__
    return await self.app(scope, receive, send)
  File "/usr/lib/python3.10/site-packages/fastapi/applications.py", line 289, in __call__
    await super().__call__(scope, receive, send)
  File "/usr/lib/python3.10/site-packages/starlette/applications.py", line 122, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/usr/lib/python3.10/site-packages/starlette/middleware/errors.py", line 184, in __call__        
    raise exc
  File "/usr/lib/python3.10/site-packages/starlette/middleware/errors.py", line 162, in __call__        
    await self.app(scope, receive, _send)
  File "/usr/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 79, in __call__     
    raise exc
  File "/usr/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 68, in __call__     
    await self.app(scope, receive, sender)
  File "/usr/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 20, in __call__   
    raise e
  File "/usr/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 17, in __call__   
    await self.app(scope, receive, send)
  File "/usr/lib/python3.10/site-packages/starlette/routing.py", line 718, in __call__
    await route.handle(scope, receive, send)
  File "/usr/lib/python3.10/site-packages/starlette/routing.py", line 276, in handle
    await self.app(scope, receive, send)
  File "/usr/lib/python3.10/site-packages/starlette/routing.py", line 66, in app
    response = await func(request)
  File "/usr/lib/python3.10/site-packages/fastapi/routing.py", line 273, in app
    raw_response = await run_endpoint_function(
  File "/usr/lib/python3.10/site-packages/fastapi/routing.py", line 190, in run_endpoint_function       
    return await dependant.call(**values)
  File "/webapp/api/routes/user.py", line 72, in register_user
    mail(payload)
  File "/webapp/api/routes/sendmail.py", line 69, in mail
    except SMTPResponseException as e:
NameError: name 'SMTPResponseException' is not defined

And these are the logs for the DB:

2023-08-22 12:31:24 3 [Warning] Aborted connection 3 to db: 'unconnected' user: 'unauthenticated' host: 
'172.22.0.3' (This connection closed normally without authentication)
2023-08-22 12:31:35 9 [Warning] Aborted connection 9 to db: 'piglet' user: 'piglet' host: '' (Got an error reading communication packets)
2023-08-22 12:32:31 10 [Warning] Aborted connection 10 to db: 'piglet' user: 'piglet' host: '' (Got an error reading communication packets)
2023-08-22 12:34:09 16 [Warning] Aborted connection 16 to db: 'piglet' user: 'piglet' host: '' (Got an error reading communication packets)

Any ideas on what I might be doing wrong? The passwords are the same. If this is for another issue, I'll open it and close this :)

k3nd0x commented 1 year ago

Ou yes this is another issue. Please create a new one. The app is trying to send a "Email-Verify-Mail" but it can't without config. I have to update the code. But the user was created right?