From 2642499df1795c8024992b3cfd8891c8fc576ed8 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Sun, 6 Dec 2020 15:12:48 -0500 Subject: De-nest Devalloc and a few other cleanups --- Biz/Bild/ShellHook.sh | 2 +- Biz/Dev.nix | 6 +- Biz/Devalloc.hs | 174 ++++++++++++++++++++++++++++++++++++++++++++++++++ Biz/Devalloc.nix | 46 +++++++++++++ Biz/Devalloc/Host.hs | 173 ------------------------------------------------- Biz/Devalloc/Host.nix | 46 ------------- 6 files changed, 224 insertions(+), 223 deletions(-) create mode 100644 Biz/Devalloc.hs create mode 100644 Biz/Devalloc.nix delete mode 100644 Biz/Devalloc/Host.hs delete mode 100644 Biz/Devalloc/Host.nix (limited to 'Biz') diff --git a/Biz/Bild/ShellHook.sh b/Biz/Bild/ShellHook.sh index 65c3f10..b40b91e 100644 --- a/Biz/Bild/ShellHook.sh +++ b/Biz/Bild/ShellHook.sh @@ -106,7 +106,7 @@ function ci() { stuff=( Biz/Pie.hs Biz/Pie.nix - Biz/Devalloc/Host.hs + Biz/Devalloc.hs Biz/Que/Site.hs Biz/Que/Host.hs Biz/Que/Prod.nix diff --git a/Biz/Dev.nix b/Biz/Dev.nix index d9f2cb6..14c0375 100644 --- a/Biz/Dev.nix +++ b/Biz/Dev.nix @@ -9,14 +9,14 @@ bild.os { ./Users.nix ./Dev/Configuration.nix ./Dev/Hardware.nix - ./Devalloc/Host.nix + ./Devalloc.nix ]; networking.hostName = "lithium"; networking.domain = "dev.simatime.com"; - services.devalloc-host = { + services.devalloc = { enable = true; port = 8095; - package = bild.ghc ./Devalloc/Host.hs; + package = bild.ghc ./Devalloc.hs; }; } diff --git a/Biz/Devalloc.hs b/Biz/Devalloc.hs new file mode 100644 index 0000000..7654785 --- /dev/null +++ b/Biz/Devalloc.hs @@ -0,0 +1,174 @@ +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE LambdaCase #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE TypeApplications #-} +{-# LANGUAGE TypeOperators #-} +{-# LANGUAGE NoImplicitPrelude #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} + +-- Developer allocation +-- +-- : out devalloc +-- : dep clay +-- dep cmark +-- sys cmark +-- : dep envy +-- : dep lucid +-- : dep protolude +-- : dep servant +-- : dep servant-lucid +-- : dep servant-server +-- : dep warp +module Biz.Devalloc + ( main, + ) +where + +import Alpha +import Biz.App (CSS (..), HtmlApp (..)) +import qualified Biz.Look +import qualified Clay +import qualified Control.Exception as Exception +import qualified Lucid +import qualified Lucid.Base as Lucid +import qualified Lucid.Servant as Lucid +import qualified Network.Wai as Wai +import Network.Wai.Application.Static (defaultWebAppSettings) +import qualified Network.Wai.Handler.Warp as Warp +import Network.Wai.Middleware.RequestLogger (logStdout) +import Servant +import Servant.HTML.Lucid +import qualified System.Envy as Envy + +main :: IO () +main = Exception.bracket startup shutdown run + where + startup = + Envy.decodeWithDefaults Envy.defConfig >>= \cfg -> do + putText "@" + putText "devalloc" + putText <| "port: " <> (show <| port cfg) + return (cfg, serve (Proxy @AllPaths) <| paths cfg) + shutdown :: (Config, Application) -> IO () + shutdown _ = pure () + run :: (Config, Wai.Application) -> IO () + run (cfg, app) = Warp.run (port cfg) (logStdout app) + +data Config = Config + { port :: Warp.Port, + assets :: FilePath + } + deriving (Generic, Show) + +instance Envy.DefConfig Config where + defConfig = + Config + { port = 8005, + assets = "_/bild/dev/static/devalloc.js" + } + +instance Envy.FromEnv Config + +-- | Wraps pages in default HTML +instance Lucid.ToHtml a => Lucid.ToHtml (HtmlApp a) where + toHtmlRaw = Lucid.toHtml + toHtml (HtmlApp x) = + Lucid.doctypehtml_ <| do + Lucid.head_ <| do + Lucid.meta_ [Lucid.charset_ "utf-8"] + jsRef "//unpkg.com/turbolinks@5.2.0/dist/turbolinks.js" + cssRef "/css/main.css" + Lucid.body_ (Lucid.toHtml x) + where + jsRef _href = + Lucid.with + (Lucid.script_ mempty) + [ Lucid.makeAttribute "src" _href, + Lucid.makeAttribute "async" mempty, + Lucid.makeAttribute "defer" mempty + ] + cssRef _href = + Lucid.with + (Lucid.link_ mempty) + [ Lucid.rel_ "stylesheet", + Lucid.type_ "text/css", + Lucid.href_ _href + ] + +-- * paths and pages + +type AllPaths = + Get '[HTML] (HtmlApp Page) + :<|> Signup + :<|> ("static" :> Raw) + :<|> "css" :> "main.css" :> Get '[CSS] Text + +type Signup = "signup" :> Get '[HTML] (HtmlApp Page) + +paths :: Config -> Server AllPaths +paths cfg = + path Home + :<|> path Signup + :<|> static + :<|> look + where + path = pure . HtmlApp + static = serveDirectoryWith <| defaultWebAppSettings <| assets cfg + look = + return . toStrict . Clay.render <| do + Biz.Look.fuckingStyle + "body" Clay.? Biz.Look.fontStack + +linkTo :: + (HasLink path, IsElem path api) => + Proxy api -> + Proxy path -> + MkLink path Lucid.Attribute +linkTo allPaths thisPath = Lucid.safeHref_ "/" allPaths thisPath + +data Page + = Home + | Signup + +instance Lucid.ToHtml Page where + toHtmlRaw = Lucid.toHtml + toHtml = \case + Home -> Lucid.toHtml pitch + Signup -> Lucid.toHtml signup + +-- * parts + +signup :: Lucid.Html () +signup = + Lucid.p_ <| Lucid.a_ [Lucid.href_ "mailto:ben@bsima.me?subject=Devalloc+signup"] "Request access via email" + +pitch :: Lucid.Html () +pitch = + Lucid.div_ <| do + Lucid.h1_ "Devalloc" + Lucid.p_ + "Devalloc analyzes your codebase trends, finds patterns \ + \ in how your developers work, and protects against tech debt." + Lucid.p_ "Just hook it up to your CI system - it will warn you when it finds a problem." + Lucid.a_ + [linkTo (Proxy :: Proxy AllPaths) (Proxy :: Proxy Signup)] + "Go to signup" + Lucid.h2_ "Identify blackholes in your codebase" + Lucid.p_ + "What if none of your active employees have touched some part of the codebase? \ + \ This happens too often with legacy code, and then it turns into a huge source of tech debt. \ + \ Devalloc finds these \"blackholes\" and warns you about them so you can be proactive in eliminating tech debt." + Lucid.h2_ "Protect against lost knowledge" + Lucid.p_ "Not everyone can know every part of a codebase. By finding pieces of code that only 1 or 2 people have touched, devalloc identifes siloed knowledge. This allows you to protect against the risk of this knowledge leaving the company if an employee leaves." + Lucid.h2_ "Don't just measure code coverage - also know your dev coverage" + Lucid.p_ "No matter how smart your employees are, if you are under- or over-utilizing your developers then you will never get optimal performance from your team." + Lucid.ul_ <| do + Lucid.li_ "Find developer hot spots in your code: which pieces of code get continually rewritten, taking up valuable dev time?" + Lucid.li_ "Know how your devs work best: which ones have depth of knowledge, and which ones have breadth?" + + Lucid.p_ "(Paid only)" + Lucid.h2_ "See how your teams *actually* organize themselves with cluster analysis" + Lucid.p_ "Does your team feel splintered or not cohesive? Which developers work best together? Devalloc analyzes the collaboration patterns between devs and helps you form optimal pairings and teams based on shared code and mindspace." + Lucid.p_ "(Paid only)" + signup diff --git a/Biz/Devalloc.nix b/Biz/Devalloc.nix new file mode 100644 index 0000000..0fd1550 --- /dev/null +++ b/Biz/Devalloc.nix @@ -0,0 +1,46 @@ +{ options +, lib +, config +, pkgs +, modulesPath +}: + +let + cfg = config.services.devalloc; +in +{ + options.services.devalloc = { + enable = lib.mkEnableOption "Enable the devalloc service"; + port = lib.mkOption { + type = lib.types.int; + default = 3000; + description = '' + The port on which devalloc will listen for + incoming HTTP traffic. + ''; + }; + package = lib.mkOption { + type = lib.types.package; + description = "devalloc package to use"; + }; + }; + config = lib.mkIf cfg.enable { + systemd.services.devalloc = { + path = [ cfg.package ]; + wantedBy = [ "multi-user.target" ]; + script = '' + ${cfg.package}/bin/devalloc + ''; + description = '' + Devalloc + ''; + serviceConfig = { + Environment = ["PORT=${toString cfg.port}"]; + KillSignal = "INT"; + Type = "simple"; + Restart = "on-abort"; + RestartSec = "1"; + }; + }; + }; +} diff --git a/Biz/Devalloc/Host.hs b/Biz/Devalloc/Host.hs deleted file mode 100644 index 522b9c6..0000000 --- a/Biz/Devalloc/Host.hs +++ /dev/null @@ -1,173 +0,0 @@ -{-# LANGUAGE DataKinds #-} -{-# LANGUAGE DeriveGeneric #-} -{-# LANGUAGE LambdaCase #-} -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE TypeApplications #-} -{-# LANGUAGE TypeOperators #-} -{-# LANGUAGE NoImplicitPrelude #-} -{-# OPTIONS_GHC -fno-warn-orphans #-} - --- Developer allocation --- --- : out devalloc-host --- : dep clay --- : dep cmark --- : sys cmark --- : dep envy --- : dep lucid --- : dep protolude --- : dep servant --- : dep servant-lucid --- : dep servant-server --- : dep warp -module Biz.Devalloc.Host - ( main, - ) -where - -import Alpha -import Biz.App (CSS (..), HtmlApp (..)) --- import qualified CMark as Cmark - -import qualified Biz.Look -import qualified Clay -import qualified Control.Exception as Exception -import qualified Lucid -import qualified Lucid.Base as Lucid -import qualified Lucid.Servant as Lucid -import qualified Network.Wai as Wai -import Network.Wai.Application.Static (defaultWebAppSettings) -import qualified Network.Wai.Handler.Warp as Warp -import Network.Wai.Middleware.RequestLogger (logStdout) -import Servant -import Servant.HTML.Lucid -import qualified System.Envy as Envy - -main :: IO () -main = Exception.bracket startup shutdown run - where - startup = - Envy.decodeWithDefaults Envy.defConfig >>= \cfg -> do - -- pitchText <- readFile <| pitches cfg - -- let pitch = Cmark.commonmarkToHtml [] pitchText - putText "@" - putText "devalloc" - putText <| "port: " <> (show <| port cfg) - return (cfg, serve (Proxy @AllPaths) <| paths cfg) - shutdown :: (Config, Application) -> IO () - shutdown _ = pure () - run :: (Config, Wai.Application) -> IO () - run (cfg, app) = Warp.run (port cfg) (logStdout app) - -data Config = Config - { port :: Warp.Port, - -- | A yaml file of pitches - pitches :: FilePath, - assets :: FilePath - } - deriving (Generic, Show) - -instance Envy.DefConfig Config where - defConfig = - Config - { port = 8005, - pitches = "./Biz/Devalloc/pitch.md", - assets = "_/bild/dev/static/devalloc.js" - } - -instance Envy.FromEnv Config - --- | Wraps pages in default HTML -instance Lucid.ToHtml a => Lucid.ToHtml (HtmlApp a) where - toHtmlRaw = Lucid.toHtml - toHtml (HtmlApp x) = - Lucid.doctypehtml_ <| do - Lucid.head_ <| do - Lucid.meta_ [Lucid.charset_ "utf-8"] - jsRef "//unpkg.com/turbolinks@5.2.0/dist/turbolinks.js" - cssRef "/css/main.css" - Lucid.body_ (Lucid.toHtml x) - where - jsRef _href = - Lucid.with - (Lucid.script_ mempty) - [ Lucid.makeAttribute "src" _href, - Lucid.makeAttribute "async" mempty, - Lucid.makeAttribute "defer" mempty - ] - cssRef _href = - Lucid.with - (Lucid.link_ mempty) - [ Lucid.rel_ "stylesheet", - Lucid.type_ "text/css", - Lucid.href_ _href - ] - --- * paths and pages - -type AllPaths = - Get '[HTML] (HtmlApp Path) - :<|> Signup - :<|> ("static" :> Raw) - :<|> "css" :> "main.css" :> Get '[CSS] Text - -type Signup = "signup" :> Get '[HTML] (HtmlApp Path) - -paths :: Config -> Server AllPaths -paths cfg = - path Home - :<|> path Signup - :<|> static - :<|> look - where - path = pure . HtmlApp - static = serveDirectoryWith <| defaultWebAppSettings <| assets cfg - look = - return . toStrict . Clay.render <| do - Biz.Look.fuckingStyle - "body" Clay.? Biz.Look.fontStack - -data Path - = Home - | Signup - -instance Lucid.ToHtml Path where - toHtmlRaw = Lucid.toHtml - toHtml = \case - Home -> Lucid.toHtml pitch - Signup -> Lucid.toHtml signup - --- * parts - -signup :: Lucid.Html () -signup = - Lucid.p_ <| Lucid.a_ [Lucid.href_ "mailto:ben@bsima.me?subject=Devalloc+signup"] "Request access via email" - -pitch :: Lucid.Html () -pitch = - Lucid.div_ <| do - Lucid.h1_ "Devalloc" - Lucid.p_ - "Devalloc analyzes your codebase trends, finds patterns \ - \ in how your developers work, and protects against tech debt." - Lucid.p_ "Just hook it up to your CI system - it will warn you when it finds a problem." - Lucid.a_ [Lucid.safeHref_ "/" (Proxy :: Proxy AllPaths) (Proxy :: Proxy Signup)] - "Go to signup" - Lucid.h2_ "Identify blackholes in your codebase" - Lucid.p_ - "What if none of your active employees have touched some part of the codebase? \ - \ This happens too often with legacy code, and then it turns into a huge source of tech debt. \ - \ Devalloc finds these \"blackholes\" and warns you about them so you can be proactive in eliminating tech debt." - Lucid.h2_ "Protect against lost knowledge" - Lucid.p_ "Not everyone can know every part of a codebase. By finding pieces of code that only 1 or 2 people have touched, devalloc identifes siloed knowledge. This allows you to protect against the risk of this knowledge leaving the company if an employee leaves." - Lucid.h2_ "Don't just measure code coverage - also know your dev coverage" - Lucid.p_ "No matter how smart your employees are, if you are under- or over-utilizing your developers then you will never get optimal performance from your team." - Lucid.ul_ <| do - Lucid.li_ "Find developer hot spots in your code: which pieces of code get continually rewritten, taking up valuable dev time?" - Lucid.li_ "Know how your devs work best: which ones have depth of knowledge, and which ones have breadth?" - - Lucid.p_ "(Paid only)" - Lucid.h2_ "See how your teams *actually* organize themselves with cluster analysis" - Lucid.p_ "Does your team feel splintered or not cohesive? Which developers work best together? Devalloc analyzes the collaboration patterns between devs and helps you form optimal pairings and teams based on shared code and mindspace." - Lucid.p_ "(Paid only)" - signup diff --git a/Biz/Devalloc/Host.nix b/Biz/Devalloc/Host.nix deleted file mode 100644 index 51aa85d..0000000 --- a/Biz/Devalloc/Host.nix +++ /dev/null @@ -1,46 +0,0 @@ -{ options -, lib -, config -, pkgs -, modulesPath -}: - -let - cfg = config.services.devalloc-host; -in -{ - options.services.devalloc-host = { - enable = lib.mkEnableOption "Enable the devalloc-host service"; - port = lib.mkOption { - type = lib.types.int; - default = 3000; - description = '' - The port on which devalloc-host will listen for - incoming HTTP traffic. - ''; - }; - package = lib.mkOption { - type = lib.types.package; - description = "devalloc-host package to use"; - }; - }; - config = lib.mkIf cfg.enable { - systemd.services.devalloc-host = { - path = [ cfg.package ]; - wantedBy = [ "multi-user.target" ]; - script = '' - ${cfg.package}/bin/devalloc-host - ''; - description = '' - Devalloc.Host - ''; - serviceConfig = { - Environment = ["PORT=${toString cfg.port}"]; - KillSignal = "INT"; - Type = "simple"; - Restart = "on-abort"; - RestartSec = "1"; - }; - }; - }; -} -- cgit v1.2.3