Commit 98a99560 authored by julien dehos's avatar julien dehos

build docker image and deploy on heroku

parent a6bd2e32
# miso-xhr
<https://miso-xhr.herokuapp.com/>
## description
- isomorphic web app in Haskell, using Miso and Servant
......@@ -8,9 +10,55 @@
- type-safe routes & links (client + server)
## usage
![](doc/miso-xhr.mp4)
Install Nix, run `make` then go to <http://localhost:3000>.
![](doc/miso-xhr.mp4)
## setup
- install Nix, docker and heroku-cli
## develop
- use a nix-shell for the client:
```
nix-shell -A client
make client
```
- use a nix-shell for the server:
```
nix-shell -A server
make server
```
- test in a browser: <http://localhost:3000>
## deploy
- build a docker image:
```
nix-build docker.nix && docker load < result
```
- upload docker image to heroku:
```
heroku container:login
heroku create miso-xhr
docker tag miso-xhr:latest registry.heroku.com/miso-xhr/web
docker push registry.heroku.com/miso-xhr/web
heroku container:release web --app miso-xhr
```
- test:
```
heroku logs
heroku open --app miso-xhr
```
{ pkgs ? import <nixpkgs> {} }:
let
miso-xhr = import ./default.nix;
entrypoint = pkgs.writeScript "entrypoint.sh" ''
#!${pkgs.stdenv.shell}
$@
'';
in
pkgs.dockerTools.buildImage {
name = "miso-xhr";
tag = "latest";
created = "now";
config = {
WorkingDir = "${miso-xhr}";
Entrypoint = [ entrypoint ];
Cmd = [ "${miso-xhr}/bin/server" ];
};
}
......@@ -5,6 +5,7 @@
{-# LANGUAGE TypeOperators #-}
import Common
import Data.Maybe (fromMaybe)
import Data.Proxy (Proxy(..))
import qualified Lucid as L
import Miso
......@@ -12,9 +13,13 @@ import Network.Wai.Handler.Warp (run)
import qualified Network.Wai.Middleware.Gzip as Wai
import Network.Wai.Middleware.RequestLogger (logStdout)
import Servant
import System.Environment (lookupEnv)
main :: IO ()
main = run 3000 $ logStdout $ compress app
main = do
port <- read . fromMaybe "3000" <$> lookupEnv "PORT"
putStrLn $ "running on port " ++ show port ++ "..."
run port $ logStdout $ compress app
where app = serve (Proxy @ServerApi) server
compress = Wai.gzip Wai.def { Wai.gzipFiles = Wai.GzipCompress }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment