mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-22 10:31:35 +00:00
Update https-unikernel example to latest API
Also, stop static linking for now, as it generates a lot of warnings with glibc. Signed-off-by: Thomas Leonard <thomas.leonard@docker.com>
This commit is contained in:
parent
76509e34a2
commit
815f5599fc
@ -1,8 +1,8 @@
|
|||||||
FROM ocaml/opam@sha256:a469435632d0cacbceab799d7e48201b727d025fa1805cbbe210d94233b251ad
|
FROM ocaml/opam@sha256:523988cb7ac4c51e1c6e2f00658686c320330000859f49e1ec8fe3d6df046a26
|
||||||
#FROM ocaml/opam:debian-9_ocaml-4.04.0
|
#FROM ocaml/opam:debian-9_ocaml-4.04.0
|
||||||
RUN opam pin add -yn capnp 'https://github.com/talex5/capnp-ocaml.git#demo1'
|
RUN opam pin add -yn capnp 'https://github.com/talex5/capnp-ocaml.git#demo2'
|
||||||
RUN opam pin add -yn capnp-rpc 'https://github.com/talex5/capnp-rpc.git#demo1'
|
RUN opam pin add -yn capnp-rpc 'https://github.com/talex5/capnp-rpc.git#demo2'
|
||||||
RUN opam pin add -yn capnp-rpc-lwt 'https://github.com/talex5/capnp-rpc.git#demo1'
|
RUN opam pin add -yn capnp-rpc-lwt 'https://github.com/talex5/capnp-rpc.git#demo2'
|
||||||
RUN opam depext -i -y jbuilder lwt cohttp astring tls capnp camlzip alcotest cohttp
|
RUN opam depext -i -y jbuilder lwt cohttp astring tls capnp camlzip alcotest cohttp
|
||||||
RUN sudo apt-get install -y screen python-pip python-setuptools python-dev --no-install-recommends
|
RUN sudo apt-get install -y screen python-pip python-setuptools python-dev --no-install-recommends
|
||||||
RUN pip install cython pycapnp
|
RUN pip install cython pycapnp
|
||||||
|
@ -23,13 +23,12 @@ The easiest way to build and run is using Docker:
|
|||||||
|
|
||||||
Once inside the container, you can run all the services in a single process like this:
|
Once inside the container, you can run all the services in a single process like this:
|
||||||
|
|
||||||
reset
|
|
||||||
https-unikernel-single
|
https-unikernel-single
|
||||||
|
|
||||||
You should be able to try out the service by opening <https://localhost:8443> in a browser.
|
You should be able to try out the service by opening <https://localhost:8443> in a browser.
|
||||||
|
|
||||||
You can also run the service as three separate processes.
|
You can also run the service as three separate processes.
|
||||||
The easiest way to do this is by running `screen`.
|
The easiest way to do this is by creating multiple windows in `screen` (which is running by default in the Docker image).
|
||||||
|
|
||||||
First, start the store:
|
First, start the store:
|
||||||
|
|
||||||
@ -64,7 +63,7 @@ $ python
|
|||||||
( ok = "<p>It works!</p><p>Powered by Irmin.</p>\n" )
|
( ok = "<p>It works!</p><p>Powered by Irmin.</p>\n" )
|
||||||
```
|
```
|
||||||
|
|
||||||
(or just do `python test_store.py`)
|
(or just do `python src/test_store.py`)
|
||||||
|
|
||||||
|
|
||||||
[Cap'n Proto RPC]: https://capnproto.org/rpc.html
|
[Cap'n Proto RPC]: https://capnproto.org/rpc.html
|
||||||
|
@ -8,7 +8,7 @@ build: [
|
|||||||
]
|
]
|
||||||
depends: [
|
depends: [
|
||||||
"lwt"
|
"lwt"
|
||||||
"cohttp"
|
"cohttp" {>="0.21.0" & <"0.99"}
|
||||||
"astring"
|
"astring"
|
||||||
"tls"
|
"tls"
|
||||||
"irmin-unix"
|
"irmin-unix"
|
||||||
|
@ -11,7 +11,7 @@ let connect ~switch path =
|
|||||||
exit 1
|
exit 1
|
||||||
end;
|
end;
|
||||||
let endpoint = Endpoint.of_socket ~switch socket in
|
let endpoint = Endpoint.of_socket ~switch socket in
|
||||||
let conn = CapTP.of_endpoint ~switch endpoint in
|
let conn = CapTP.connect ~switch endpoint in
|
||||||
CapTP.bootstrap conn
|
CapTP.bootstrap conn
|
||||||
|
|
||||||
let rm_socket path =
|
let rm_socket path =
|
||||||
@ -33,7 +33,7 @@ let listen ~switch ~offer path =
|
|||||||
Logs.info (fun f -> f "Got connection on %S" path);
|
Logs.info (fun f -> f "Got connection on %S" path);
|
||||||
Lwt_switch.with_switch @@ fun switch -> (* todo: with_child_switch *)
|
Lwt_switch.with_switch @@ fun switch -> (* todo: with_child_switch *)
|
||||||
let endpoint = Endpoint.of_socket ~switch (Lwt_unix.unix_file_descr c) in
|
let endpoint = Endpoint.of_socket ~switch (Lwt_unix.unix_file_descr c) in
|
||||||
ignore (CapTP.of_endpoint ~switch ~offer endpoint);
|
ignore (CapTP.connect ~switch ~offer endpoint);
|
||||||
loop () in
|
loop () in
|
||||||
loop ()
|
loop ()
|
||||||
|
|
||||||
|
@ -17,8 +17,7 @@ module Remote_flow = struct
|
|||||||
let read t =
|
let read t =
|
||||||
let module R = Api.Reader.Flow.Read_results in
|
let module R = Api.Reader.Flow.Read_results in
|
||||||
let req = Capability.Request.create_no_args () in
|
let req = Capability.Request.create_no_args () in
|
||||||
let proxy = new Api.Reader.Flow.client t in
|
Capability.call_for_value_exn t Api.Reader.Flow.read_method req >>= fun resp ->
|
||||||
Capability.call_for_value_exn proxy#read req >>= fun resp ->
|
|
||||||
let p = R.of_payload resp in
|
let p = R.of_payload resp in
|
||||||
let data = R.data_get p in
|
let data = R.data_get p in
|
||||||
Lwt.return (Ok (`Data (Cstruct.of_string data)))
|
Lwt.return (Ok (`Data (Cstruct.of_string data)))
|
||||||
@ -26,9 +25,8 @@ module Remote_flow = struct
|
|||||||
let write t data =
|
let write t data =
|
||||||
let module P = Api.Builder.Flow.Write_params in
|
let module P = Api.Builder.Flow.Write_params in
|
||||||
let req, p = Capability.Request.create P.init_pointer in
|
let req, p = Capability.Request.create P.init_pointer in
|
||||||
let proxy = new Api.Reader.Flow.client t in
|
|
||||||
P.data_set p (Cstruct.to_string data);
|
P.data_set p (Cstruct.to_string data);
|
||||||
Capability.call_for_value_exn proxy#write req >>= fun _ ->
|
Capability.call_for_value_exn t Api.Reader.Flow.write_method req >>= fun _ ->
|
||||||
Lwt.return (Ok ())
|
Lwt.return (Ok ())
|
||||||
|
|
||||||
let writev t data =
|
let writev t data =
|
||||||
@ -77,8 +75,7 @@ let get t path =
|
|||||||
let module P = Api.Builder.Store.Get_params in
|
let module P = Api.Builder.Store.Get_params in
|
||||||
let req, p = Capability.Request.create P.init_pointer in
|
let req, p = Capability.Request.create P.init_pointer in
|
||||||
ignore (P.path_set_list p path);
|
ignore (P.path_set_list p path);
|
||||||
let proxy = new Api.Reader.Store.client t in
|
Capability.call_for_value_exn t Api.Reader.Store.get_method req >>= fun resp ->
|
||||||
Capability.call_for_value_exn proxy#get req >>= fun resp ->
|
|
||||||
let open Api.Reader.Store in
|
let open Api.Reader.Store in
|
||||||
match GetResults.get (GetResults.of_payload resp) with
|
match GetResults.get (GetResults.of_payload resp) with
|
||||||
| GetResults.NotFound -> Lwt.return None
|
| GetResults.NotFound -> Lwt.return None
|
||||||
@ -119,8 +116,10 @@ let handle_connection store c =
|
|||||||
|
|
||||||
let service store =
|
let service store =
|
||||||
Api.Builder.HttpServer.local @@
|
Api.Builder.HttpServer.local @@
|
||||||
object (_ : Api.Builder.HttpServer.service)
|
object
|
||||||
method accept req =
|
inherit Api.Builder.HttpServer.service
|
||||||
|
|
||||||
|
method accept_impl req =
|
||||||
Log.info (fun f -> f "Handing new connection");
|
Log.info (fun f -> f "Handing new connection");
|
||||||
let module P = Api.Reader.HttpServer.Accept_params in
|
let module P = Api.Reader.HttpServer.Accept_params in
|
||||||
let p = P.of_payload req in
|
let p = P.of_payload req in
|
||||||
|
@ -1,25 +1,11 @@
|
|||||||
(* -*- tuareg -*- *)
|
(jbuild_version 1)
|
||||||
open Jbuild_plugin.V1
|
|
||||||
|
|
||||||
let extra_flags =
|
(executables (
|
||||||
match Sys.getenv "JBUILD_STATIC" with
|
(names (main store_main http_main tls_main))
|
||||||
| "true" -> "-cclib -static"
|
(libraries (capnp-rpc-lwt cohttp.lwt irmin-unix cmdliner fmt.tty))
|
||||||
| x -> failwith (Printf.sprintf "JBUILD_STATIC: unknown value %S" x)
|
(flags (:standard -w -53-55))
|
||||||
| exception Not_found -> ""
|
))
|
||||||
|
(rule
|
||||||
let sexp = Printf.sprintf {|
|
((targets (proto.ml proto.mli))
|
||||||
(jbuild_version 1)
|
(deps (proto.capnp))
|
||||||
|
(action (run capnpc -o ocaml ${<}))))
|
||||||
(executables (
|
|
||||||
(names (main store_main http_main tls_main))
|
|
||||||
(libraries (capnp-rpc-lwt cohttp.lwt irmin-unix cmdliner fmt.tty))
|
|
||||||
(flags (:standard -w -53-55 %s))
|
|
||||||
))
|
|
||||||
(rule
|
|
||||||
((targets (proto.ml proto.mli))
|
|
||||||
(deps (proto.capnp))
|
|
||||||
(action (run capnpc -o ocaml ${<}))))
|
|
||||||
|} extra_flags
|
|
||||||
|
|
||||||
let () =
|
|
||||||
send sexp
|
|
||||||
|
@ -21,15 +21,15 @@ let () =
|
|||||||
begin
|
begin
|
||||||
Store.service () >>= fun service ->
|
Store.service () >>= fun service ->
|
||||||
let tags = Logs.Tag.add Common.Actor.tag (`Green, "Store ") Logs.Tag.empty in
|
let tags = Logs.Tag.add Common.Actor.tag (`Green, "Store ") Logs.Tag.empty in
|
||||||
let _ : CapTP.t = CapTP.of_endpoint ~offer:service ~tags ~switch store_to_http in
|
let _ : CapTP.t = CapTP.connect ~offer:service ~tags ~switch store_to_http in
|
||||||
Lwt.return ()
|
Lwt.return ()
|
||||||
end
|
end
|
||||||
>>= fun () ->
|
>>= fun () ->
|
||||||
begin
|
begin
|
||||||
let tags = Logs.Tag.add Common.Actor.tag (`Red, "HTTP ") Logs.Tag.empty in
|
let tags = Logs.Tag.add Common.Actor.tag (`Red, "HTTP ") Logs.Tag.empty in
|
||||||
let store = CapTP.bootstrap (CapTP.of_endpoint ~tags ~switch http_to_store) in
|
let store = CapTP.bootstrap (CapTP.connect ~tags ~switch http_to_store) in
|
||||||
let service = Http_server.service store in
|
let service = Http_server.service store in
|
||||||
let _ : CapTP.t = CapTP.of_endpoint ~offer:service ~tags ~switch http_to_tls in
|
let _ : CapTP.t = CapTP.connect ~offer:service ~tags ~switch http_to_tls in
|
||||||
Lwt.return ()
|
Lwt.return ()
|
||||||
end
|
end
|
||||||
>>= fun () ->
|
>>= fun () ->
|
||||||
|
@ -13,8 +13,10 @@ let service () =
|
|||||||
Irmin_store.Repo.v config >>= fun repo ->
|
Irmin_store.Repo.v config >>= fun repo ->
|
||||||
Irmin_store.of_branch repo Irmin_store.Branch.master >|= fun db ->
|
Irmin_store.of_branch repo Irmin_store.Branch.master >|= fun db ->
|
||||||
Api.Builder.Store.local @@
|
Api.Builder.Store.local @@
|
||||||
object (_ : Api.Builder.Store.service)
|
object
|
||||||
method get req =
|
inherit Api.Builder.Store.service
|
||||||
|
|
||||||
|
method get_impl req =
|
||||||
let module P = Api.Reader.Store.Get_params in
|
let module P = Api.Reader.Store.Get_params in
|
||||||
let module R = Api.Builder.Store.GetResults in
|
let module R = Api.Builder.Store.GetResults in
|
||||||
let params = P.of_payload req in
|
let params = P.of_payload req in
|
||||||
|
@ -3,8 +3,10 @@ open Capnp_rpc_lwt
|
|||||||
|
|
||||||
let make_flow _flow ic oc =
|
let make_flow _flow ic oc =
|
||||||
Api.Builder.Flow.local @@
|
Api.Builder.Flow.local @@
|
||||||
object (_ : Api.Builder.Flow.service)
|
object
|
||||||
method read _ =
|
inherit Api.Builder.Flow.service
|
||||||
|
|
||||||
|
method read_impl _ =
|
||||||
Service.return_lwt (fun () ->
|
Service.return_lwt (fun () ->
|
||||||
Lwt_io.read ~count:4096 ic >|= fun data ->
|
Lwt_io.read ~count:4096 ic >|= fun data ->
|
||||||
let module R = Api.Builder.Flow.Read_results in
|
let module R = Api.Builder.Flow.Read_results in
|
||||||
@ -13,7 +15,7 @@ let make_flow _flow ic oc =
|
|||||||
Ok resp
|
Ok resp
|
||||||
)
|
)
|
||||||
|
|
||||||
method write req =
|
method write_impl req =
|
||||||
let module R = Api.Reader.Flow.Write_params in
|
let module R = Api.Reader.Flow.Write_params in
|
||||||
let p = R.of_payload req in
|
let p = R.of_payload req in
|
||||||
let data = R.data_get p in
|
let data = R.data_get p in
|
||||||
@ -24,11 +26,11 @@ let make_flow _flow ic oc =
|
|||||||
end
|
end
|
||||||
|
|
||||||
let handle ~http_service flow =
|
let handle ~http_service flow =
|
||||||
let proxy = new Api.Reader.HttpServer.client http_service in
|
|
||||||
let module P = Api.Builder.HttpServer.Accept_params in
|
let module P = Api.Builder.HttpServer.Accept_params in
|
||||||
let req, p = Capability.Request.create P.init_pointer in
|
let req, p = Capability.Request.create P.init_pointer in
|
||||||
P.connection_set p (Some (Capability.Request.export req flow));
|
P.connection_set p (Some (Capability.Request.export req flow));
|
||||||
Capability.call_for_value proxy#accept req >|= function
|
Capability.dec_ref flow;
|
||||||
|
Capability.call_for_value http_service Api.Reader.HttpServer.accept_method req >|= function
|
||||||
| Ok _ -> ()
|
| Ok _ -> ()
|
||||||
| Error e -> Logs.warn (fun f -> f "Error from HTTP server: %a" Capnp_rpc.Error.pp e)
|
| Error e -> Logs.warn (fun f -> f "Error from HTTP server: %a" Capnp_rpc.Error.pp e)
|
||||||
|
|
||||||
@ -49,5 +51,5 @@ let run ~port ~http_service =
|
|||||||
|
|
||||||
let init ~switch ~to_http =
|
let init ~switch ~to_http =
|
||||||
let tags = Logs.Tag.add Common.Actor.tag (`Blue, "TLS ") Logs.Tag.empty in
|
let tags = Logs.Tag.add Common.Actor.tag (`Blue, "TLS ") Logs.Tag.empty in
|
||||||
let http_service = CapTP.bootstrap (CapTP.of_endpoint ~tags ~switch to_http) in
|
let http_service = CapTP.bootstrap (CapTP.connect ~tags ~switch to_http) in
|
||||||
run ~http_service ~port:8443
|
run ~http_service ~port:8443
|
||||||
|
Loading…
Reference in New Issue
Block a user