Added better uri parsing, updated README
This commit is contained in:
parent
c00aa232fc
commit
5628e4f062
2 changed files with 36 additions and 3 deletions
30
README.md
30
README.md
|
@ -1,3 +1,33 @@
|
||||||
# dockge-cli
|
# dockge-cli
|
||||||
|
|
||||||
A simple CLI application written in Python for communicating with Dockge using websockets
|
A simple CLI application written in Python for communicating with Dockge using websockets
|
||||||
|
|
||||||
|
## Background
|
||||||
|
|
||||||
|
Dockge (spoken dock-ge or dockage) is a tool to manage docker-compose stacks from a web ui. It is developed by louislam, who also develops UptimeKuma.
|
||||||
|
|
||||||
|
Dockge itself doesn't offer any kind of API or programmatic access, as it is just intended for managing stacks via UI.
|
||||||
|
|
||||||
|
My current deployment solution for firq.dev and fgo-ta.com is based on Dockge, and I was over it always having to reload the stack whenever I pushed an update. Instead, I wanted to have this as a separate CI step, automatically redeploying a givens stack.
|
||||||
|
|
||||||
|
As Dockge is using a websocket-based system under the hood, it was easy to take a look at how communication occurs. In general, communication is achieved by leveraging socket.io for the data. Since Python already offers a solution for socket.io, it is just a matter of emulating the calls the webui sends and receives.
|
||||||
|
|
||||||
|
In the end, this is the current result that works pretty well for my understanding. I am still trying to improve upon some issues (login times out, stability, features), but in general this works as a fine solution for automatic stack updating.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
Install it from the custom package index using
|
||||||
|
|
||||||
|
```
|
||||||
|
pip install --extra-index-url https://forgejo.neshweb.net/api/packages/Firq/pypi/simple/ dockge-cli
|
||||||
|
```
|
||||||
|
|
||||||
|
Alternativly, install it using this repository. When installing for development, make sure to install with the additional dependencies
|
||||||
|
|
||||||
|
```
|
||||||
|
pip install -e .[lint,typing]
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Call the CLI using `dockge-cli` or `dockge`.
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
from getpass import getpass
|
from getpass import getpass
|
||||||
|
import re
|
||||||
|
|
||||||
from ...models import Credentials
|
from ...models import Credentials
|
||||||
from ...service import storage
|
from ...service import storage
|
||||||
|
@ -26,10 +27,12 @@ class FunctionBindings():
|
||||||
host command binding
|
host command binding
|
||||||
"""
|
"""
|
||||||
if len(extra_args) > 0:
|
if len(extra_args) > 0:
|
||||||
res = urlparse(extra_args[0])
|
mat = re.search(r"((\w+\.)?\w+\.\w+(\/.+)?)", extra_args[0], re.IGNORECASE)
|
||||||
|
if mat is None:
|
||||||
|
raise ValueError("Given host did not match regex")
|
||||||
|
res = urlparse(f"https://{mat[0]}")
|
||||||
if all([res.scheme, res.netloc]):
|
if all([res.scheme, res.netloc]):
|
||||||
host = extra_args[0].rstrip("/").replace("https://", "").replace("wss://", "")
|
storage.put("host", mat[0])
|
||||||
storage.put("host", host)
|
|
||||||
else:
|
else:
|
||||||
raise ValueError(f"Malformed URL {extra_args[0]}")
|
raise ValueError(f"Malformed URL {extra_args[0]}")
|
||||||
print(storage.get("host"))
|
print(storage.get("host"))
|
||||||
|
|
Loading…
Reference in a new issue