diff --git a/README.md b/README.md index 865cd1e..bf77790 100644 --- a/README.md +++ b/README.md @@ -42,9 +42,9 @@ Only Nix build instructions are provided below. ### Containers 1) Clone this repository 2) Build the container image (with flakes enabled): `nix build .#purr-container` -3) Load the container image - - podman load -i result -4) NixOS configuration: +3) Load the container image: `podman load -i result` +4) Pick option 5, 6, or use your favorite process to manage containers and ENV +5) NixOS configuration: ``` virtualisation.oci-containers.containers.purr = { image = "purr"; @@ -63,9 +63,13 @@ virtualisation.oci-containers.containers.purr = { }; }; ``` -5) Docker Stack - 1) Set environment variables in docker-stack.yml or mount a .env file. - 2) `docker stack deploy -c docker-stack.yml purr` +6) Docker Stack + 1) Copy the docker-stack.yml example and edit as needed. + 1) `cp examples/docker-stack.yml ./; $EDITOR ./docker-stack.yml` + 2) Set environment variables: + - `cp examples/.env.example ./.env; $EDITOR ./.env` + - Or set them in the docker-stack.yml environment declaration. + 3) Deploy: `docker stack deploy -c docker-stack.yml purr` ## DEVELOPMENT & SUPPORT diff --git a/src/Core/Configuration.hs b/src/Core/Configuration.hs index 63c6b23..f02f157 100644 --- a/src/Core/Configuration.hs +++ b/src/Core/Configuration.hs @@ -39,6 +39,9 @@ encKey = do adminEmail :: IO String adminEmail = getEnv "ADMINEMAIL" +getRuntimeEnvironment :: IO String +getRuntimeEnvironment = getEnv "ENVIRONMENT" + appPort :: IO String appPort = getEnv "APPLICATIONPORT" diff --git a/src/Core/HTTP.hs b/src/Core/HTTP.hs index e18cbbd..b0e041d 100644 --- a/src/Core/HTTP.hs +++ b/src/Core/HTTP.hs @@ -1,22 +1,28 @@ module Core.HTTP ( app ) where -import Core.Configuration (adminEmail, confLinkLength) +import Core.Configuration ( adminEmail + , confLinkLength + , getRuntimeEnvironment) import Core.Types import Core.Templates (renderIndex, renderStyle) import Feature.Generation.HTTP as Generation import Feature.Sharing.HTTP as Sharing +import Control.Monad (void) import Control.Monad.Trans (liftIO) import Data.Maybe (Maybe (Nothing)) -import Network.Wai.Middleware.RequestLogger (logStdoutDev) +import Network.Wai.Middleware.RequestLogger (logStdout, logStdoutDev) import Network.Wai.Middleware.Static import Web.Scotty -app :: PurrApp () -app = do +app :: String -> PurrApp () +app env = do -- Middleware that are processed on every request - middleware logStdoutDev + case env of + "production" -> middleware logStdout + "prod" -> middleware logStdout + _ -> middleware logStdoutDev middleware $ staticPolicy (noDots >-> addBase "data/assets/public") -- Core Routes diff --git a/src/Lib.hs b/src/Lib.hs index 08f23be..a6554fd 100644 --- a/src/Lib.hs +++ b/src/Lib.hs @@ -27,5 +27,6 @@ main = do {- Get the configured port to run on and start the Scotty webserver app defined in HTTP.app -} appPortStr <- Configuration.appPort + env <- Configuration.getRuntimeEnvironment let appPort = read appPortStr :: Int - scotty appPort HTTP.app + scotty appPort (HTTP.app env)