• Stars
    star
    119
  • Rank 297,930 (Top 6 %)
  • Language
    OCaml
  • License
    ISC License
  • Created over 8 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A git-blogging unikernel written using MirageOS

Canopy - A git-blogging unikernel 🌿 Build Status

Canopy is an attempt at writting a blog-engine based on Git using MirageOS.

The goal is to provide a simple blog platform that only requires you to provide a Git remote URL and respecting some architecture rules within the said repository.

Canopy is written in OCaml using MirageOS and Irmin. It is running on both Unix and Xen.

HTTPS/TLS support

Canopy has TLS support, you have to first create your TLS private key and get a signed certificate (using certify and/or let's encrypt - sorry, no let's encrypt client in OCaml yet).

Put your unencrypted private key into tls/server.key, and your full certificate chain (starting with the server certificate, then the intermediate CAs, no need to include the root CA) into tls/server.pem before running mirage configure (which will embed them as OCaml code into the binary).

You can configure Canopy with --tls=<port> to run it as HTTPS service. Canopy will then respond to HTTP requests with a moved permanently redirection to the HTTPS URL. Also, the HTTPS service includes a strict transport security HTTP header (containing max-age=31536000).

Compiling and running Canopy

You will need at least OCaml 4.07.1, opam 2.0 and mirage 3.7.5 before starting. To setup a mirage environment, please refer to the mirage website.

Checkout Canopy repository, then go inside:

# Configure the mirage application, compile assets
mirage configure -t unix
# Get dependencies
make depend
# Compile Canopy
make
# Run it
./canopy

Note: if you run Canopy with a grsec kernel you might have to relax memory-mapping restrictions (i.e.: paxctl -cm canopy) and load the tun module.

A server will be launched using the specified URL as the git remote, Index as the default page rendered on the blog (it must exist within the repository) and 8080 is the listening port. You can see more options by running ./canopy --help.

To prepare your own data repository, you have to use npm, less-css and browserify if you want to compile and retrieve everything related to the blog-styling. The mirage configure step takes care of fetching and recompiling all assets. If none of the mentioned programs were to be found, the configure step will use the tarball found in the assets directory, containing already compiled assets.

# OR start with git clone git://github.com/Engil/__blog.git ;)
mkdir canopy-data
cd canopy-data
git init .
# Populate data using npm, browserify, etc.
if [ -x `which npm` ] ; then
  ./populate.sh /tmp/data
else
  # OR use pregenerated tarball
  cd /tmp/data && tar xf assets/assets_generated.tar.gz
  cd /tmp/data && mv disk/static .
fi;

git add static

# Generate a UUID for the Atom feed
uuidtrip -r > .config/uuid
# Add blog name (defaults to "Canopy")
echo "My blog" > .config/blog_name
git add .config

git commit -m initial

# configure git remote and push
git remote add origin [email protected]/me/__blog.git
git push origin master

You can run Canopy with your own data repository:

./canopy -r git://github.com/me/__blog.git

You can use git branches for drafting changes: ./canopy -r git://github.com/me/__blog.git#dev.

Compiling and running on Xen

If you want to build for xen, there's a couple of packages that need to be installed from specific branches.

opam pin add dolog 'https://github.com/UnixJunkie/dolog.git#no_unix'
opam pin add bin_prot 'https://github.com/hannesm/bin_prot.git#113.33.00+xen'

You can either build with support for DHCP or static ip, just specifying it as command line arguments, for instance:

mirage configure --xen --dhcp false --net direct --ip 10.0.0.2 --netmask 255.255.255.0 --gateways 10.0.0.1
make

Make sure to have br0 set up for this. For example, I did:

# provide ip forwarding
echo 'net.ipv4.ip_forward=1' >> /etc/sysctl.conf
sysctl -p /etc/sysctl.conf
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
# create a new bridge
brctl addbr br0
ip addr dev br0 add 10.0.0.1/24
ip link set br0 up

Finally you can run your unikernel!

xl create -c canopy.xl

Git push hooks

