From 34cb6e5dc7e1e12fdfef245184052c58b6bf07d3 Mon Sep 17 00:00:00 2001
From: Firq <firelp42@gmail.com>
Date: Sat, 20 Jul 2024 17:25:34 +0200
Subject: [PATCH 01/10] Increased timeouts

---
 dockge_cli/service/connection.py | 15 ++++++++-------
 pyproject.toml                   |  4 ++--
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/dockge_cli/service/connection.py b/dockge_cli/service/connection.py
index 9fb063b..bcb3802 100644
--- a/dockge_cli/service/connection.py
+++ b/dockge_cli/service/connection.py
@@ -99,10 +99,11 @@ class DockgeConnection:
                         "password": storage.get("password", encoded=True),
                         "token": ""
                     },
-                    timeout=5
+                    timeout=10
                 )
                 retry = False
             except socketio.exceptions.TimeoutError:
+                print("Reached timeout for login, retrying ...")
                 retry = True
                 count += 1
 
@@ -125,42 +126,42 @@ class DockgeConnection:
         """
         Lists status for a stack
         """
-        ret = self._sio.call("agent", ("", "serviceStatusList", name), timeout=5)
+        ret = self._sio.call("agent", ("", "serviceStatusList", name), timeout=10)
         return ret
 
     def restart(self, name):
         """
         Restarts a given stack
         """
-        ret = self._sio.call("agent", ("", "restartStack", name), timeout=10)
+        ret = self._sio.call("agent", ("", "restartStack", name), timeout=30)
         return ret
 
     def update(self, name):
         """
         Updates a given stack
         """
-        ret = self._sio.call("agent", ("", "updateStack", name), timeout=10)
+        ret = self._sio.call("agent", ("", "updateStack", name), timeout=30)
         return ret
 
     def stop(self, name):
         """
         Stops a given stack
         """
-        ret = self._sio.call("agent", ("", "stopStack", name), timeout=10)
+        ret = self._sio.call("agent", ("", "stopStack", name), timeout=30)
         return ret
 
     def start(self, name):
         """
         Starts a given stack
         """
-        ret = self._sio.call("agent", ("", "startStack", name), timeout=10)
+        ret = self._sio.call("agent", ("", "startStack", name), timeout=30)
         return ret
 
     def down(self, name):
         """
         Stops and downs a given stack
         """
-        ret = self._sio.call("agent", ("", "downStack", name), timeout=10)
+        ret = self._sio.call("agent", ("", "downStack", name), timeout=30)
         return ret
 
     def disconnect(self):
diff --git a/pyproject.toml b/pyproject.toml
index 1412bbb..6371330 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,6 +1,6 @@
 [project]
 name = "dockge_cli"
