mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-21 10:09:07 +00:00
Merge pull request #1408 from samoht/reorg
mirageSDK: re-organise the file hierarchy
This commit is contained in:
commit
46cda7dc72
27
projects/miragesdk/dhcp-client/.gitignore
vendored
27
projects/miragesdk/dhcp-client/.gitignore
vendored
@ -1,27 +0,0 @@
|
|||||||
.build
|
|
||||||
.pkg
|
|
||||||
.dev
|
|
||||||
obj/
|
|
||||||
|
|
||||||
hash
|
|
||||||
|
|
||||||
# Generated by `make dev`
|
|
||||||
_build/
|
|
||||||
main.native
|
|
||||||
calf/dhcp_client
|
|
||||||
src/bpf/.merlin
|
|
||||||
|
|
||||||
# Generated by the mirage tool
|
|
||||||
calf/_build
|
|
||||||
calf/Makefile
|
|
||||||
calf/myocamlbuild.ml
|
|
||||||
calf/*.opam
|
|
||||||
calf/key_gen.ml
|
|
||||||
calf/main.ml
|
|
||||||
calf/.mirage.config
|
|
||||||
|
|
||||||
# Trash files
|
|
||||||
\#*
|
|
||||||
.#*
|
|
||||||
*~
|
|
||||||
.*~
|
|
@ -1,74 +0,0 @@
|
|||||||
B ../_build/default/src
|
|
||||||
B ../_build/default/src/bpf
|
|
||||||
FLG -cclib -static
|
|
||||||
PKG astring
|
|
||||||
PKG base64
|
|
||||||
PKG bigarray
|
|
||||||
PKG bytes
|
|
||||||
PKG calendar
|
|
||||||
PKG cmdliner
|
|
||||||
PKG cohttp
|
|
||||||
PKG cohttp.lwt
|
|
||||||
PKG cohttp.lwt-core
|
|
||||||
PKG conduit
|
|
||||||
PKG conduit.lwt
|
|
||||||
PKG conduit.lwt-unix
|
|
||||||
PKG cstruct
|
|
||||||
PKG cstruct.lwt
|
|
||||||
PKG cstruct.ppx
|
|
||||||
PKG decompress
|
|
||||||
PKG dispatch
|
|
||||||
PKG fieldslib
|
|
||||||
PKG fmt
|
|
||||||
PKG fmt.cli
|
|
||||||
PKG fmt.tty
|
|
||||||
PKG git
|
|
||||||
PKG hex
|
|
||||||
PKG inotify
|
|
||||||
PKG inotify.lwt
|
|
||||||
PKG ipaddr
|
|
||||||
PKG ipaddr.unix
|
|
||||||
PKG irmin
|
|
||||||
PKG irmin-git
|
|
||||||
PKG irmin-http
|
|
||||||
PKG irmin-watcher
|
|
||||||
PKG irmin-watcher.core
|
|
||||||
PKG irmin-watcher.inotify
|
|
||||||
PKG irmin-watcher.polling
|
|
||||||
PKG jsonm
|
|
||||||
PKG logs
|
|
||||||
PKG logs-syslog
|
|
||||||
PKG logs-syslog.lwt
|
|
||||||
PKG logs.cli
|
|
||||||
PKG logs.fmt
|
|
||||||
PKG logs.lwt
|
|
||||||
PKG lwt
|
|
||||||
PKG lwt.log
|
|
||||||
PKG lwt.unix
|
|
||||||
PKG magic-mime
|
|
||||||
PKG mstruct
|
|
||||||
PKG ocamlgraph
|
|
||||||
PKG ocplib-endian
|
|
||||||
PKG ocplib-endian.bigstring
|
|
||||||
PKG ptime
|
|
||||||
PKG ptime.clock.os
|
|
||||||
PKG rawlink
|
|
||||||
PKG re
|
|
||||||
PKG re.emacs
|
|
||||||
PKG re.posix
|
|
||||||
PKG re.str
|
|
||||||
PKG result
|
|
||||||
PKG sexplib
|
|
||||||
PKG str
|
|
||||||
PKG stringext
|
|
||||||
PKG syslog-message
|
|
||||||
PKG threads
|
|
||||||
PKG threads.posix
|
|
||||||
PKG tuntap
|
|
||||||
PKG uchar
|
|
||||||
PKG unix
|
|
||||||
PKG uri
|
|
||||||
PKG uri.services
|
|
||||||
PKG uutf
|
|
||||||
PKG webmachine
|
|
||||||
S .
|
|
31
projects/miragesdk/src/.gitignore
vendored
Normal file
31
projects/miragesdk/src/.gitignore
vendored
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
.build
|
||||||
|
.pkg
|
||||||
|
.dev
|
||||||
|
obj/
|
||||||
|
hash
|
||||||
|
|
||||||
|
# Generated by jbuilder
|
||||||
|
dhcp-client/bpf/.merlin
|
||||||
|
dhcp-client/.merlin
|
||||||
|
sdk/.merlin
|
||||||
|
|
||||||
|
# Generated by `make dev`
|
||||||
|
_build/
|
||||||
|
main.native
|
||||||
|
calf/dhcp_client
|
||||||
|
src/bpf/.merlin
|
||||||
|
|
||||||
|
# Generated by the mirage tool
|
||||||
|
dhcp-client/calf/_build
|
||||||
|
dhcp-client/calf/Makefile
|
||||||
|
dhcp-client/calf/myocamlbuild.ml
|
||||||
|
dhcp-client/calf/*.opam
|
||||||
|
dhcp-client/calf/key_gen.ml
|
||||||
|
dhcp-client/calf/main.ml
|
||||||
|
dhcp-client/calf/.mirage.config
|
||||||
|
|
||||||
|
# Trash files
|
||||||
|
\#*
|
||||||
|
.#*
|
||||||
|
*~
|
||||||
|
.*~
|
@ -7,14 +7,13 @@ RUN opam pin -n add mirage-net-unix https://github.com/samoht/mirage-net-unix.gi
|
|||||||
RUN opam depext -iy mirage-net-unix logs-syslog irmin-unix cohttp decompress
|
RUN opam depext -iy mirage-net-unix logs-syslog irmin-unix cohttp decompress
|
||||||
RUN opam depext -iy rawlink tuntap.1.0.0 jbuilder irmin-watcher inotify
|
RUN opam depext -iy rawlink tuntap.1.0.0 jbuilder irmin-watcher inotify
|
||||||
|
|
||||||
RUN sudo mkdir -p /src /bin
|
RUN sudo mkdir -p /src
|
||||||
COPY ./src /src
|
COPY ./sdk /src/sdk
|
||||||
|
COPY ./dhcp-client /src/dhcp-client
|
||||||
RUN sudo chown opam -R /src
|
RUN sudo chown opam -R /src
|
||||||
|
|
||||||
USER opam
|
USER opam
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
|
|
||||||
RUN opam pin add tuntap 1.0.0
|
RUN opam config exec -- jbuilder build dhcp-client/main.exe
|
||||||
|
RUN sudo cp /src/_build/default/dhcp-client/main.exe /dhcp-client
|
||||||
RUN opam config exec -- jbuilder build main.exe
|
|
||||||
RUN sudo cp /src/_build/default/main.exe /dhcp-client
|
|
@ -1,12 +1,13 @@
|
|||||||
BASE=ocaml/opam:alpine-3.5_ocaml-4.04.0
|
BASE=ocaml/opam:alpine-3.5_ocaml-4.04.0
|
||||||
FILES=$(shell find src/ -regex '.*\.mli?') src/bpf/dhcp.c \
|
FILES=$(shell find . -name jbuild) \
|
||||||
src/jbuild src/bpf/jbuild
|
$(shell find sdk/ -regex '.*\.mli?') \
|
||||||
|
dhcp-client/bpf/dhcp.c dhcp-client/main.ml
|
||||||
IMAGE=dhcp-client
|
IMAGE=dhcp-client
|
||||||
OBJS=obj/dhcp-client
|
OBJS=obj/dhcp-client
|
||||||
|
|
||||||
MIRAGE_COMPILE=mobylinux/mirage-compile:f903b0e1b4328271364cc63f123ac49d56739cef@sha256:a54d9ca84d3f5998dba92ce83d60d49289cee8908a8b0f6ec280d30ab8edf46c
|
MIRAGE_COMPILE=mobylinux/mirage-compile:f903b0e1b4328271364cc63f123ac49d56739cef@sha256:a54d9ca84d3f5998dba92ce83d60d49289cee8908a8b0f6ec280d30ab8edf46c
|
||||||
CALF_OBJS=obj/dhcp-client-calf
|
CALF_OBJS=obj/dhcp-client-calf
|
||||||
CALF_FILES=calf/config.ml calf/unikernel.ml
|
CALF_FILES=dhcp-client/calf/config.ml dhcp-client/calf/unikernel.ml
|
||||||
|
|
||||||
default: push
|
default: push
|
||||||
@
|
@
|
7
projects/miragesdk/src/dhcp-client/jbuild
Normal file
7
projects/miragesdk/src/dhcp-client/jbuild
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
(jbuild_version 1)
|
||||||
|
|
||||||
|
(executables
|
||||||
|
((names (main))
|
||||||
|
(libraries (sdk bpf_dhcp))
|
||||||
|
(flags (-cclib -static))
|
||||||
|
))
|
@ -1,4 +1,5 @@
|
|||||||
open Lwt.Infix
|
open Lwt.Infix
|
||||||
|
open Sdk
|
||||||
|
|
||||||
let src = Logs.Src.create "dhcp-client" ~doc:"DHCP client"
|
let src = Logs.Src.create "dhcp-client" ~doc:"DHCP client"
|
||||||
module Log = (val Logs.src_log src : Logs.LOG)
|
module Log = (val Logs.src_log src : Logs.LOG)
|
||||||
@ -97,10 +98,17 @@ let ethif =
|
|||||||
in
|
in
|
||||||
Arg.(value & opt string "eth0" & doc)
|
Arg.(value & opt string "eth0" & doc)
|
||||||
|
|
||||||
|
let path =
|
||||||
|
let doc =
|
||||||
|
Arg.info ~docv:"DIR"
|
||||||
|
~doc:"The directory where control state will be stored." ["path"]
|
||||||
|
in
|
||||||
|
Arg.(value & opt string "/data" & doc)
|
||||||
|
|
||||||
let run =
|
let run =
|
||||||
Term.(const run $ setup_log $ cmd $ ethif),
|
Term.(const run $ setup_log $ cmd $ ethif $ path),
|
||||||
Term.info "dhcp-client" ~version:"0.0"
|
Term.info "dhcp-client" ~version:"0.0"
|
||||||
|
|
||||||
let () = match Term.eval run with
|
let () = match Term.eval run with
|
||||||
| `Error _ -> exit 1
|
| `Error _ -> exit 1
|
||||||
| _ -> exit 0
|
| `Ok () |`Help |`Version -> exit 0
|
@ -25,10 +25,10 @@ let v path =
|
|||||||
KV.Repo.v config >>= fun repo ->
|
KV.Repo.v config >>= fun repo ->
|
||||||
KV.of_branch repo "calf"
|
KV.of_branch repo "calf"
|
||||||
|
|
||||||
let set_listen_dir_hook () =
|
let () =
|
||||||
Irmin.Private.Watch.set_listen_dir_hook Irmin_watcher.hook
|
Irmin.Private.Watch.set_listen_dir_hook Irmin_watcher.hook
|
||||||
|
|
||||||
module HTTP = struct
|
module Dispatch = struct
|
||||||
|
|
||||||
module Wm = struct
|
module Wm = struct
|
||||||
module Rd = Webmachine.Rd
|
module Rd = Webmachine.Rd
|
||||||
@ -112,7 +112,7 @@ module HTTP = struct
|
|||||||
(Uri.path (Request.uri request)));
|
(Uri.path (Request.uri request)));
|
||||||
Log.debug (fun l -> l "path=%a" Fmt.(Dump.list string) path);
|
Log.debug (fun l -> l "path=%a" Fmt.(Dump.list string) path);
|
||||||
(* Finally, send the response to the client *)
|
(* Finally, send the response to the client *)
|
||||||
Cohttp_lwt_unix.Server.respond ~flush:true ~headers ~body ~status ()
|
Cohttp_lwt_unix.Server.respond ~headers ~body ~status ()
|
||||||
in
|
in
|
||||||
(* create the server and handle requests with the function defined above *)
|
(* create the server and handle requests with the function defined above *)
|
||||||
let conn_closed (_, conn) =
|
let conn_closed (_, conn) =
|
||||||
@ -122,7 +122,15 @@ module HTTP = struct
|
|||||||
Cohttp_lwt_unix.Server.make ~callback ~conn_closed ()
|
Cohttp_lwt_unix.Server.make ~callback ~conn_closed ()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
let int_of_fd (t:Lwt_unix.file_descr) =
|
||||||
|
(Obj.magic (Lwt_unix.unix_file_descr t): int)
|
||||||
|
|
||||||
let serve ~routes db fd =
|
let serve ~routes db fd =
|
||||||
let http = HTTP.v db routes in
|
let http = Dispatch.v db routes in
|
||||||
let on_exn e = Log.err (fun l -> l "ERROR: %a" Fmt.exn e) in
|
let on_exn e = Log.err (fun l -> l "ERROR: %a" Fmt.exn e) in
|
||||||
|
Lwt_unix.blocking fd >>= fun blocking ->
|
||||||
|
Log.debug (fun l ->
|
||||||
|
l "Serving the control state over fd:%d (blocking=%b)"
|
||||||
|
(int_of_fd fd) blocking
|
||||||
|
);
|
||||||
Cohttp_lwt_unix.Server.create ~on_exn ~mode:(`Fd fd) http
|
Cohttp_lwt_unix.Server.create ~on_exn ~mode:(`Fd fd) http
|
@ -126,8 +126,8 @@ module Pipe = struct
|
|||||||
{ Fd.name = name; fd = priv }, { Fd.name = name ^ "-calf"; fd = calf }
|
{ Fd.name = name; fd = priv }, { Fd.name = name ^ "-calf"; fd = calf }
|
||||||
|
|
||||||
(* logs pipe *)
|
(* logs pipe *)
|
||||||
let stdout = pipe "logs-out"
|
let stdout = pipe "stdout"
|
||||||
let stderr = pipe "logs-err"
|
let stderr = pipe "stderr"
|
||||||
|
|
||||||
(* store pipe *)
|
(* store pipe *)
|
||||||
let ctl = socketpair "ctl"
|
let ctl = socketpair "ctl"
|
||||||
@ -182,8 +182,9 @@ let check_exit_status cmd status =
|
|||||||
|
|
||||||
let exec_priv ~pid ~cmd ~net ~ctl ~handlers =
|
let exec_priv ~pid ~cmd ~net ~ctl ~handlers =
|
||||||
|
|
||||||
(* close child fds *)
|
|
||||||
Fd.(redirect_to_dev_null stdin) >>= fun () ->
|
Fd.(redirect_to_dev_null stdin) >>= fun () ->
|
||||||
|
|
||||||
|
(* close child fds *)
|
||||||
Fd.close Pipe.(calf stdout) >>= fun () ->
|
Fd.close Pipe.(calf stdout) >>= fun () ->
|
||||||
Fd.close Pipe.(calf stderr) >>= fun () ->
|
Fd.close Pipe.(calf stderr) >>= fun () ->
|
||||||
Fd.close Pipe.(calf net) >>= fun () ->
|
Fd.close Pipe.(calf net) >>= fun () ->
|
||||||
@ -206,7 +207,7 @@ let exec_priv ~pid ~cmd ~net ~ctl ~handlers =
|
|||||||
Fd.forward ~src:Pipe.(priv stderr) ~dst:Fd.stderr;
|
Fd.forward ~src:Pipe.(priv stderr) ~dst:Fd.stderr;
|
||||||
(* TODO: Init.Fd.forward ~src:Init.Pipe.(priv metrics) ~dst:Init.Fd.metric; *)
|
(* TODO: Init.Fd.forward ~src:Init.Pipe.(priv metrics) ~dst:Init.Fd.metric; *)
|
||||||
ctl ();
|
ctl ();
|
||||||
handlers ();
|
(* handlers (); *)
|
||||||
])
|
])
|
||||||
|
|
||||||
let run ~net ~ctl ~handlers cmd =
|
let run ~net ~ctl ~handlers cmd =
|
@ -1,10 +1,9 @@
|
|||||||
(jbuild_version 1)
|
(jbuild_version 1)
|
||||||
|
|
||||||
(executables
|
(library
|
||||||
((names (main))
|
((name sdk)
|
||||||
(libraries (logs-syslog.lwt threads cohttp.lwt cstruct.lwt
|
(libraries (logs-syslog.lwt threads cohttp.lwt cstruct.lwt
|
||||||
cmdliner fmt.cli logs.fmt logs.cli fmt.tty decompress
|
cmdliner fmt.cli logs.fmt logs.cli fmt.tty decompress
|
||||||
irmin irmin-git irmin-http lwt.unix rawlink tuntap bpf_dhcp
|
irmin irmin-git irmin-http lwt.unix rawlink tuntap
|
||||||
irmin-watcher inotify))
|
irmin-watcher inotify))
|
||||||
(flags (-cclib -static))
|
|
||||||
))
|
))
|
Loading…
Reference in New Issue
Block a user