Merge branch 'main' into register-deregister-actions

# Conflicts:
#	pkgs/ui/src/components/sequence_diagram/index.tsx
This commit is contained in:
Arslan, Erdem
2024-01-21 20:45:24 +01:00
7 changed files with 162 additions and 168 deletions

View File

@@ -2,33 +2,112 @@
The clan-cli contains the command line interface as well as the graphical webui through the `clan webui` command.
## Hacking on the cli
Start the web ui with
We recommend setting up [direnv](https://direnv.net/) to load the developement with nix.
If you do not have it set up you can also use `nix develop` directly like this:
```
use flake .#clan-cli --builders ''
```bash
clan webui --reload --no-open --log-level debug --populate --emulate
```
After you can use the local bin wrapper to test things in the cli:
- The `--populate` flag will automatically populate the database with dummy data
- To look into the endpoints open up a swagger instance by visiting: http://localhost:2979/docs
- The `--emulate` flag will automatically run servers the database with dummy data for the fronted to communicate with (ap, dlg, c1 and c2)
- To look into the emulated endpoints go to http://localhost:2979/emulate
```
./bin/clan
# Building a Docker Image
To build a docker image of the frontend and backend be inside the `pkgs/clan-cli` folder and execute:
```bash
nix build .#clan-docker
```
## Hacking on the webui
This will create a symlink directory called `result` to a tar.gz docker file. Import it by executing:
By default the webui is build from a tarball available https://git.clan.lol/clan/-/packages/generic/ui/.
To start a local developement environment instead, use the `--dev` flag:
```
./bin/clan webui --dev
```bash
docker load < result
```
This will spawn two webserver, a python one to for the api and a nodejs one that rebuilds the ui on the fly.
And then run the docker file by executing:
## Run webui directly
```bash
docker run -p 127.0.0.1:2979:2979 clan-docker:latest
```
# Auto Generating a Python Client
For the tests we automatically generate a python client for the API endpoints. To do this execute while inside the `pkgs/clan-cli` folder:
```bash
./bin/gen-python-client
```
This will replace the folder
`tests/openapi_client`.
# API Documentation
Api documentation can be found in the folder `pkgs/clan-cli/tests/openapi_client/docs/`
For Entity object go to [tests/openapi_client/docs/EntityCreate.md](tests/openapi_client/docs/EntityCreate.md)
# Debugging
When working on the backend of your project, debugging is an essential part of the development process. Here are some methods for debugging and testing the backend of your application:
## Test Backend Locally in Devshell with Breakpoints
To test the backend locally in a development environment and set breakpoints for debugging, follow these steps:
1. Run the following command to execute your tests and allow for debugging with breakpoints:
```bash
rm -f sql_app.db && pytest -s
```
You can place `breakpoint()` in your Python code where you want to trigger a breakpoint for debugging.
## Test Backend Locally in a Nix Sandbox
To run your backend tests in a Nix sandbox, you have two options depending on whether your test functions have been marked as impure or not:
### Running Tests Marked as Impure
If your test functions need to execute `nix build` and have been marked as impure because you can't execute `nix build` inside a Nix sandbox, use the following command:
```bash
nix run .#impure-checks
```
This command will run the impure test functions.
### Running Pure Tests
For test functions that have not been marked as impure and don't require executing `nix build`, you can use the following command:
```bash
nix build .#checks.x86_64-linux.clan-pytest --rebuild
```
This command will run all pure test functions.
### Inspecting the Nix Sandbox
If you need to inspect the Nix sandbox while running tests, follow these steps:
1. Insert an endless sleep into your test code where you want to pause the execution. For example:
```python
import time
time.sleep(3600) # Sleep for one hour
```
2. Use `cntr` and `psgrep` to attach to the Nix sandbox. This allows you to interactively debug your code while it's paused. For example:
```bash
psgrep -a -x your_python_process_name
cntr attach <pid>
```
These debugging and testing methods will help you identify and fix issues in your backend code efficiently, ensuring the reliability and robustness of your application.
## Run Web UI in VSCode
Useful for vscode run and debug option
@@ -53,18 +132,3 @@ Add this `launch.json` to your .vscode directory to have working breakpoints in
]
}
```
## Run locally single-threaded for debugging
By default tests run in parallel using pytest-xdist.
pytest-xdist however breaks `breakpoint()`. To disable it, use this:
```console
pytest -n0 -s
```
You can also run a single test like this:
```console
pytest -n0 -s tests/test_secrets_cli.py::test_users
```

View File

@@ -5,7 +5,7 @@ cors_url = [
"http://0.0.0.0",
"http://[::]",
]
cors_ports = [2979, 3000]
cors_ports = ["*", 3000, 2979]
# host for the server, frontend, backend and emulators
host = "127.0.0.1"

View File

@@ -12,6 +12,19 @@
};
inherit (self'.packages.clan-cli) clan-openapi;
default = self'.packages.clan-cli;
clan-docker = pkgs.dockerTools.buildImage {
name = "clan-docker";
tag = "latest";
created = "now";
config = {
Cmd = [ "${self'.packages.clan-cli}/bin/clan" "webui" "--no-open" "--host" "0.0.0.0" ];
ExposedPorts = {
"2979/tcp" = { };
};
};
};
};
checks = self'.packages.clan-cli.tests;