To keep your Canopy content updated, you need to tell your instance that new content is available on the git remote, then it will just pull the changes and will serve the new content.

To do that, Canopy use a simple URL path that you can set into Canopy_config.ml (hook_push_path).

Using Github, setting up this hook is pretty simple: just add a push webhook targeting your URL + your hook path. For example, by default this hook path is push, so the resulting URL is http://yourdomain/push.

If you are not using Github, you can just find a way (post-commit-hooks, for example) to run a HTTP request to this URL.

How Canopy works

Canopy will require you to provide a Git remote uri. Once started, it will clone in-memory the repository content and serve the content in a more or less organized way.

Each file at the root of the repository is considered a standalone page, more like the usual « About » or « Contact » pages. They will have their own entries in the navigation menu.

Each directories will contains more pages, but that will be classified under a category decided by the name of the said directory. For example, a posts/hello-word.md file will be a new blog post under the Posts category. You can use it to emulate some sort of tag, like for example having an OCaml directory regrouping all you writing in everyone's favorite language. :-)

Static assets (not processed) can be added into "static" subdir, configuration values below ".config".

The file syntax of articles is just plain markdown, everything should be supported out-the-box (depending on the ocaml-omd markdown implementation), with a little bit of extra informations absolutely needed at the top of each files.

---
title: A blog entry
author: Me
author_url: http://www.an_optional_link_that_wraps_the_author.com
abstract: A simple line telling what this article is all about, will be displayed in listing pages. (optional)
---
article content

If you don't respect this syntax, then the article won't show up in the resulting website.

You can also put some MathJax inside articles, Mathjax is activated if you pass the --mathjax parameter at startup.

More Repositories

1

Goodboy

A pure OCaml Gameboy emulator
OCaml
80
star
2

reason-web-toplevel

A Reason web toplevel built using js_of_ocaml
OCaml
17
star
3

Toolboy

A set of tools to work with Gameboy stuff
OCaml
14
star
4

KaamelottAsAService

MirageOS application serving random Kaamelott quotation via HTTP - Running here
OCaml
12
star
5

ImaginaryFriend

IRC logger using Irmin for persistence
OCaml
10
star
6

gc-tracing

Jupyter Notebook
5
star
7

Cotton

Experiments with an Opium based webservice+Irmin
OCaml
4
star
8

Candy

UI for Cotton
OCaml
4
star
9

ocaml-ctypes-inverted-stubs-tls-prototype

OCaml Ctypes inverted stubs for Ocaml-tls.
OCaml
4
star
10

ocamlotron

WIP
3
star
11

ocaml-exif

A streaming parser and writer for EXIF metadata, in pure OCaml
2
star
12

ocaml-babeltrace1

Bindings to the Babeltrace library (version 1.5 only)
OCaml
2
star
13

KaamelottQuotesElm

A simple Elm example using KaamelottAsAService to retrieve quotes
Elm
2
star
14

Integ

Diverses méthodes de calcul d'intégrales implémentées en une vingtaine de langages.
Ada
2
star
15

ErlangPlayground

Just toying around with Erlang
Erlang
1
star
16

opium-middleware-extra

Various middleware to use with Opium (WIP)
Makefile
1
star
17

Canopy-skeleton

A sample Canopy configuration repository
JavaScript
1
star
18

makefs

MirBSD's makefs extracted from the latest Debian package
C
1
star
19

Cotonnier

A Blog-engine written in Haskell with Yesod and using MongoDB
CSS
1
star
20

tezos-multicore-docker

dockerfile to build tezos against Multicore OCaml
Dockerfile
1
star
21

Tapioca

Experimenting on an Eliom/Ocsigen collaborative rich text editor
OCaml
1
star
22

irmin-playground

There is nothing to see here
OCaml
1
star
23

eliom-collaborative-editor

A repository used to showcase how to implement such an editor using Eliom and Ocsigen
OCaml
1
star
24

RainbOCaml

A 2048 clone based on color combinations
OCaml
1
star
25

ctypes-playground

OCaml
1
star