- download node
- download npm
- navigate to the cnaas-front folder
- run
npm ito install all the dependencies - run:
npm startto bundle the js files - navigate to
http://localhost:1234in browser
This guide will show you how to set up cnaas-nms on your local machine for development. The components will run in Docker containers.
The cnaas-nms frontend will also run inside a Docker container and update interactively with every code change.
Clone the source code for frontend and API. Both should be in the same parent directory.
git clone https://github.com/SUNET/cnaas-front.git cnaas-front
git clone https://github.com/SUNET/cnaas-nms.git cnaas-nmsNavigate to cnaas-front/docker/.
cd cnaas-front/dockerBuild and run with
docker compose --env-file <your .env file> up -dA script will set up the auth container for you. This script will create a certificate to verify JWTokens issued by the auth server. It will also create a user named "cnaas" with password "cnaascnaascnaas".
docker cp docker/front-dev/setup_auth.sh cnaas-front_auth_1:/opt/auth-server-poc/
docker exec -t cnaas-front_auth_1 /bin/chmod u+x /opt/auth-server-poc/setup_auth.sh
docker exec -t cnaas-front_auth_1 /opt/auth-server-poc/setup_auth.shThe public key file is used to verify JWTokens between the auth server and the API.
public.pem has to be copied from the auth container to the API container:
docker cp cnaas-front_auth_1:/opt/auth-server-poc/cert/public.pem .
docker cp public.pem cnaas-front_api_1:/opt/cnaas/jwtcert/public.pem
rm public.pem
docker exec -u root -t cnaas-front_api_1 /bin/chown root:www-data /opt/cnaas/jwtcert/public.pemThen, restart the API application.
docker exec -t cnaas-front_api_1 /usr/bin/killall uwsgiAlternatively, you can restart the whole API container.
docker compose restart apidocker exec -i cnaas-front_postgres_1 /usr/bin/psql -U cnaas cnaas < docker/front-dev/cnaas.pgdumpSome errors and warnings will appear. You can ignore those.
On the host system (that's your computer), you can now run the following commands to ensure that everything is working: auth, API and frontend.
curl -ks https://localhost:2443/api/v1.0/auth -X POST -u cnaas -pThis should return an access token if you enter the password correctly. It should look something like this:
{"access_token": "exceedingly.ridiculouslyrandomlylookinglongstring"}
This token can be used to authenticate with the cnaas-nms REST API, instead of username/password.
Next, create a .env file and fill in the token (whatever was returned as the
exceedingly.ridiculouslyrandomlylookinglongstring without the JSON wrapper) as JWT_AUTH_TOKEN.
echo 'JWT_AUTH_TOKEN="exceedingly.ridiculouslyrandomlylookinglongstring"' > .envNext, load the token into the JWT_AUTH_TOKEN environment variable with source and define an
alias command that allows you to authenticate with the cnaas-nms REST API using this token.
(The alias is defined for the current shell session only. You can add the alias line to your
.bashrc to make it permanent.)
source .env
alias curlJ='curl -k -s -H "Authorization: Bearer $JWT_AUTH_TOKEN" -H "Content-Type: application/json"'
curlJ https://localhost/api/v1.0/devices | jqThis should return a list of two test devices.
Point your browser to http://127.0.0.1:8083.
You should be able to log into the frontend with the user credentials mentioned
earlier and click through the tabs.
Be at root of the repo
docker build -f docker/front/Dockerfile -t cnaas-front .Check docker/compose.yaml
- CNAAS_API_URL
- SETTINGS_WEB_URL
- TEMPLATES_WEB_URL
- ARISTA_DETECT_ARCH
- CNAAS_FIRMWARE_REPO_METADATA_URL
- CNAAS_FIRMWARE_REPO_URL
- CNAAS_FIRMWARE_URL
- CNAAS_FRONT_URL
- GRAPHITE_URL
- GNMI_PROXY_URL
- MONITORING_WEB_URL
- NETBOX_API_TOKEN
- NETBOX_API_URL
- NETBOX_TENANT_ID
- OIDC_ENABLED When OIDC_ENABLED is true CNAAS_AUTH_URL also needs to be set.
docker run -p 4443:4443 --name cnaas-front --env-file .env-docker --rm -it cnaas-frontThis project uses ESLint (v9+ flat config) and Prettier. Prettier handles formatting rules, while ESLint handles code quality rules.
The ESLint configuration is in eslint.config.mjs and includes:
- @eslint/js for core recommended rules.
- eslint-plugin-react and eslint-plugin-react-hooks for React-specific rules.
- eslint-plugin-import for import/export linting.
- eslint-plugin-jsx-a11y for accessibility rules.
- eslint-plugin-prettier integrates Prettier as an ESLint rule, and must be the last config to properly override previous rules.
To lint the project:
npm run lintTo auto-fix lint and formatting issues:
npm run lint:fixTo format a single file with Prettier:
npx prettier <file name> --write