View File

@@ -1,5 +1,25 @@
# cLan - awesome UI
The files in `src/api` are autogenerated from the openapi.json. The openapi.json comes from the backend, from fastapi which autogenerates the openapi.json file from the python code.
We then use orval to generate typescript files to `src/api`
## Build Development Web UI
To build the dev web ui with hotreloading
```bash
npm run dev
```
## Build release Web UI
To build the release version execute
```bash
npm run build
```
## Updating dependencies
After changing dependencies with
@@ -16,14 +36,6 @@ To sort classnames manually:
`cd /clan-core/pkgs/ui/`
## Upload ui to gitea
## Troubleshooting
Create a gitea token here: https://git.clan.lol/user/settings/applications
Than run this command:
```
GITEA_TOKEN=<YOUR_TOKEN> nix run .#update-ui-assets
```
.
Sometimes new endpoints don't appear in `src/api`. Delete the `ui/openapi.json` file and execute `direnv reload`

View File

@@ -1,5 +1,5 @@
{ fetchzip }:
fetchzip {
url = "https://gitea.gchq.icu/api/packages/IoSL/generic/IoSL-service-aware-frontend/1m8l6mwmcwgl25pnh4gyzx7jgbfdrrmnqn61nqh10mmadlxh2lay/assets.tar.gz";
sha256 = "1m8l6mwmcwgl25pnh4gyzx7jgbfdrrmnqn61nqh10mmadlxh2lay";
url = "https://gitea.gchq.icu/api/packages/IoSL/generic/IoSL-service-aware-frontend/0c4ihz96c4q5d0ikjj7b6vpj43fsv0xnj1viicv8v5kjvdz8s6nw/assets.tar.gz";
sha256 = "0c4ihz96c4q5d0ikjj7b6vpj43fsv0xnj1viicv8v5kjvdz8s6nw";
}

View File

@@ -7,6 +7,7 @@ import { HomeTableConfig } from "@/config/home";
import dynamic from "next/dynamic";
import { useEffect } from "react";
import { mutate } from "swr";
import ErrorBoundary from "@/components/error_boundary";
const NoSSRSequenceDiagram = dynamic(
() => import("../../components/sequence_diagram"),
@@ -56,7 +57,9 @@ export default function Home() {
<div>
<h4>Sequence Diagram</h4>
<NoSSRSequenceDiagram />
<ErrorBoundary>
<NoSSRSequenceDiagram />
</ErrorBoundary>
</div>
</div>
);