Skip to content

Commit

Permalink
Automate and tweak example/z-docker-opam
Browse files Browse the repository at this point in the history
  • Loading branch information
aantron committed May 8, 2021
1 parent f3d04f2 commit f36afcf
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 24 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/docker-opam.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: docker-opam
on:
push:
paths:
- 'example/z-docker-opam/**'
- .github/workflows/docker-opam.yml

jobs:
deploy:
runs-on: ubuntu-latest
defaults:
run:
working-directory: example/z-docker-opam
steps:
- uses: actions/checkout@v2

- uses: webfactory/[email protected]
with:
ssh-private-key: ${{secrets.DIGITALOCEAN_SSH_KEY}}
- run: echo "${{secrets.DIGITALOCEAN_DOCKER_OPAM_KNOWN_HOSTS}}" >> /home/runner/.ssh/known_hosts

- run: rsync -rlv . [email protected]:app --exclude _build --exclude _opam
- run: ssh [email protected] "cd app && bash deploy.sh"
6 changes: 4 additions & 2 deletions example/z-docker-opam/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM ocaml/opam:alpine as build
# Install system dependencies
RUN sudo apk add --update libev-dev openssl-dev

WORKDIR /build
WORKDIR /home/opam

# Install dependencies
ADD hello.opam hello.opam
Expand All @@ -13,10 +13,12 @@ RUN opam install . --deps-only
ADD . .
RUN opam exec -- dune build



FROM alpine:3.12 as run

RUN apk add --update libev

COPY --from=build /build/_build/default/app.exe /bin/app
COPY --from=build /home/opam/_build/default/app.exe /bin/app

ENTRYPOINT /bin/app
18 changes: 14 additions & 4 deletions example/z-docker-opam/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@

<br>

This example wraps a very simple Web app in a [Docker](https://www.docker.com/)
container, and runs it persistently, as a daemon.
This example runs a simple Web app inside a [Docker](https://www.docker.com/)
container. It is a variant of [**`z-docker-esy`**](../z-docker-esy#files), but
with [opam](https://opam.ocaml.org/) as the package manager.

It is an variant of `z-docker` with Opam as a package manager instead of Esy.
Please see `z-docker`'s README for an in-depth guide on how to configure a Digital Ocean droplet and the commands to deploy.
All the instructions are the same as in
[**`z-docker-esy`**](../z-docker-esy#files). The difference is in the
[`Dockerfile`](https://github.com/aantron/dream/blob/master/example/z-docker-opam/Dockerfile),
which, in this example, derives an image from one of the [opam base
images](https://hub.docker.com/r/ocaml/opam), and installs dependencies using
opam. The initial build requires at least 2 GB of memory.

The example is live at
[http://docker-opam.dream.as](http://docker-opam.dream.as), and is deployed
there automatically, on push, by a
[GitHub action](https://github.com/aantron/dream/blob/master/.github/workflows/docker-opam.yml).

<br>

Expand Down
3 changes: 2 additions & 1 deletion example/z-docker-opam/app.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ let () =
Dream.run ~interface:"0.0.0.0"
@@ Dream.logger
@@ Dream.router [
Dream.get "/" (fun _ -> Dream.html "Good morning, world!");
Dream.get "/" (fun _ ->
Dream.html "Dream started by Docker Compose, built with opam!");
]
@@ Dream.not_found
19 changes: 2 additions & 17 deletions example/z-docker-opam/hello.opam
Original file line number Diff line number Diff line change
@@ -1,22 +1,7 @@
opam-version: "2.0"
synopsis: "Example of a docker deployment with Dream"
description: "Example of a docker deployment with Dream."

depends: [
"ocaml" {>= "4.08.0"}
"dune"
"dune" {>= "2.0.0"}
"dream"
]
build: [
["dune" "subst"] {pinned}
[
"dune"
"build"
"-p"
name
"-j"
jobs
"@install"
"@runtest" {with-test}
"@doc" {with-doc}
]
]

0 comments on commit f36afcf

Please sign in to comment.