Finished README for backend
All checks were successful
checks-impure / test (pull_request) Successful in 25s
checks / test (pull_request) Successful in 1m16s

This commit is contained in:
2024-01-24 17:53:46 +01:00
parent 3c6cbe01e8
commit fba6dcb70a
3 changed files with 139 additions and 21 deletions

View File

@@ -33,6 +33,63 @@ And then run the docker file by executing:
docker run -p 127.0.0.1:2979:2979 clan-docker:latest
```
- To change parameters in the generated docker image edit the file :
[flake-module.nix at line 22](flake-module.nix)
- Documentation on `dockerTools.buildImage` you can find here: https://nix.dev/tutorials/nixos/building-and-running-docker-images.html
## Docker build with UI changes
If changes to the UI have been made, and you want them to propagate to the docker container edit the file: [../ui/nix/ui-assets.nix](../ui/nix/ui-assets.nix).
This is where a release version of the frontend is downloaded and integrated into the cli and the docker build. To do this first execute
```bash
nix build .#ui --out-link ui-release
```
Make a tarball out of it called `ui-assets.tar.gz`
```bash
tar -czvf ui-assets.tar.gz ui-release/lib/node_modules/clan-ui/out/
```
Upload ui-assets.tar.gz to gitlab. To get the `GITLAB_TOKEN` go to [repo access tokens](https://git.tu-berlin.de/internet-of-services-lab/service-aware-network-front-end/-/settings/access_tokens) and generate one. Then execute
```bash
export GITLAB_TOKEN="<your-access-token>"
```
```bash
curl --header "PRIVATE-TOKEN: $GITLAB_TOKEN" \
--upload-file ./ui-assets.tar.gz \
"https://git.tu-berlin.de/api/v4/projects/internet-of-services-lab%2Fservice-aware-network-front-end/packages/generic/ui-assets/1.0.0/ui-assets.tar.gz"
```
You can find your uploaded package at the [package registry](https://git.tu-berlin.de/internet-of-services-lab/service-aware-network-front-end/-/packages)
And export the download url into a variable:
```
export url="https://git.tu-berlin.de/api/v4/projects/internet-of-services-lab%2Fservice-aware-network-front-end/packages/generic/ui-assets/1.0.0/ui-assets.tar.gz"
```
Now execute the command:
```bash
cat > "../ui/nix/ui-assets.nix" <<EOF
{ fetchzip }:
fetchzip {
url = "$url";
sha256 = "$(nix-prefetch-url --unpack $url)";
}
EOF
```
And now build the docker image:
```bash
nix build .#clan-docker
```
# Uploading a Docker Image
Login to the tu docker image server
@@ -76,6 +133,70 @@ For the tests we automatically generate a python client for the API endpoints. T
This will replace the folder
`tests/openapi_client`.
# Adding dependencies
**Dependency Management**: We use the [Nix package manager](https://nixos.org/) to manage dependencies and ensure reproducibility, making your development process more robust.
To add dependencies edit the file [default.nix](default.nix)
To search for a python dependency named "request" execute:
```bash
nix search nixpkgs#pythonPackages request
```
Add the depdendency at the top of the file
```nix
{
, mydep # <--- Add here
, websockets
, broadcaster
, aenum
, dateutil
, urllib3
}:
let
[...]
```
Add them into this array if they are a python dependency
```nix
dependencies = [
argcomplete
fastapi
uvicorn
sqlalchemy
websockets
broadcaster
mydep # <--- Add here
];
```
To search for a binary dependency named "firefox" execute:
```bash
nix search nixpkgs firefox
```
Runtime dependency add them into this array:
```nix
runtimeDependencies = [
bash
nix
fakeroot
zbar
git
mypy
];
```
# Development environment
The development environment created by `nix develop` or automatically by `direnv` is located at [shell.nix](shell.nix). The `shellHook` variable execute bash code.
# API Documentation
Api documentation can be found in the folder `pkgs/clan-cli/tests/openapi_client/docs/`

View File

@@ -1,5 +1,4 @@
{ age
, lib
{ lib
, argcomplete
, fastapi
, uvicorn
@@ -15,23 +14,17 @@
, python3
, runCommand
, setuptools
, sops
, stdenv
, wheel
, fakeroot
, rsync
, ui-assets
, bash
, sshpass
, zbar
, tor
, git
, nixpkgs
, makeDesktopItem
, copyDesktopItems
, qemu
, gnupg
, e2fsprogs
, mypy
, sqlalchemy
, websockets
@@ -73,17 +66,9 @@ let
bash
nix
fakeroot
openssh
sshpass
zbar
tor
age
rsync
sops
git
mypy
qemu
e2fsprogs
];
runtimeDependenciesAsSet = builtins.listToAttrs (builtins.map (p: lib.nameValuePair (lib.getName p.name) p) runtimeDependencies);

View File

@@ -1,4 +1,6 @@
# cLan - awesome UI
# Web UI
**Dependency Management**: We use the [Nix package manager](https://nixos.org/) to manage dependencies and ensure reproducibility, making your development process more robust.
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.
@@ -16,10 +18,24 @@ npm run dev
To build the release version execute
```bash
nix build .#ui
```
you can find the output in your current working directory at a symlink called `result`
The actual web files served by the web server are located in
`result/lib/node_modules/clan-ui/out`
You can also build it directly in you dev environment. Notice however that this will clutter your directory. The out directory is directly in you working dir.
```bash
npm run build
```
## Development environment
The development environment created by `nix develop` or automatically by `direnv` is located at [shell.nix](shell.nix). The `shellHook` variable executes bash code.
## Updating dependencies
After changing dependencies with
@@ -35,7 +51,3 @@ The prettier tailwind class sorting is not yet working properly with our devShel
To sort classnames manually:
`cd /clan-core/pkgs/ui/`
## Troubleshooting
Sometimes new endpoints don't appear in `src/api`. Delete the `ui/openapi.json` file and execute `direnv reload`