Skip to content

Commit

Permalink
Merge pull request #2031 from zshipko/irmin-server-no-http
Browse files Browse the repository at this point in the history
  • Loading branch information
metanivek authored Aug 9, 2023
2 parents 020b52e + bd71dae commit 8f6f56f
Show file tree
Hide file tree
Showing 63 changed files with 5,720 additions and 3 deletions.
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 <contact@tarides.com>
*
* 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
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 <contact@tarides.com>
*
* 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 <contact@tarides.com>
*
* 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 <zachshipko@gmail.com>"
authors: "Zach Shipko <zachshipko@gmail.com>"
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 <zachshipko@gmail.com>"
authors: "Zach Shipko <zachshipko@gmail.com>"
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 <contact@tarides.com>
*
* 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

0 comments on commit 8f6f56f

Please sign in to comment.