From 95281748b6ae2e41f22078f862f49a14e2fdf04b Mon Sep 17 00:00:00 2001 From: Tristan Cacqueray Date: Sat, 6 Jan 2024 11:39:14 -0500 Subject: [PATCH] doc: move common commands to the just file --- CONTRIBUTING.md | 41 ++++++++++++++---------- Justfile | 51 ++++++++++++++++++++++++++++++ nix/default.nix | 7 ---- src/Monocle/Backend/Provisioner.hs | 2 +- 4 files changed, 76 insertions(+), 25 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c11f79cb2..6c38c2fbb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -33,7 +33,7 @@ This section describes how to start the Monocle services directly on your host. #### Start ElasticSearch ```ShellSession -nix develop --command elasticsearch-start +just elastic ``` #### Start the Monocle API @@ -41,13 +41,13 @@ nix develop --command elasticsearch-start The API serves the web UI and the Monocle API. The web App must be built first by running: ```ShellSession -cd web && npm install && npm run build && cd - +just build-web ``` Then, ensure you have set the Monocle config file `config.yaml` (see [README.md](README.md#configuration)) and run: ```ShellSession -nix develop --command monocle-repl +just repl λ> import Monocle.Main λ> run $ defaultApiConfig 8080 "http://localhost:19200" "etc/config.yaml" ``` @@ -55,9 +55,12 @@ nix develop --command monocle-repl … or by running the executable: ```ShellSession -CRAWLERS_API_KEY=secret MONOCLE_CONFIG=./etc/config.yaml nix develop --command cabal run -O0 monocle -- api +just api ``` +> Make sure to setup your .env file, e.g. with: +> (echo CRAWLERS_API_KEY=secret; echo MONOCLE_CONFIG=./etc/config.yaml) > .env + The Monocle UI should be accessible: ```ShellSession @@ -67,13 +70,19 @@ firefox http://localhost:8080 #### Start the Monocle crawler process ```ShellSession -nix develop --command monocle-repl +just repl λ> import Macroscope.Worker λ> import Macroscope.Main λ> import Monocle.Client (withClient) λ> withClient "http://localhost:8080" Nothing $ \client -> runMacroscope 19001 "etc/config.yaml" client ``` +… or by running the executable: + +```ShellSession +just crawler +``` + ### Start the CLI Display the CLI help: @@ -113,9 +122,8 @@ You might need to install the right Haskell plugin for your editor. ghcid automatically re-compiles the code when a haskell file change and display compilation errors and warnings. - ```ShellSession -nix develop --command monocle-ghcid +just ghcid ``` ### Run hoogle @@ -123,7 +131,7 @@ nix develop --command monocle-ghcid Hoogle generates the documentation from the Monocle source code. ```ShellSession -nix develop --command hoogle server -p 8081 --local --haskell +just hoogle ``` You can access the generated documentation on port 8081. @@ -136,19 +144,19 @@ Ensure the service is started by running: `nix develop --command elasticsearch-s Run linters (fourmolu and hlint) with: ```ShellSession -nix develop --command monocle-fast-ci-run +just ci-fast ``` When the linters fail, you can fix the issue automatically with: ```ShellSession -nix develop --command monocle-reformat-run +just fmt ``` Run the full test suite with: ```ShellSession -nix develop --command monocle-ci-run +just ci ``` Run a single test: @@ -162,7 +170,7 @@ cabal test --test-options='-p "Change stream"' Start the web dev server (hot-reload): ```ShellSession -nix develop --command monocle-web-start +just web firefox http://localhost:13000 ``` @@ -188,7 +196,7 @@ ghcid --set ":set args api" --test 'CLI.main' Start Kibana with: ```ShellSession -nix develop --command kibana-start +just kibana ``` Then access http://localhost:5601 @@ -198,9 +206,8 @@ Then access http://localhost:5601 Provisonning fake data (only fake changes are supported) can be done using the repl: ``` -nix develop --command monocle-repl -λ> import Monocle.Backend.Provisioner -λ> runProvisioner "etc/config.yaml" "http://localhost:19200" "demo-fake-data" 300 +just repl +λ> Monocle.Backend.Provisioner.runProvisioner "etc/config.yaml" "http://localhost:19200" "demo-fake-data" 300 ``` Prior to run the provisonner, add the *demo-fake-data* workspace in the config file with an @@ -214,7 +221,7 @@ protobuf definitions present in the [./schemas/monocle folder](./schemas/monocle the api and web client by running the protoc command using the Makefile: ```ShellSession -$ just codegen +just codegen ``` ## Create a monocle build diff --git a/Justfile b/Justfile index 44a1ac5b9..7ff0769df 100644 --- a/Justfile +++ b/Justfile @@ -3,11 +3,62 @@ # # doc: https://just.systems/man/en/chapter_1.html +# Load .env file +set dotenv-load + PINCLUDE := "-I /usr/include ${PROTOC_FLAGS} -I ./schemas/" # just doesn't support array so we create a space separated string for bash # see: https://github.com/casey/just/issues/1570 PBS := `ls schemas/monocle/protob/*.proto | grep -v http.proto | sed 's/schemas.//' | tr '\n' ' '` +# Start elasticsearch +elastic: + nix develop --command elasticsearch-start + +# Start kibana +kibana: + nix develop --command kibana-start + +# Start web devel server +web: + nix develop --command monocle-web-start + +# Build the web interface +build-web: + cd web && npm install && npm run build + +# Reformat and apply hlint hints +fmt: + nix develop --command monocle-reformat-run + +# Run the full ci test suite +ci: + nix develop --command monocle-ci-run + +# Run unit tests +ci-fast: + nix develop --command monocle-fast-ci-run + +# Start ghcid +ghcid: + nix develop --command ghcid + +# Start hoogle to search documentation +hoogle: + nix develop --command hoogle server -p 8081 --local --haskell + +# Start a ghci repl +repl: + nix develop --command monocle-repl + +# Run the API +api: + nix develop --command cabal run -O0 monocle -- api + +# Run the CRAWLER +crawler: + nix develop --command cabal run -O0 monocle -- crawler + # Update code after changing protobuf schema (./schemas/monocle/protob), ci.dhall or architecture.plantuml codegen: codegen-ci codegen-doc codegen-stubs codegen-javascript codegen-openapi codegen-haskell diff --git a/nix/default.nix b/nix/default.nix index 04cd048ca..85d4ec99a 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -336,12 +336,6 @@ in rec { cabal repl --build-depends pretty-simple monocle ''; - monocleGhcid = pkgs.writeScriptBin "monocle-ghcid" '' - #!/bin/sh - set -x - ${hspkgs.ghcid}/bin/ghcid -c "cabal repl monocle" $* - ''; - monocleWebStart = pkgs.writeScriptBin "monocle-web-start" '' #!/bin/sh set -ex @@ -366,7 +360,6 @@ in rec { elasticsearchStart monocleReplStart monocleWebStart - monocleGhcid ]; # define the base requirements diff --git a/src/Monocle/Backend/Provisioner.hs b/src/Monocle/Backend/Provisioner.hs index c985d39db..96ceaecc9 100644 --- a/src/Monocle/Backend/Provisioner.hs +++ b/src/Monocle/Backend/Provisioner.hs @@ -57,7 +57,7 @@ runProvisioner configPath elasticUrl tenantName docCount = do case r of Left err -> logInfo "Unable to perform the provisionning" ["error" .= err] Right _ -> pure () - Nothing -> pure () + Nothing -> logWarn "Could not find tenant" [] -- | Ensure changes have a unique ID setChangeID :: [EChange] -> IO [EChange]