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

Shell config #26

Merged
merged 6 commits into from
Apr 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 0 additions & 3 deletions .bowerrc

This file was deleted.

12 changes: 6 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
FROM ocaml/dev:release-debian-9_ocaml-4.02.3
FROM ocaml/dev:release-ubuntu-14.04_ocaml-4.02.3
MAINTAINER canopy
ENV OPAMYES 1
RUN sudo apt-get update
RUN opam pin add dolog https://github.com/UnixJunkie/dolog.git\#no_unix
RUN opam pin add bin_prot https://github.com/hannesm/bin_prot.git\#113.33.00+xen
RUN cd /home/opam/opam-repository; git pull && opam update
RUN opam upgrade
RUN opam update
RUN opam install ptime
RUN opam pin add syndic https://github.com/Cumulus/Syndic.git\#ptime
COPY . /src
RUN sudo chown -R opam:opam /src
WORKDIR /src
RUN mkdir disk
RUN opam config exec -- mirage configure --xen
RUN opam config exec -- make
RUN opam config exec -- mirage configure --unix
RUN opam config exec -- make
Binary file added assets/assets_generated.tar.gz
Binary file not shown.
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions assets/js/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var $;
$ = require('jquery')
global.jQuery = require("jquery")
_ = require('bootstrap')
var hljs = require('highlight.js')
hljs.initHighlightingOnLoad();
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ article {

footer {
margin-top: 20px;
}

pre {
padding: 0px;
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 0 additions & 14 deletions bower.json

This file was deleted.

2 changes: 0 additions & 2 deletions canopy_config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ type t = {
index_page : string;
port : int;
push_hook_path: string;
mathjax: bool;
tls_port : int option;
}

Expand All @@ -14,6 +13,5 @@ let config () = {
blog_name = Key_gen.name ();
port = Key_gen.port ();
push_hook_path = Key_gen.push_hook ();
mathjax = Key_gen.mathjax ();
tls_port = Key_gen.tls_port ();
}
2 changes: 1 addition & 1 deletion canopy_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module Main (C: CONSOLE) (S: STACKV4) (RES: Resolver_lwt.S) (CON: Conduit_mirag
X509.certificate kv `Default >|= fun cert ->
Tls.Config.server ~certificates:(`Single cert) ()

let start console stack resolver conduit disk _clock keys _ =
let start console stack resolver conduit disk _clock keys _ _ =
let module Context =
( struct
let v _ = Lwt.return_some (resolver, conduit)
Expand Down
68 changes: 32 additions & 36 deletions canopy_templates.ml
Original file line number Diff line number Diff line change
Expand Up @@ -36,49 +36,45 @@ let links keys =
li [ a ~a:[a_href ("/" ^ link)] [span [pcdata link]]] in
List.map format_link paths

let script_mathjax =
[script ~a:[a_src "https://travis-ci.org/Engil/Canopy"] (pcdata "")]

let main ~config ~content ~title ~keys =
let links = links keys in
let mathjax = if config.mathjax then script_mathjax else [] in
let page =
html
(head
(Html5.M.title (pcdata title))
([
meta ~a:[a_charset "UTF-8"] ();
link ~rel:[`Stylesheet] ~href:"/static/bower/bootstrap/dist/css/bootstrap.min.css" ();
link ~rel:[`Stylesheet] ~href:"/static/css/style.css" ();
script ~a:[a_src "/static/bower/jquery/dist/jquery.min.js"] (pcdata "");
script ~a:[a_src "/static/bower/bootstrap/dist/js/bootstrap.min.js"] (pcdata "");
link ~rel:[`Alternate] ~href:"/atom" ~a:[a_title title; a_mime_type "application/atom+xml"] ();
] ++ mathjax)
(Html5.M.title (pcdata title))
([
meta ~a:[a_charset "UTF-8"] ();
link ~rel:[`Stylesheet] ~href:"/static/css/bootstrap.min.css" ();
link ~rel:[`Stylesheet] ~href:"/static/css/style.css" ();
link ~rel:[`Stylesheet] ~href:"/static/css/highlight.css" ();
script ~a:[a_src "/static/js/canopy.js"] (pcdata "");
link ~rel:[`Alternate] ~href:"/atom" ~a:[a_title title; a_mime_type "application/atom+xml"] ();
])
)
(body
[
nav ~a:[a_class ["navbar navbar-default navbar-fixed-top"]] [
div ~a:[a_class ["container"]] [
div ~a:[a_class ["navbar-header"]] [
button ~a:[a_class ["navbar-toggle collapsed"];
a_user_data "toggle" "collapse";
a_user_data "target" ".navbar-collapse"
] [
span ~a:[a_class ["icon-bar"]][];
span ~a:[a_class ["icon-bar"]][];
span ~a:[a_class ["icon-bar"]][]
];
a ~a:[a_class ["navbar-brand"]; a_href ("/" ^ config.index_page)][pcdata config.blog_name]
];
div ~a:[a_class ["collapse navbar-collapse collapse"]] [
ul ~a:[a_class ["nav navbar-nav navbar-right"]] links
]
]
];
main [
div ~a:[a_class ["flex-container"]] content
]
]
[
nav ~a:[a_class ["navbar navbar-default navbar-fixed-top"]] [
div ~a:[a_class ["container"]] [
div ~a:[a_class ["navbar-header"]] [
button ~a:[a_class ["navbar-toggle collapsed"];
a_user_data "toggle" "collapse";
a_user_data "target" ".navbar-collapse"
] [
span ~a:[a_class ["icon-bar"]][];
span ~a:[a_class ["icon-bar"]][];
span ~a:[a_class ["icon-bar"]][]
];
a ~a:[a_class ["navbar-brand"]; a_href ("/" ^ config.index_page)][pcdata config.blog_name]
];
div ~a:[a_class ["collapse navbar-collapse collapse"]] [
ul ~a:[a_class ["nav navbar-nav navbar-right"]] links
]
]
];
main [
div ~a:[a_class ["flex-container"]] content
]
]
)
in
StringHtml.print page
Expand Down
48 changes: 42 additions & 6 deletions config.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,46 @@
open Mirage

(* Shell commands to run at configure time *)
type shellconfig = ShellConfig
let shellconfig = Type ShellConfig

let config_shell = impl @@ object
inherit base_configurable

method configure i =
let open Functoria_app.Cmd in
let (>>=) = Rresult.(>>=) in
let dir = Info.root i in

run "mkdir -p %s" (dir ^ "/disk/static/js") >>= fun () ->
run "mkdir -p %s" (dir ^ "/disk/static/css") >>= fun () ->
run "mkdir -p %s" (dir ^ "/disk/static/fonts") >>= fun () ->
let npm_query = run "which npm" |> Rresult.R.is_ok in
let lessc_query = run "which lessc" |> Rresult.R.is_ok in
let browserify_query = run "which browserify" |> Rresult.R.is_ok in
if (npm_query && lessc_query && browserify_query) then
(Printf.printf "npm, browserify and lessc found… fetching and compiling all assets\n";
run "cp assets/fonts/JosefinSans-SemiBold.ttf %s" (dir ^ "/disk/static/fonts") >>= fun () ->
run "npm install" >>= fun () ->
run "browserify assets/js/main.js -o disk/static/js/canopy.js" >>= fun () ->
run "lessc assets/less/style.less disk/static/css/style.css --source-map-map-inline --strict-imports" >>= fun () ->
run "cp node_modules/bootstrap/dist/css/bootstrap.min.css disk/static/css/bootstrap.min.css" >>= fun () ->
run "cp node_modules/highlight.js/styles/solarized-light.css disk/static/css/highlight.css" >>= fun () ->
Printf.printf "Compressing compiled assets to assets/assets_generated.tar.gz…\n";
run "tar -cf assets/assets_generated.tar.gz disk/")
else
(Printf.printf "npm, browserify and lessc not found… decompressing from assets/assets_generated.tar.gz\n";
run "tar -xf assets/assets_generated.tar.gz")

method clean i = Functoria_app.Cmd.run "rm -r node_modules disk"
Copy link
Collaborator

Choose a reason for hiding this comment

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

if node_modules and/or disk is not present, this leads to mirage clean failing... would be better to run the rm here only if the directories are present...


method module_name = "Functoria_runtime"
method name = "shell_config"
method ty = shellconfig
end

(* disk device *)

let disk =
let fs_key = Key.(value @@ kv_ro ()) in
let fat_ro dir = generic_kv_ro ~key:fs_key dir in
Expand Down Expand Up @@ -31,10 +72,6 @@ let remote_k =
let doc = Key.Arg.info ~doc:"Remote repository to fetch content." ["r"; "remote"] in
Key.(create "remote" Arg.(opt string "https://github.com/Engil/__blog.git" doc))

let mathjax_k =
let doc = Key.Arg.info ~doc:"Enable mathjax" ["mathjax"; "m"] in
Key.(create "mathjax" Arg.(flag doc))

(* Dependencies *)

let libraries = [
Expand Down Expand Up @@ -82,14 +119,13 @@ let () =
abstract port_k;
abstract push_hook_k;
abstract remote_k;
abstract mathjax_k;
abstract tls_port_k;
])
in
register "canopy" [
foreign
~libraries
~deps:[abstract nocrypto]
~deps:[abstract nocrypto; abstract config_shell]
~keys
~packages
"Canopy_main.Main"
Expand Down
36 changes: 36 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "canopy",
"version": "0.0.1",
"description": "A git-blogging unikernel",
"main": "canopy.js",
"directories": {
"test": "tests"
},
"dependencies": {
"bootstrap": "^3.3.6",
"highlight.js": "^9.3.0",
"jquery": "^2.2.3",
"less": "^2.6.1"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Engil/Canopy.git"
},
"keywords": [
"ocaml",
"mirage",
"canopy",
"blog",
"static"
],
"author": "Enguerrand Decorne",
"license": "MIT",
"bugs": {
"url": "https://github.com/Engil/Canopy/issues"
},
"homepage": "https://github.com/Engil/Canopy#readme"
}
4 changes: 0 additions & 4 deletions style.sh

This file was deleted.