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 d978817
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 31 deletions.
50 changes: 27 additions & 23 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,11 +70,14 @@ firefox http://localhost:8080
#### Start the Monocle crawler process

```ShellSession
nix develop --command monocle-repl
λ> import Macroscope.Worker
λ> import Macroscope.Main
λ> import Monocle.Client (withClient)
λ> withClient "http://localhost:8080" Nothing $ \client -> runMacroscope 19001 "etc/config.yaml" client
just repl
λ> Monocle.Client.withClient "http://localhost:8080" Nothing $ \client -> Macroscope.Main.runMacroscope 19001 "etc/config.yaml" client
```

… or by running the executable:

```ShellSession
just crawler
```

### Start the CLI
Expand Down Expand Up @@ -113,17 +119,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,33 +141,33 @@ 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:
Run a single test (on failure, tasty provides a pattern to re-run a single test):

```ShellSession
cabal test --test-options='-p "Change stream"'
just test "PATTERN"
```

## Start the web development server

Start the web dev server (hot-reload):

```ShellSession
nix develop --command monocle-web-start
just web
firefox http://localhost:13000
```

Expand All @@ -188,7 +193,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 +203,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 +218,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
54 changes: 54 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,65 @@
#
# 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

test pattern:
nix develop --command cabal -O0 test --test-options='-p "{{pattern}}"'

# 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 d978817

Please sign in to comment.