Skip to content

Commit

Permalink
Merge #116: Switch everything over to Cabal
Browse files Browse the repository at this point in the history
Approved-by: robbert-vdh
Auto-deploy: false
  • Loading branch information
OpsBotPrime committed Jun 19, 2023
2 parents 5848b8a + c5f098d commit 2109f59
Show file tree
Hide file tree
Showing 34 changed files with 577 additions and 563 deletions.
23 changes: 23 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

# Add possibility to run a custom envrc that completely overrides the behavior of this envrc.
CUSTOM_ENVRC=.customenvrc
if [ -f "$CUSTOM_ENVRC" ]; then
echo "Using .customenvrc file"
source_env $CUSTOM_ENVRC
else
# Decrease logging output
# shellcheck disable=SC2034 # unused variable is still read by direnv.
DIRENV_LOG_FORMAT=
# Install nix-direnv, which has an improved implementation of `use nix` that
# caches the Nix environment. Note that this URL is cached locally, so it
# doesn't fetch the script every time.
if ! has nix_direnv_version || ! nix_direnv_version 2.2.1; then
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.2.1/direnvrc" "sha256-zelF0vLbEl5uaqrfIzbgNzJWGmLzCmYAkInj/LNxvKs="
fi

nix_direnv_watch_file nix/sources.json nix/haskell-dependencies.nix
dotenv

use nix default.nix --argstr environment shell
fi
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
dist-newstyle/
cabal.project.local
*.prof
*.eventlog

# Icepeak data
icepeak.db
icepeak.json
icepeak.json.journal
icepeak.json.new

# IntelliJ IDEA project files
*.idea
*.iml

# Nix result symlinks
result*

# Direnv
.direnv/
1 change: 0 additions & 1 deletion .semaphore/install-stack.2.7.3.sha256

This file was deleted.

46 changes: 3 additions & 43 deletions .semaphore/semaphore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,7 @@ agent:
os_image: "ubuntu2004"

blocks:
- name: "Run checks"
dependencies: []

task:
prologue:
commands:
- "checkout"

# Haskell requires libgmp for big integers.
- "sudo apt install libgmp-dev"

# Install Stack from source
- "mkdir -p ~/.local/bin"
- "export PATH=$HOME/.local/bin:$PATH"
- "wget https://github.com/commercialhaskell/stack/releases/download/v2.7.3/stack-2.7.3-linux-x86_64.tar.gz"
- "sha256sum --check .semaphore/install-stack.2.7.3.sha256"
- "cat stack-2.7.3-linux-x86_64.tar.gz | tar xz --wildcards --strip-components=1 -C ~/.local/bin '*/stack'"

# restore stack cache
- "cache restore stack-"

jobs:
- name: "Run tests for client"
commands:
- "(cd client-haskell && stack setup -j2 --no-terminal)"
- "(cd client-haskell && stack build -j2 --no-terminal)"
- "(cd client-haskell && stack test -j2 --no-terminal)"

- name: "Run tests for server"
commands:
- "(cd server && stack setup -j2 --no-terminal)"
- "(cd server && stack build -j2 --no-terminal)"
- "(cd server && stack test -j2 --no-terminal)"

epilogue:
always:
commands:
# Store a copy of the stack installation folder
- "cache store stack-$(date -u -Idate) ~/.stack"

- name: "Build"
- name: "Build and test"
dependencies: []

task:
Expand Down Expand Up @@ -85,11 +45,11 @@ blocks:
jobs:
- name: "Build client"
commands:
- "nix-build --no-out-link -E '(import ./nix/nixpkgs.nix {}).haskellPackages.callPackage ./client-haskell/client.nix {}'"
- "nix-build --no-out-link ./release.nix --attr icepeak-client"

- name: "Build server"
commands:
- "nix-build --no-out-link ./server/default.nix"
- "nix-build --no-out-link ./release.nix --attr icepeak"

