Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate irmin-server #2031

Merged
merged 26 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
9a1244a
Add irmin-server and irmin-client
zshipko Jul 20, 2022
a22a140
Add executables and test
zshipko Jul 21, 2022
62e42d4
Add examples for client/server
samoht Feb 16, 2023
fe03261
irmin-server example: expose the dashboard on port 1234
samoht Feb 20, 2023
48cb953
Add server command to irmin cli
samoht Feb 16, 2023
77a060c
Fix irmin-client.opam
zshipko Aug 1, 2022
8c5a0c1
Add irmin-server/irmin-client to changelog
samoht Feb 16, 2023
001d081
Make unix/jsoo packages optional
zshipko Aug 1, 2022
3bcea9d
Add more dependencies
zshipko Aug 1, 2022
7770c37
Formatting
zshipko Aug 1, 2022
7e18c09
Add depopts
zshipko Aug 1, 2022
c73a44f
Add copyright header
zshipko Aug 5, 2022
1ca919a
Add basic web dashboard
zshipko Aug 9, 2022
ff36968
Improvements to dashboard
zshipko Aug 16, 2022
6b20442
Fix irmin-cli tests
zshipko Sep 7, 2022
51f1af7
formatting
zshipko Sep 7, 2022
494d85c
Remove high-level get function to fix atomic tests
zshipko Sep 14, 2022
c0f3c8b
fix loading contents on dashboard
zshipko Nov 21, 2022
cb78799
Remove optional dependencies
samoht Feb 16, 2023
aa11dd8
Use latest Brr
samoht Feb 16, 2023
eb45063
Minor changes to the dashboard
samoht Feb 20, 2023
aec5e8f
irmin-client: add minimal documentation for the Batch module
samoht Feb 20, 2023
4a34601
start documenting S.Batch
zshipko Mar 3, 2023
d593ff2
Update irmin-server/client to use `clear` arg
metanivek Aug 2, 2023
866bdff
irmin-server: do not flush request header write
metanivek Aug 8, 2023
bd71dae
irmin-server: remove un-needed clients hash table
metanivek Aug 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
## Unreleased

### Added

- **irmin-server**
- Added `irmin-server` package (#2031, @zshipko)
- **irmin-client**
- Added `irmin-client` package to connect to `irmin-server` instances (#2031,
@zshipko)

### Fixed

- **irmin-pack**
Expand Down
47 changes: 47 additions & 0 deletions examples/client_batch.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
(*
* Copyright (c) 2018-2022 Tarides <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)

open Lwt.Syntax
open Lwt.Infix
module Store = Irmin_mem.KV.Make (Irmin.Contents.String)
module Client = Irmin_client_unix.Make (Store)
module Error = Irmin_client.Error

let main =
let info () = Client.Info.empty in
let uri = Uri.of_string Sys.argv.(1) in
let* client = Client.connect uri in

let* main = Client.main client in
let* () = Client.set_exn ~info main [ "testing" ] "testing" in
let* head = Client.Branch.get client Client.Branch.main in
let* tree =
Client.Batch.Tree.of_commit client (Client.Commit.hash head) >|= Option.get
in
let* tree = Client.Batch.Tree.add client tree [ "b"; "c" ] "123" in
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zshipko could you describe the rational of Batch here? Does it mean that Client.Tree always connect to the server while Client.Batch.Tree is maintaining a local tree?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right, the Batch API allows you to manipulate a local tree and send it all at once since the Irmin Store API doesn't give much control over when data will be transferred over the network.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind adding a bit of documentation about this somewhere? Maybe in the corresponding mli?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am in the process of adding some more comments, I will push something up this week

let* tree = Client.Batch.Tree.add_tree client tree [ "a" ] tree in
let* tree = Client.Batch.Tree.remove client tree [ "testing" ] in
let* commit = Client.Batch.commit ~parents:[ head ] ~info client tree in
let* () = Client.Branch.set client Client.Branch.main commit in
let* foo = Client.get main [ "foo" ] in
let* abc = Client.get main [ "a"; "b"; "c" ] in
let* testing = Client.find main [ "testing" ] in
assert (foo = "bar");
assert (abc = "123");
assert (Option.is_none testing);
Lwt_io.printlf "foo => %s\na/b/c => %s" foo abc

let () = Lwt_main.run main
12 changes: 10 additions & 2 deletions examples/dune
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
push
custom_graphql
custom_storage
fold)
fold
client_batch
server)
(libraries
astring
cohttp
Expand All @@ -20,6 +22,10 @@
irmin-graphql.unix
irmin-pack.unix
irmin-watcher
irmin-server.unix
irmin-client.unix
websocket-lwt-unix
conduit-lwt-unix
lwt
lwt.unix)
(preprocess
Expand All @@ -39,7 +45,9 @@
custom_graphql.exe
fold.exe
gc.exe
custom_storage.exe))
custom_storage.exe
client_batch.exe
server.exe))

