SelfhostedPro / Yacht

A web interface for managing docker containers with an emphasis on templating to provide 1 click deployments. Think of it like a decentralized app store for servers that anyone can make packages for.
MIT License
3.32k stars 158 forks source link

[Bug Report] Unhandled error: No internet access when adding templates #512

Closed gelven4sec closed 4 weeks ago

gelven4sec commented 2 years ago

Describe the bug When your Yacht instance doesn't have internet access (which was my fault), and trying to add templates, you get an unhandled error. The thing is that it took me a moment to see that the problem was coming from my containers not having internet access.

To Reproduce Steps to reproduce the behavior:

  1. Work in a compagny with a way too strong security policy
  2. Have your Docker containers not having internet access and hardly know why.
  3. Try to adding templates image
  4. See error image

Expected behavior image I'm not difficult with the message but there gotta be a smiley sharing my feelings.

Desktop (please complete the following information):

Logs The point of this issue is to deal with the exception printed in the container logs. (The 3 last lines says it all)

ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/uvicorn/protocols/http/httptools_impl.py", line 390, in run_asgi
    result = await app(self.scope, self.receive, self.send)
  File "/usr/lib/python3.8/site-packages/uvicorn/middleware/proxy_headers.py", line 45, in __call__
    return await self.app(scope, receive, send)
  File "/usr/lib/python3.8/site-packages/fastapi/applications.py", line 199, in __call__
    await super().__call__(scope, receive, send)
  File "/usr/lib/python3.8/site-packages/starlette/applications.py", line 111, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/usr/lib/python3.8/site-packages/starlette/middleware/errors.py", line 181, in __call__
    raise exc from None
  File "/usr/lib/python3.8/site-packages/starlette/middleware/errors.py", line 159, in __call__
    await self.app(scope, receive, _send)
  File "/usr/lib/python3.8/site-packages/starlette/exceptions.py", line 82, in __call__
    raise exc from None
  File "/usr/lib/python3.8/site-packages/starlette/exceptions.py", line 71, in __call__
    await self.app(scope, receive, sender)
  File "/usr/lib/python3.8/site-packages/starlette/routing.py", line 566, in __call__
    await route.handle(scope, receive, send)
  File "/usr/lib/python3.8/site-packages/starlette/routing.py", line 227, in handle
    await self.app(scope, receive, send)
  File "/usr/lib/python3.8/site-packages/starlette/routing.py", line 41, in app
    response = await func(request)
  File "/usr/lib/python3.8/site-packages/fastapi/routing.py", line 201, in app
    raw_response = await run_endpoint_function(
  File "/usr/lib/python3.8/site-packages/fastapi/routing.py", line 150, in run_endpoint_function
    return await run_in_threadpool(dependant.call, **values)
  File "/usr/lib/python3.8/site-packages/starlette/concurrency.py", line 34, in run_in_threadpool
    return await loop.run_in_executor(None, func, *args)
  File "/usr/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/./api/routers/templates.py", line 61, in add_template
    return crud.add_template(db=db, template=template)
  File "/./api/db/crud/templates.py", line 133, in add_template
    raise HTTPException(status_code=err.status_code, detail=err.explanation)
AttributeError: 'URLError' object has no attribute 'status_code'

PS: I'm really excited about this project. Great work !

EDIT: I just noticed that the screenshots could be misleading, I successfully added templates before making those screenshots.

wickedyoda commented 2 years ago

This will be an issue because yachts or just like portainers and others have to query the template file. Unless it's on a gitlab or a platform hosted internally. Not really a bug or a yacht issue. Internet access will be required in some cases.

Self-hosted would be best to answer this, he is down sick and should be returning in a week or so.

wickedyoda commented 2 years ago

@SelfhostedPro Is there a way to load the templates locally from a file instead of a URL.

SelfhostedPro commented 2 years ago

@SelfhostedPro Is there a way to load the templates locally from a file instead of a URL.

Yeah there is. I don’t remember the nomenclature though. I’ll try to find it.

I can add an error if there’s no satus_code attribute to throw that. Ty for the feedback and relevant logs.

SelfhostedPro commented 2 years ago

I will make sure the error has a smiley in it just for you

wickedyoda commented 2 years ago

I will make sure the error has a smiley in it just for you

Take care of yourself first; covid can get serious fast and takes time to recover.

gelven4sec commented 2 years ago

Hi,

I'm sorry to hear that you got sick, I wish you to recover soon.

This will be an issue because yachts or just like portainers and others have to query the template file. Unless it's on a gitlab or a platform hosted internally. Not really a bug or a yacht issue. Internet access will be required in some cases.

Self-hosted would be best to answer this, he is down sick and should be returning in a week or so.

Of course Yacht should have internet access, this was misconfiguration of mine. It just took me a moment to see that the problem was coming from that. So to prevent this in the future, the error message should be a little more specifiq.

A lot of services aren't able to point out that there is a missing internet connection, I was playing with another container which told me that my credentials were wrong instead of telling me it had no internet access.

Anyway, I'm a bit of a Python developer myself and this being a very minor issue I could see myself writing a PR to fix it. If it doesn't imply touching anything in the front, this should be an easy fix.

So you guys let that issue aside for a while and I see if I can take care of this myself.

brccabral commented 1 year ago

Hi @sven-eliasen , any luck?

gelven4sec commented 1 year ago

Hi @sven-eliasen , any luck?

Hi, I spent a time trying to setup the developpement environement but didn't figured this out yet.

I actually got into something else and I don't know when I will be woriking on this.

heatzync commented 1 year ago

Hi @wickedyoda and @SelfhostedPro

I would also like to know how to load the templates locally from a file instead of a URL.

I tried the following:

/path/to/template.json
file:/path/to/template.json
file:///path/to/template.json

without success. All fail with the same error as @sven-eliasen showed above:

ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/usr/lib/python3.8/site-packages/uvicorn/protocols/http/httptools_impl.py", line 390, in run_asgi
    result = await app(self.scope, self.receive, self.send)
  File "/usr/lib/python3.8/site-packages/uvicorn/middleware/proxy_headers.py", line 45, in __call__
    return await self.app(scope, receive, send)
  File "/usr/lib/python3.8/site-packages/fastapi/applications.py", line 199, in __call__
    await super().__call__(scope, receive, send)
  File "/usr/lib/python3.8/site-packages/starlette/applications.py", line 111, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/usr/lib/python3.8/site-packages/starlette/middleware/errors.py", line 181, in __call__
    raise exc from None
  File "/usr/lib/python3.8/site-packages/starlette/middleware/errors.py", line 159, in __call__
    await self.app(scope, receive, _send)
  File "/usr/lib/python3.8/site-packages/starlette/exceptions.py", line 82, in __call__
    raise exc from None
  File "/usr/lib/python3.8/site-packages/starlette/exceptions.py", line 71, in __call__
    await self.app(scope, receive, sender)
  File "/usr/lib/python3.8/site-packages/starlette/routing.py", line 566, in __call__
    await route.handle(scope, receive, send)
  File "/usr/lib/python3.8/site-packages/starlette/routing.py", line 227, in handle
    await self.app(scope, receive, send)
  File "/usr/lib/python3.8/site-packages/starlette/routing.py", line 41, in app
    response = await func(request)
  File "/usr/lib/python3.8/site-packages/fastapi/routing.py", line 201, in app
    raw_response = await run_endpoint_function(
  File "/usr/lib/python3.8/site-packages/fastapi/routing.py", line 150, in run_endpoint_function
    return await run_in_threadpool(dependant.call, **values)
  File "/usr/lib/python3.8/site-packages/starlette/concurrency.py", line 34, in run_in_threadpool
    return await loop.run_in_executor(None, func, *args)
  File "/usr/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/./api/routers/templates.py", line 61, in add_template
    return crud.add_template(db=db, template=template)
  File "/./api/db/crud/templates.py", line 133, in add_template
    raise HTTPException(status_code=err.status_code, detail=err.explanation)
AttributeError: 'URLError' object has no attribute 'status_code'

Will you please point me to the documentation (I wasn't able to find it) or just drop an example here?

SelfhostedPro commented 1 year ago

You can just host the template in a simple web server container like nginx.

if you need it locally, you’ll need to bind mount it into the container. This is how one user does it but I haven’t tested it:

1: Navigate to /: cd /. 2: Download an example: wget https://raw.githubusercontent.com/SelfhostedPro/selfhosted_templates/master/Template/yacht.json. 3: Open the browser with the Yacht's URL (default: https://localhost:8000). 4: Go to /#/templates/new (default: https://localhost:8000/#/templates/new). 5: Fill the name field with any content. 6: Fill the URL field with file:///yacht.json.