diff options
author | Ben Sima <ben@bsima.me> | 2019-11-02 15:54:20 -0700 |
---|---|---|
committer | Ben Sima <ben@bsima.me> | 2019-11-02 17:13:04 -0700 |
commit | ed4e214d481f67f796014aa80731b6d273618b6c (patch) | |
tree | f44cd4b80de8b624f38f7637f4615b79517ee993 | |
parent | 9d114cfc773171b0a95bd4d2c39f1bb0eb783c8d (diff) |
add common scripts, remove old scripts, update readme
-rwxr-xr-x | Com/Simatime/roun (renamed from chip/roun) | 0 | ||||
-rw-r--r-- | README.md | 50 | ||||
-rwxr-xr-x | bild | 2 | ||||
-rwxr-xr-x | chip/make | 138 | ||||
-rwxr-xr-x | chip/push | 48 | ||||
-rwxr-xr-x | chip/run | 3 | ||||
-rwxr-xr-x | ghci | 2 | ||||
-rwxr-xr-x | push | 5 | ||||
-rwxr-xr-x | rise | 5 |
9 files changed, 43 insertions, 210 deletions
diff --git a/chip/roun b/Com/Simatime/roun index addbaf3..addbaf3 100755 --- a/chip/roun +++ b/Com/Simatime/roun @@ -1,19 +1,22 @@ # Source Layout -The source tree maps to the DNS namespace that we own. The purpose of this -mapping is to keep things organized hierarchically in how they are deployed on -the Internet. The main 'common' space is `com.simatime`, everything else should -be related to the application. +The source tree maps to the DNS namespace that we own. The purpose of +this mapping is to keep things organized hierarchically in how they are +deployed on the Internet. The main 'common' space is `Com.Simatime`, +other namespaces should be related to the application. -Development aspects should be localized to their sub-namespaces as much as -possible. Only after sufficient iteration such that interfaces are solidified -and functionality is well-established should some code be promoted up the -namespace hierarchy. +Development aspects should be localized to their sub-namespaces as much +as possible. Only after sufficient iteration such that interfaces are +solidified and functionality is well-established should some code be +promoted up the namespace hierarchy. Boundaries and interfaces between namespaces should be small and -well-defined. Likewise, the functionality and purpose of a particular namespace -should be small and well-defined. Following the unix principle of "do one thing -and do it well" is advised. +well-defined. Likewise, the functionality and purpose of a particular +namespace should be small and well-defined. Following the unix principle +of "do one thing and do it well" is advised. + +For building the code, we use `nix` and basically copy the namespace +hierarchy into the main build file `./default.nix`. # Development @@ -21,31 +24,36 @@ To build code, do: nix build -f default.nix <thing> -To get a repl: +To get in the environment for a thing, use `nix run`. For example, if +you want `ghci` with packages for `ibb`, do this: - nix run -f default.nix <thing> + nix run -f default.nix Com.InfluencedByBooks.ghc && ghci And to deploy: nix copy --to ssh://root@simatime.com ./result ssh root@simatime.com $(realpath ./result)/bin/switch-to-configuration switch +These three common tasks are captured in the `./bild`, `./ghci`, and +`./push` scripts. + # Goals of the developer workflow: - have minimal ceremony - default to asynchrony, but allow for synchronous work when necessary - automate the boring stuff -- standardize environments, tooling, and versions to minimize friction while - collaborating +- standardize environments, tooling, and versions to minimize friction + while collaborating - support the longevity and self-sustainability of the project -Ideally, each contributor should be able to go off grid for a day or a week or -more, continue working offline, submit their work when finished, and have no or -minimal conflicts. This also refers to the resilience of the production systems. +Ideally, each contributor should be able to go off grid for a day or a +week or more, continue working offline, submit their work when finished, +and have no or minimal conflicts. This also refers to the resilience of +the production systems. -We should never need "out of office" email auto-replies, or urgent contact. No -pager duty, no daily stand-ups. Yes, this policy will affect what code we write, -not just how we write it; that is by design. +We should never need "out of office" email auto-replies, or urgent +contact. No pager duty, no daily stand-ups. Yes, this policy will affect +what code we write, not just how we write it; that is by design. ## Org @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +nix build -f default.nix "$@" diff --git a/chip/make b/chip/make deleted file mode 100755 index da5fe97..0000000 --- a/chip/make +++ /dev/null @@ -1,138 +0,0 @@ -#!/usr/bin/env runhaskell - -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE RecordWildCards #-} -{-# OPTIONS_GHC -Wall #-} - --- | chip/make --- --- this is the main build script. it just calls out to `ghc --make` basically. --- - -module Main where - -import Control.Concurrent -import Control.Exception -import Control.Monad -import Data.ByteString.Char8 (pack) -import qualified Data.Char as Char -import Data.List -import System.Directory -import System.Environment -import System.FilePath -import System.INotify -import System.Process - -data Notify = Notify - { notify :: IO () - , wait :: IO () - } - --- | skip channel to model concurrency semantics. this ensures that we don't --- execute more than one command at a time. -initNotify :: IO Notify -initNotify = do - mvar <- newMVar () - pure $ Notify - (void $ tryPutMVar mvar ()) - (takeMVar mvar) - -main :: IO () -main = do - (app, act) <- parseArgs <$> getArgs - case act of - Rise -> do - inotify <- initINotify - Notify {..} <- initNotify - dirs <- nub . concat <$> mapM getDirs ["aero", "apex", "lore"] - forM_ dirs $ \arg -> - void $ addWatch inotify [Modify] (pack arg) (const notify) - forever $ wait >> bild app >> say "waiting..." - Make -> bild app - Tidy -> do - callCommand "rm -rf bild/*" - say "made: tidy" - -bild :: App -> IO () -bild app = do - say $ "make: " ++ name app - apex app `catch` nop - aero app `catch` nop - say $ "made: " ++ name app - -say :: String -> IO () -say = putStrLn - -nop :: SomeException -> IO () -nop _ = pure () - - -data Action = Make | Rise | Tidy - -parseArgs :: [String] -> (App, Action) -parseArgs [] = errorWithoutStackTrace "usage: chip/make [make|rise|tidy] <app>" -parseArgs (act:name:_) = - ( App (lowercase name) (capitalize name) - , case lowercase act of - "rise" -> Rise - "tidy" -> Tidy - _ -> Make - ) -parseArgs (name:_) = case name of - "tidy" -> (App (lowercase "") (capitalize ""), Tidy) - _ -> (App (lowercase name) (capitalize name), Make) - -capitalize, lowercase :: String -> String -capitalize (α:ω) = Char.toUpper α : map Char.toLower ω -capitalize [] = [] -lowercase (α:ω) = Char.toLower α : map Char.toLower ω -lowercase [] = [] - -data App = App - { name :: String - , entrypoint :: String - } - --- | common build options. -ghcopts :: String -ghcopts = "-odir bild/o -hidir bild/hi -Wall" - --- | compile with ghc. -apex :: App -> IO () -apex App {..} = callCommand $ intercalate " " - [ "ghc" - , ghcopts - , "-iapex -ilore" - , "-main-is", entrypoint - , "--make", "apex/" ++ entrypoint ++ ".hs" - , "-o bild/" ++ name - ] - --- | compile with ghcjs. -aero :: App -> IO () -aero App {..} = callCommand $ intercalate " " - [ "ghcjs" - , ghcopts - , "-iaero -ilore" - , "-main-is", entrypoint - , "--make", "aero/" ++ entrypoint ++ ".hs" - , "-o bild/" ++ name - ] - -getDirs :: FilePath -> IO [FilePath] -getDirs path = do - isDir <- doesDirectoryExist path - if isDir - then do - dirs <- listDirectory path - if null dirs - then pure [path] - else concat <$> do - mapM getDirs $ (path </>) <$> dirs - else pure [prune path] - -prune :: String -> String -prune = reverse . dropWhile (/= '/') . reverse - -secs :: Int -> Int -secs = (* 1000000) diff --git a/chip/push b/chip/push deleted file mode 100755 index f7114ed..0000000 --- a/chip/push +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env python3 - -import argparse -import os -import subprocess -import tempfile -import importlib.util -import sys - -def shell(*args): - "Run a shell command and capture the output." - try: - proc = subprocess.run(args, check=True, capture_output=True) - except subprocess.CalledProcessError as e: - print(f'! fail {e.returncode}') - print(f'! {" ".join(e.cmd)}') - print(f'! {e.stderr.strip().decode("utf8")}') - sys.exit(1) - return proc.stdout.strip().decode('utf8') - -cli = argparse.ArgumentParser(description='deploy a thing') -cli.add_argument('depo', type=str, - help='the depo roun to deploy') - -args = cli.parse_args() - -cwd = os.getcwd() -bild_dir = f"{cwd}/bild" - -src = f"{cwd}/depo/{args.depo}" -out = f"{bild_dir}/{args.depo}" - - -# bild -shell("nix-build", "-A", f"depo.{args.depo}", "--out-link", out) -print("+ bilt") - -# push -shell("nix", "copy", "--to", f"ssh://root@{args.depo}", f"{out}") -print("+ sent") - -# switch -shell("ssh", f"root@{args.depo}", "sudo", - f"{os.readlink(out)}/bin/switch-to-configuration", - "switch") -print("+ switched") - -print(f"+ pushed {args.depo}") diff --git a/chip/run b/chip/run deleted file mode 100755 index cf4a768..0000000 --- a/chip/run +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash - -cd bild && exec "./$1" @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +nix run -f default.nix "$@.ghc" -c ghci @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +where="$1" +what="$2" +nix copy --to ssh://root@$where $what +ssh root@$where $(realpath $what)/bin/switch-to-configuration switch @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +nix build -f default.nix "$@".app +export STATIC_DIR=$(realpath ./result/static) +echo $STATIC_DIR +./result/bin/ibb |