(alias
(name runtest)
Expand Down
16 changes: 16 additions & 0 deletions examples/plugin/plugin.ml
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
(*
* Copyright (c) 2018-2022 Tarides <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)

open Irmin_cli

(* Adding a new content type *)
Expand Down
40 changes: 40 additions & 0 deletions examples/server.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
(*
* Copyright (c) 2018-2022 Tarides <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)

open Lwt.Syntax
module Store = Irmin_mem.KV.Make (Irmin.Contents.String)
module Server = Irmin_server_unix.Make (Store)

let info () = Irmin.Info.Default.empty

let init () =
let* repo = Store.Repo.v (Irmin_mem.config ()) in
let* main = Store.main repo in
let+ () = Store.set_exn ~info main [ "foo" ] "bar" in
()

let main () =
let uri = Uri.of_string Sys.argv.(1) in
let config = Irmin_mem.config () in
let dashboard = `TCP (`Port 1234) in
let* server = Server.v ~uri ~dashboard config in
let () = Format.printf "Listening on %a@." Uri.pp uri in
Server.serve server

let () =
Lwt_main.run
@@ let* () = init () in
main ()
3 changes: 3 additions & 0 deletions irmin-cli.opam
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ depends: [
"irmin-pack" {= version}
"irmin-graphql" {= version}
"irmin-tezos" {= version}
"irmin-server" {= version}
"git-unix" {>= "3.7.0"}
"digestif" {>= "0.9.0"}
"irmin-watcher" {>= "0.2.0"}
Expand All @@ -36,6 +37,8 @@ depends: [
"conduit"
"conduit-lwt"
"conduit-lwt-unix"
"websocket-lwt-unix"
"ppx_blob"
"logs"
"uri"
"cmdliner"
Expand Down
25 changes: 25 additions & 0 deletions irmin-client.opam
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
opam-version: "2.0"
synopsis: "A client for irmin-server"
maintainer: "Zach Shipko <[email protected]>"
authors: "Zach Shipko <[email protected]>"
license: "ISC"
homepage: "https://github.com/mirage/irmin"
doc: "https://irmin.org"
bug-reports: "https://github.com/mirage/irmin/issues"
depends: [
"ocaml" {>= "4.08.0"}
"dune" {>= "2.0.0"}
"irmin-server" {= version}
"ipaddr"
"websocket-lwt-unix"
"conduit-lwt-unix"
"lwt-dllist"
"js_of_ocaml-lwt"
"brr" {>= "0.0.4"}
]
build: [
["dune" "subst"] {pinned}
["dune" "build" "-p" name "-j" jobs]
["dune" "runtest" "-p" name] {with-test}
]
dev-repo: "git+ssh://github.com/mirage/irmin"
30 changes: 30 additions & 0 deletions irmin-server.opam
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
opam-version: "2.0"
synopsis: "A high-performance server for Irmin"
maintainer: "Zach Shipko <[email protected]>"
authors: "Zach Shipko <[email protected]>"
license: "ISC"
homepage: "https://github.com/mirage/irmin"
doc: "https://irmin.org"
bug-reports: "https://github.com/mirage/irmin/issues"
depends: [
"ocaml" {>= "4.08.0"}
"dune" {>= "2.0.0"}
"optint" {>= "0.1.0"}
"irmin" {= version}
"ppx_irmin" {= version}
"uri"
"fmt"
"cmdliner" {>= "1.0.4"}
"logs" {>= "0.7.0"}
"lwt" {>= "5.4.0"}
"conduit-lwt-unix"
"websocket-lwt-unix"
"cohttp-lwt-unix"
"ppx_blob"
]

build: [
["dune" "subst"] {pinned}
["dune" "build" "-p" name "-j" jobs]
["dune" "runtest" "-p" name] {with-test}
]
13 changes: 12 additions & 1 deletion src/irmin-cli/cli.ml
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,15 @@ let graphql =
Term.(mk graphql $ store () $ port $ addr));
}

(* SERVER *)
let server =
{
name = "server";
doc = "Run irmin-server.";
man = [];
term = Server.main_term;
}

let options =
{
name = "options";
Expand Down Expand Up @@ -953,14 +962,15 @@ let default =
\ watch %s\n\
\ dot %s\n\
\ graphql %s\n\
\ server %s\n\
\ options %s\n\
\ branches %s\n\
\ log %s\n\n\
See `irmin help <command>` for more information on a specific command.\n\
%!"
init.doc get.doc set.doc remove.doc list.doc tree.doc clone.doc fetch.doc
merge.doc pull.doc push.doc snapshot.doc revert.doc watch.doc dot.doc
graphql.doc options.doc branches.doc log.doc
graphql.doc server.doc options.doc branches.doc log.doc
in
( Term.(mk usage $ const ()),
deprecated_info "irmin" ~version:Irmin.version ~sdocs:global_option_section
Expand All @@ -986,6 +996,7 @@ let commands =
watch;
dot;
graphql;
server;
options;
branches;
log;
Expand Down
3 changes: 3 additions & 0 deletions src/irmin-cli/dune
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
irmin-git.unix
irmin-fs.unix
irmin-graphql.unix
irmin-server.unix
websocket-lwt-unix
conduit-lwt-unix
irmin-watcher
cmdliner
git-unix
Expand Down
16 changes: 16 additions & 0 deletions src/irmin-cli/irmin_cli.mli
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
(*
* Copyright (c) 2018-2022 Tarides <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)

include module type of Cli
(** @inline *)

Expand Down
Loading
Loading