epilogue:
always:
Expand Down
41 changes: 20 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Clients can subscribe to specific paths in the JSON document like e.g. `/users/1
via the websocket-based API and they will get a push update whenever any of the
JSON data below this path changes.

If a client subscribes to the document root `/` they will receive *all* updates.
If a client subscribes to the document root `/` they will receive _all_ updates.

Icepeak supports JWT-based authorization. JWT claims can be used
to restrict the prefixes in the JSON document that a client can read or write.
Expand Down Expand Up @@ -49,11 +49,12 @@ a Haskell client library.

## Building and running Icepeak

Cd into `/server`.
Build with `stack build`.
Run the tests with `stack test`.
And run `icepeak` itself with `stack exec icepeak`.
Install with `stack install`.
Icepeak can be built using [Cabal](https://cabal.readthedocs.io/en/stable/),
which can be installed through [ghcup](https://www.haskell.org/ghcup/). You can
also use the [Nix](https://nixos.org/) shell provided by this repo.

- Run the tests with `cabal test -j icepeak`.
- And run `icepeak` itself with `cabal run -j icepeak`.

Integration tests are in `/server/integration-tests`.
They are stand-alone scripts that can be executed directly, e.g. `./read_after_write_test.py`.
Expand All @@ -67,11 +68,10 @@ garbage collector by passing the following runtime flags to icepeak:

## Building the Haskell client library

Cd into `/client-haskell`.
Build with `stack build`.
Run the tests with `stack test`.
Build with `cabal build -j icepeak-client`.
Run the tests with `cabal test -j icepeak-client`.

Run `stack haddock --no-haddock-deps` to generate the Haskell API documentation.
Run `cabal haddock` to generate the Haskell API documentation.

## Usage:

Expand Down Expand Up @@ -119,15 +119,15 @@ The `icepeak` claim has the following JSON schema:
"type": "object",
"required": ["version"],
"properties": {
"version": {"enum": [1]},
"version": { "enum": [1] },
"whitelist": {
"type": "array",
"items": {
"type": "object",
"required": ["prefix", "modes"],
"properties": {
"prefix": {"type": "array", "items": {"type": "string"}},
"modes": {"type": "array", "items": {"enum": ["read", "write"]}}
"prefix": { "type": "array", "items": { "type": "string" } },
"modes": { "type": "array", "items": { "enum": ["read", "write"] } }
}
}
}
Expand All @@ -142,17 +142,18 @@ Example JWT token claim set:
"icepeak": {
"version": 1,
"whitelist": [
{"prefix": ["foo"], "modes": ["read"]},
{"prefix": ["bar", "1"], "modes": ["read", "write"]}
{ "prefix": ["foo"], "modes": ["read"] },
{ "prefix": ["bar", "1"], "modes": ["read", "write"] }
]
}
}
```

A request with this claim set may only:
- Read paths that have `/foo` as a prefix.
- Update paths that have `/bar/1` as a prefix.
Any other request will result in a *401 Unauthorized* response.

- Read paths that have `/foo` as a prefix.
- Update paths that have `/bar/1` as a prefix.
Any other request will result in a _401 Unauthorized_ response.

Generally, a claim contains a list of permissions which apply to the listed path
itself and all sub-paths. A request is considered valid if there is at least one
Expand Down Expand Up @@ -220,7 +221,6 @@ Icepeak can provide usage metrics to Prometheus with the `--metrics HOST:PORT` c

- `PORT` denotes the port number the metrics endpoint is listening on.


## Tests

There are both unit and integration tests.
Expand All @@ -229,8 +229,7 @@ The unit tests for the server can be found in `server/tests`.
They can be run with:

```
cd server
stack test
cabal test -j all
```

The integration tests can be found in `server/integration-tests`.
Expand Down
6 changes: 6 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
packages:
server/icepeak.cabal
client-haskell/icepeak-client.cabal

package icepeak
optimization: 2
3 changes: 0 additions & 3 deletions client-haskell/.gitignore

This file was deleted.

44 changes: 0 additions & 44 deletions client-haskell/client.nix

This file was deleted.

15 changes: 0 additions & 15 deletions client-haskell/default.nix

This file was deleted.

29 changes: 29 additions & 0 deletions client-haskell/icepeak-client.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
cabal-version: 1.12
name: icepeak-client
version: 0.1.1
synopsis:
Client library for Icepeak, a fast JSON document store with push notification support

homepage: https://github.com/channable/icepeak
license: BSD3
build-type: Simple

library
exposed-modules: Icepeak.Client
other-modules: Paths_icepeak_client
hs-source-dirs: src
ghc-options:
-Wall -Wincomplete-uni-patterns -Wincomplete-record-updates

build-depends:
aeson
, base
, binary
, bytestring
, exceptions
, http-client
, http-types
, retry
, text

default-language: Haskell2010
50 changes: 50 additions & 0 deletions client-haskell/icepeak-client.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{ lib, mkDerivation

# Core packages
, nix-gitignore

# Haskell packages
, aeson, base, binary, bytestring, http-client, http-types, text, retry
, exceptions }:
mkDerivation {
pname = "icepeak-client";
version = "0.1.1";

src = let
# We do not want to include all files, because that leads to a lot of things
# that nix has to copy to the temporary build directory that we don't want
# to have in there (e.g. the `.dist-newstyle` directory, the `.git`
# directory, etc.)
prefixWhitelist =
builtins.map builtins.toString [ ./icepeak-client.cabal ./src ];
# Compute source based on whitelist
whitelistFilter = path: _type:
lib.any (prefix: lib.hasPrefix prefix path) prefixWhitelist;
gitignore = builtins.readFile ../.gitignore;
gitignoreFilter =
nix-gitignore.gitignoreFilterPure whitelistFilter gitignore ./.;
whitelistedSrc = lib.cleanSourceWith {
src = lib.cleanSource ./.;
filter = gitignoreFilter;
};
in whitelistedSrc;

isLibrary = true;
isExecutable = false;

libraryHaskellDepends = [
aeson
base
binary
bytestring
http-client
http-types
text
retry
exceptions
];

homepage = "https://github.com/channable/icepeak";

license = lib.licenses.bsd3;
}
26 changes: 0 additions & 26 deletions client-haskell/package.yaml

This file was deleted.

Loading

0 comments on commit 2109f59

Please sign in to comment.