WIP: trigger nixops from panel #246

Closed
kiara wants to merge 36 commits from kiara/Fediversity:stitching into main
Owner

closes .

As a workaround to pass info (from our user form) into nixops4 uses environment variable DEPLOYMENT thru nix's --extra-experimental-features configurable-impure-env.

Things to be tested:

  • manual deployment (make sure to use nix over lix):
    DEPLOYMENT='{"domain": "fediversity.net", "mastodon": {"enable": false}, "pixelfed": {"enable": true}, "peertube": {"enable": false}, "initialUser": {"displayName": "Testy McTestface", "username": "test", "password": "testtest", "email": "test@test.com"}}' nix develop --extra-experimental-features "configurable-impure-env" --command nixops4 apply test
    
  • deploy button works in development (cd panel; nix-shell; manage runserver -> trigger deploy button in form at 127.0.0.1:8000)
  • deploy button works in production (nix develop; nixops4 apply -> trigger deploy button in form at https://demo.fediversity.eu/)
    • status: despite seemingly successful deploy to demo causes HTTP 502 (before being able to load the panel to press buttons)
  • make automated test
closes #76. As a workaround to pass info (from our user form) into nixops4 uses environment variable `DEPLOYMENT` thru nix's `--extra-experimental-features configurable-impure-env`. Things to be tested: - [x] manual deployment (make sure to use nix over lix): ```sh DEPLOYMENT='{"domain": "fediversity.net", "mastodon": {"enable": false}, "pixelfed": {"enable": true}, "peertube": {"enable": false}, "initialUser": {"displayName": "Testy McTestface", "username": "test", "password": "testtest", "email": "test@test.com"}}' nix develop --extra-experimental-features "configurable-impure-env" --command nixops4 apply test ``` - [x] deploy button works in development (`cd panel; nix-shell; manage runserver` -> trigger deploy button in form at 127.0.0.1:8000) - [ ] deploy button works in production (`nix develop; nixops4 apply` -> trigger deploy button in form at https://demo.fediversity.eu/) - status: despite seemingly successful deploy to demo causes HTTP 502 (before being able to load the panel to press buttons) - [ ] make automated test
kiara added 8 commits 2025-03-12 16:33:24 +01:00
- test the form interaction for a fixed schema version
- also add a database migration missed in the last commit
Closes .

Note I had not yet manage to successfully test this.

Manually trying the parameterized NixOps4 I tried using the following
command, tho I had yet to get this to work as well:

```sh
DEPLOYMENT='{"domain": "fediversity.net", "mastodon": {"enable": false},
"pixelfed": {"enable": true}, "peertube": {"enable": false}}' nix
develop --extra-experimental-features "configurable-impure-env"
--command nixops4 apply test
```

(or rather, I used a hardcoded Nix here so as to make it not use Lix.)

So far this had failed for me with:

```
the following units failed:
acme-mastodon.web.garage.fediversity.net.service
...
nixops4 error: Failed to create resource garage-configuration
```
WIP: Get nix in scope
kiara added 1 commit 2025-03-13 13:29:32 +01:00
kiara added 1 commit 2025-03-13 13:50:55 +01:00
kiara force-pushed stitching from 481dcf3223 to 40060f19b6 2025-03-13 15:34:02 +01:00 Compare
kiara added 1 commit 2025-03-13 16:30:44 +01:00
kiara added 1 commit 2025-03-17 13:24:29 +01:00
kiara added 1 commit 2025-03-17 13:51:03 +01:00
kiara added 1 commit 2025-03-17 14:10:32 +01:00
kiara added 1 commit 2025-03-17 14:23:37 +01:00
kiara force-pushed stitching from 561d50cf50 to f50ee049f2 2025-03-17 15:13:31 +01:00 Compare
Owner

the reason why there is a 502 seems to be the following

The nginx log seems to get a connection refused from the panel

Mar 18 08:40:15 fedi201 nginx[32351]: 2025/03/18 08:40:15 [error] 32351#32351: *2983 connect() failed (111: Connection refused) while connecting to upstream, client: 185.206.232.76, server: demo.fediversity.eu, request: "GET / HTTP/2.0>
Mar 18 08:40:15 fedi201 nginx[32351]: 2025/03/18 08:40:15 [error] 32351#32351: *2983 connect() failed (111: Connection refused) while connecting to upstream, client: 185.206.232.76, server: demo.fediversity.eu, request: "GET / HTTP/2.0>
Mar 18 08:48:02 fedi201 nginx[32351]: 2025/03/18 08:48:02 [error] 32351#32351: *2986 connect() failed (111: Connection refused) while connecting to upstream, client: 95.214.53.106, server: demo.fediversity.eu, request: "GET / HTTP/1.1">

which make sense since de the panel service is failed

[root@fedi201:~]# systemctl status panel
× panel.service - panel ASGI server
     Loaded: loaded (/etc/systemd/system/panel.service; enabled; preset: ignored)
     Active: failed (Result: exit-code) since Tue 2025-03-18 08:56:27 CET; 8min ago
   Duration: 382ms
 Invocation: d59a00cf7d1242e9a34db686336214ab
    Process: 38838 ExecStartPre=/nix/store/c9rsxyyg5mvjnp4qyq2k016qfw8r6iac-unit-script-panel-pre-start/bin/panel-pre-start (code=exited, status=0/SUCCESS)
    Process: 38843 ExecStart=/nix/store/89cms2c53lzccbdczdn574icbkaa9vvw-unit-script-panel-start/bin/panel-start (code=exited, status=1/FAILURE)
   Main PID: 38843 (code=exited, status=1/FAILURE)

Mar 18 08:56:27 fedi201 systemd[1]: panel.service: Scheduled restart job, restart counter is at 5.
Mar 18 08:56:27 fedi201 systemd[1]: panel.service: Start request repeated too quickly.
Mar 18 08:56:27 fedi201 systemd[1]: panel.service: Failed with result 'exit-code'.
Mar 18 08:56:27 fedi201 systemd[1]: Failed to start panel ASGI server.

and the cause of that seems to be the following

Mar 18 08:56:26 fedi201 systemd[1]: panel.service: Scheduled restart job, restart counter is at 4.
Mar 18 08:56:26 fedi201 systemd[1]: Starting panel ASGI server...
Mar 18 08:56:26 fedi201 systemd[1]: Started panel ASGI server.
Mar 18 08:56:26 fedi201 panel-start[38845]: Traceback (most recent call last):
Mar 18 08:56:26 fedi201 panel-start[38845]:   File "/nix/store/29nryh37jmmy4n91za8fyj2iri18x2fs-python3.12-panel-0.0.0/lib/python3.12/site-packages/panel/settings.py", line 35, in get_secret
Mar 18 08:56:26 fedi201 panel-start[38845]:     with open(f"{credentials_dir}/{name}", encoding=encoding) as f:
Mar 18 08:56:26 fedi201 panel-start[38845]:          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Mar 18 08:56:26 fedi201 panel-start[38845]: FileNotFoundError: [Errno 2] No such file or directory: '/var/lib/panel/.credentials/SECRET_KEY'
Mar 18 08:56:26 fedi201 panel-start[38845]: During handling of the above exception, another exception occurred:
Mar 18 08:56:26 fedi201 panel-start[38845]: Traceback (most recent call last):

and the .CREDENTIALS indeed doesnt exist

[root@fedi201:~]# ls -a /var/lib/panel/
.  ..  db.sqlite3  package-version  static
the reason why there is a 502 seems to be the following The nginx log seems to get a connection refused from the panel ``` Mar 18 08:40:15 fedi201 nginx[32351]: 2025/03/18 08:40:15 [error] 32351#32351: *2983 connect() failed (111: Connection refused) while connecting to upstream, client: 185.206.232.76, server: demo.fediversity.eu, request: "GET / HTTP/2.0> Mar 18 08:40:15 fedi201 nginx[32351]: 2025/03/18 08:40:15 [error] 32351#32351: *2983 connect() failed (111: Connection refused) while connecting to upstream, client: 185.206.232.76, server: demo.fediversity.eu, request: "GET / HTTP/2.0> Mar 18 08:48:02 fedi201 nginx[32351]: 2025/03/18 08:48:02 [error] 32351#32351: *2986 connect() failed (111: Connection refused) while connecting to upstream, client: 95.214.53.106, server: demo.fediversity.eu, request: "GET / HTTP/1.1"> ``` which make sense since de the panel service is failed ``` [root@fedi201:~]# systemctl status panel × panel.service - panel ASGI server Loaded: loaded (/etc/systemd/system/panel.service; enabled; preset: ignored) Active: failed (Result: exit-code) since Tue 2025-03-18 08:56:27 CET; 8min ago Duration: 382ms Invocation: d59a00cf7d1242e9a34db686336214ab Process: 38838 ExecStartPre=/nix/store/c9rsxyyg5mvjnp4qyq2k016qfw8r6iac-unit-script-panel-pre-start/bin/panel-pre-start (code=exited, status=0/SUCCESS) Process: 38843 ExecStart=/nix/store/89cms2c53lzccbdczdn574icbkaa9vvw-unit-script-panel-start/bin/panel-start (code=exited, status=1/FAILURE) Main PID: 38843 (code=exited, status=1/FAILURE) Mar 18 08:56:27 fedi201 systemd[1]: panel.service: Scheduled restart job, restart counter is at 5. Mar 18 08:56:27 fedi201 systemd[1]: panel.service: Start request repeated too quickly. Mar 18 08:56:27 fedi201 systemd[1]: panel.service: Failed with result 'exit-code'. Mar 18 08:56:27 fedi201 systemd[1]: Failed to start panel ASGI server. ``` and the cause of that seems to be the following ``` Mar 18 08:56:26 fedi201 systemd[1]: panel.service: Scheduled restart job, restart counter is at 4. Mar 18 08:56:26 fedi201 systemd[1]: Starting panel ASGI server... Mar 18 08:56:26 fedi201 systemd[1]: Started panel ASGI server. Mar 18 08:56:26 fedi201 panel-start[38845]: Traceback (most recent call last): Mar 18 08:56:26 fedi201 panel-start[38845]: File "/nix/store/29nryh37jmmy4n91za8fyj2iri18x2fs-python3.12-panel-0.0.0/lib/python3.12/site-packages/panel/settings.py", line 35, in get_secret Mar 18 08:56:26 fedi201 panel-start[38845]: with open(f"{credentials_dir}/{name}", encoding=encoding) as f: Mar 18 08:56:26 fedi201 panel-start[38845]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Mar 18 08:56:26 fedi201 panel-start[38845]: FileNotFoundError: [Errno 2] No such file or directory: '/var/lib/panel/.credentials/SECRET_KEY' Mar 18 08:56:26 fedi201 panel-start[38845]: During handling of the above exception, another exception occurred: Mar 18 08:56:26 fedi201 panel-start[38845]: Traceback (most recent call last): ``` and the .CREDENTIALS indeed doesnt exist ``` [root@fedi201:~]# ls -a /var/lib/panel/ . .. db.sqlite3 package-version static ```
kiara force-pushed stitching from f50ee049f2 to 3e2c83435d 2025-03-18 09:56:17 +01:00 Compare
kiara added 1 commit 2025-03-18 11:38:32 +01:00
makes `nixops4 apply` go thru, tho the service still fails on `No module
named 'django_pydantic_field'`
kiara added 1 commit 2025-03-18 14:46:28 +01:00
lois added 17 commits 2025-03-18 15:45:51 +01:00
Closes .

Note I had not yet manage to successfully test this.

Manually trying the parameterized NixOps4 I tried using the following
command, tho I had yet to get this to work as well:

```sh
DEPLOYMENT='{"domain": "fediversity.net", "mastodon": {"enable": false},
"pixelfed": {"enable": true}, "peertube": {"enable": false}}' nix
develop --extra-experimental-features "configurable-impure-env"
--command nixops4 apply test
```

(or rather, I used a hardcoded Nix here so as to make it not use Lix.)

So far this had failed for me with:

```
the following units failed:
acme-mastodon.web.garage.fediversity.net.service
...
nixops4 error: Failed to create resource garage-configuration
```
WIP: Get nix in scope
08d109cc82/services/fediversity/sharedOptions.nix (L44)
kevin added 1 commit 2025-03-18 16:25:39 +01:00
lois added 1 commit 2025-03-18 16:58:27 +01:00
kiara reviewed 2025-03-18 17:31:51 +01:00
@ -44,0 +54,4 @@
return obj
def run_deployment(self, obj):
if "deploy" in self.request.POST.keys():
Author
Owner

@kevin is there a reason we perform this check twice now?

@kevin is there a reason we perform this check twice now?
kiara reviewed 2025-03-18 17:32:59 +01:00
@ -42,2 +49,4 @@
)
if "deploy" in self.request.POST.keys():
threading.Thread(target=self.run_deployment, args=(obj,)).start()
Author
Owner

@kevin do we have a way to return info back to the client this way? or would the client know what it needs to know for now?

@kevin do we have a way to return info back to the client this way? or would the client know what it needs to know for now?
Author
Owner

given this pr got convoluted with commits for , i'll close this to split things up.
a distilled pr covering a local PR button is now up in reviewable state at .

given this pr got convoluted with commits for #74, i'll close this to split things up. a distilled pr covering a local PR button is now up in reviewable state at #253.
kiara closed this pull request 2025-03-18 18:25:41 +01:00
All checks were successful
/ check-pre-commit (pull_request) Successful in 25s
Required
Details
/ check-website (pull_request) Successful in 10s
Required
Details
/ check-peertube (pull_request) Successful in 21s
Required
Details

Pull request closed

Sign in to join this conversation.
No description provided.