Skip to content

Commit

Permalink
doc: move common commands to the just file
Browse files Browse the repository at this point in the history
  • Loading branch information
TristanCacqueray committed Jan 6, 2024
1 parent 8fbd45c commit 9528174
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 25 deletions.
41 changes: 24 additions & 17 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,34 @@ 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

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"
```

… 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
Expand All @@ -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:
Expand Down Expand Up @@ -113,17 +122,16 @@ 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

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.
Expand All @@ -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:
Expand All @@ -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
```

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
51 changes: 51 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 0 additions & 7 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -366,7 +360,6 @@ in rec {
elasticsearchStart
monocleReplStart
monocleWebStart
monocleGhcid
];

# define the base requirements
Expand Down
2 changes: 1 addition & 1 deletion src/Monocle/Backend/Provisioner.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 9528174

Please sign in to comment.