-version = "0.1.0"
+version = "0.1.1-c.1"
 dependencies = [
     "pyyaml~=6.0.1",
     "pydantic~=2.8.0",
@@ -11,7 +11,7 @@ dependencies = [
 requires-python = ">= 3.10"
 authors = [{name = "Firq", email = "firelp42@gmail.com"}]
 maintainers = [{name = "Firq", email = "firelp42@gmail.com"}]
-description = "CLi for interacting with dockge"
+description = "CLI for interacting with dockge"
 classifiers = [
     "Development Status :: 3 - Alpha",
     "Programming Language :: Python :: 3",

From 44a04097985ebb68c4ec64a6f5e4b56adb931b9d Mon Sep 17 00:00:00 2001
From: Firq <firelp42@gmail.com>
Date: Sat, 20 Jul 2024 17:49:25 +0200
Subject: [PATCH 02/10] More logging

---
 dockge_cli/service/connection.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/dockge_cli/service/connection.py b/dockge_cli/service/connection.py
index bcb3802..35ba9a6 100644
--- a/dockge_cli/service/connection.py
+++ b/dockge_cli/service/connection.py
@@ -63,6 +63,7 @@ class DockgeConnection:
             success = True
         else:
             print("Issue with login procedure")
+            print(data)
         return success
 
     # Functions

From 003204afb137fe7c0678b20a47b68ab4b96bca14 Mon Sep 17 00:00:00 2001
From: Firq <firelp42@gmail.com>
Date: Mon, 22 Jul 2024 17:40:57 +0200
Subject: [PATCH 03/10] Add docker build step to provide ready-to-use dockge
 cli container

---
 .forgejo/workflows/build-release.yaml | 35 +++++++++++++++++++++++++++
 Dockerfile                            |  4 +++
 2 files changed, 39 insertions(+)
 create mode 100644 Dockerfile

diff --git a/.forgejo/workflows/build-release.yaml b/.forgejo/workflows/build-release.yaml
index 600b9b0..9bbcfd2 100644
--- a/.forgejo/workflows/build-release.yaml
+++ b/.forgejo/workflows/build-release.yaml
@@ -56,3 +56,38 @@ jobs:
         run: pip install twine
       - name: Upload package to registry
         run: python -m twine upload --repository-url ${{ secrets.REPOSITORY_URL }} -u ${{ secrets.TWINE_DEPLOY_USER }} -p ${{ secrets.TWINE_DEPLOY_PASSWORD }} dist/*
+
+  build-and-push-container:
+    needs: [ "publish-artifacts" ]
+    runs-on: dind
+    steps:
+      - name: Set up Docker Buildx
+        uses: docker/setup-buildx-action@v3
+      - name: Log into Docker Package Registry
+        uses: docker/login-action@v3
+        with:
+          registry: forgejo.neshweb.net
+          username: ${{ secrets.FORGEJO_USERNAME }}
+          password: ${{ secrets.FORGEJO_TOKEN }}
+      - name: Build and push to Docker Package Registry
+        uses: docker/build-push-action@v5
+        with:
+          context: .
+          build-args: |
+            PACKAGE_VERSION=${{ github.ref_name }}
+            push: true
+          tags: forgejo.neshweb.net/firq/dockge-cli:${{ github.ref_name }}
+
+  release:
+    needs: [ build-and-push-container, publish-artifacts ]
+    if: success()
+    runs-on: docker
+    steps:
+      - name: Release New Version
+        uses: actions/forgejo-release@v1
+        with:
+          direction: upload
+          url: https://forgejo.neshweb.net
+          release-dir: release
+          token: ${{ secrets.FORGEJO_TOKEN }}
+          tag: ${{  github.ref_name }}
\ No newline at end of file
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..88e754d
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,4 @@
+FROM forgejo.neshweb.net/ci-docker-images/python-neshweb:3.11
+
+ARG PACKAGE_VERSION=0.1.0
+RUN pip install dockge-cli==${PACKAGE_VERSION}

From ca5803bcccfa5a9575572c28c229f0ea60bda930 Mon Sep 17 00:00:00 2001
From: Firq <firelp42@gmail.com>
Date: Mon, 22 Jul 2024 17:42:48 +0200
Subject: [PATCH 04/10] Fixed version

---
 pyproject.toml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyproject.toml b/pyproject.toml
index 6371330..7e3f81e 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,6 +1,6 @@
 [project]
 name = "dockge_cli"
-version = "0.1.1-c.1"
+version = "0.1.1-c.2"
 dependencies = [
     "pyyaml~=6.0.1",
     "pydantic~=2.8.0",

From de234133f9fac7e516691288030af9844cec565b Mon Sep 17 00:00:00 2001
From: Firq <firelp42@gmail.com>
Date: Mon, 22 Jul 2024 17:44:54 +0200
Subject: [PATCH 05/10] Fixed workflow

---
 .forgejo/workflows/build-release.yaml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.forgejo/workflows/build-release.yaml b/.forgejo/workflows/build-release.yaml
index 9bbcfd2..6932d93 100644
--- a/.forgejo/workflows/build-release.yaml
+++ b/.forgejo/workflows/build-release.yaml
@@ -75,7 +75,7 @@ jobs:
           context: .
           build-args: |
             PACKAGE_VERSION=${{ github.ref_name }}
-            push: true
+          push: true
           tags: forgejo.neshweb.net/firq/dockge-cli:${{ github.ref_name }}
 
   release:

From 09da354b0ec9f56eb9eb5d95d9f16c8c414fe1e1 Mon Sep 17 00:00:00 2001
From: Firq <firelp42@gmail.com>
Date: Mon, 22 Jul 2024 17:47:06 +0200
Subject: [PATCH 06/10] Fixed workflow 2

---
 .forgejo/workflows/build-release.yaml | 1 -
 1 file changed, 1 deletion(-)

diff --git a/.forgejo/workflows/build-release.yaml b/.forgejo/workflows/build-release.yaml
index 6932d93..48e5e92 100644
--- a/.forgejo/workflows/build-release.yaml
+++ b/.forgejo/workflows/build-release.yaml
@@ -72,7 +72,6 @@ jobs:
       - name: Build and push to Docker Package Registry
         uses: docker/build-push-action@v5
         with:
-          context: .
           build-args: |
             PACKAGE_VERSION=${{ github.ref_name }}
           push: true

From fc7ecdcd774e9fddd4c0b1204521409c5d4645bc Mon Sep 17 00:00:00 2001
From: Firq <firelp42@gmail.com>
Date: Thu, 15 Aug 2024 23:09:02 +0200
Subject: [PATCH 07/10] Readme

---
 README.md | 38 ++++++++++++++++++++++++++++++++++++--
 1 file changed, 36 insertions(+), 2 deletions(-)

diff --git a/README.md b/README.md
index 3ce3770..2f946e3 100644
--- a/README.md
+++ b/README.md
@@ -18,16 +18,50 @@ In the end, this is the current result that works pretty well for my understandi
 
 Install it from the custom package index using
 
-```
+```shell
 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
 
-```
+```shell
 pip install -e .[lint,typing]
 ```
 
 ## Usage
 
 Call the CLI using `dockge-cli` or `dockge`.
+
+```shell
+usage: dockge_cli [-h] [--version] {host,login,logout,list,status,restart,start,stop,down,update,exit,help}
+
+CLI interface for interacting with Dockge
+
+positional arguments:
+  {host,login,logout,list,status,restart,start,stop,down,update,exit,help}
+
+options:
+  -h, --help            show this help message and exit
+  --version             show program's version number and exit
+```
+
+Help for each individual command can be invoked by calling `dockge-cli help <command>`
+
+## The magic behind this
+
+Generally, this makes use of the underlying Websockets API that the Dockge frontend uses to communicate with the server. By analyzing the traffic and looking into the codebase, I was able to reverse most of the packets that are being sent. This allows me to then contruct, send and receive my own packets, making the whole thing work.
+
+There are some things that need to be taken into account for this: For one, dockge uses socket.io for the websocket communication. This meant I had to find the corresponding socket.io version to get the correct version of python-socketio. In addition, I had to find out how the authorization mechanism behind this works.
+
+After finishing up the first prototype, the workings are as follows:
+
+1. A websocket session is established using socket.io - this happens automatically
+2. After the session is ready, the `login` command is sent together with a provided username and password
+3. Once the CLI is authorized, the selected command is sent
+4. The CLI waits for any response values and exits once the command has executed successfully
+
+To provide a smooth experience, both the credentials and the remote host URI are stored on disk. just like the `docker` cli, the credentials are not encrypted, meaning it is advised to either clear the credentials after use OR to use the `--username` and `--password` parameters. This is especially recommended for CI applications.
+
+## Known issues
+
+This CLI does not work when Mullvad is used, as Mullvad actively blocks port forwarding (which python-socketio uses)

From 401e446059320a325ed5fc0e6de4df0fc8d498ef Mon Sep 17 00:00:00 2001
From: Firq <firelp42@gmail.com>
Date: Sat, 28 Sep 2024 15:39:22 +0200
Subject: [PATCH 08/10] Release 0.1.1

---
 pyproject.toml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyproject.toml b/pyproject.toml
index 7e3f81e..43d9c5d 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,6 +1,6 @@
 [project]
 name = "dockge_cli"
-version = "0.1.1-c.2"
+version = "0.1.1"
 dependencies = [
     "pyyaml~=6.0.1",
     "pydantic~=2.8.0",

From ed24d59a9203631d1066036f04f7fcde8054a510 Mon Sep 17 00:00:00 2001
From: Firq <firelp42@gmail.com>
Date: Tue, 1 Oct 2024 23:24:31 +0200
Subject: [PATCH 09/10] HTTP long polling before upgrade

---
 dockge_cli/service/connection.py | 2 +-
 pyproject.toml                   | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/dockge_cli/service/connection.py b/dockge_cli/service/connection.py
index 35ba9a6..78e7582 100644
--- a/dockge_cli/service/connection.py
+++ b/dockge_cli/service/connection.py
@@ -72,7 +72,7 @@ class DockgeConnection:
         Connect to the websocket
         """
         # Dockge uses Socket.io for the websockets, so this URI and params are always the same
-        self._sio.connect(f"https://{self._host}/socket.io/", transports=['websocket'])
+        self._sio.connect(f"https://{self._host}/socket.io/")
         self.login()
 
     def login(self):
diff --git a/pyproject.toml b/pyproject.toml
index 43d9c5d..39793ce 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -4,6 +4,7 @@ version = "0.1.1"
 dependencies = [
     "pyyaml~=6.0.1",
     "pydantic~=2.8.0",
+    "requests~=2.32.3",
     "python-socketio~=5.11.3",
     "websocket-client~=1.8.0",
     "tabulate ~=0.9.0",

From ac982668c73b7e6a296e755c3ffff3174b4caa17 Mon Sep 17 00:00:00 2001
From: Firq <firelp42@gmail.com>
Date: Tue, 1 Oct 2024 23:25:30 +0200
Subject: [PATCH 10/10] HTTP long polling before upgrade

---
 pyproject.toml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyproject.toml b/pyproject.toml
index 39793ce..b706b37 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,6 +1,6 @@
 [project]
 name = "dockge_cli"
-version = "0.1.1"
+version = "0.1.2"
 dependencies = [
     "pyyaml~=6.0.1",
     "pydantic~=2.8.0",