Clarify README further, ensure production logger is used when set to PRODUCTION environment

This commit is contained in:
James Eversole 2024-02-18 19:34:16 -06:00
parent d713f9b4e6
commit 5072fb4df4
4 changed files with 26 additions and 12 deletions

@ -42,9 +42,9 @@ Only Nix build instructions are provided below.
### Containers ### Containers
1) Clone this repository 1) Clone this repository
2) Build the container image (with flakes enabled): `nix build .#purr-container` 2) Build the container image (with flakes enabled): `nix build .#purr-container`
3) Load the container image 3) Load the container image: `podman load -i result`
- podman load -i result 4) Pick option 5, 6, or use your favorite process to manage containers and ENV
4) NixOS configuration: 5) NixOS configuration:
``` ```
virtualisation.oci-containers.containers.purr = { virtualisation.oci-containers.containers.purr = {
image = "purr"; image = "purr";
@ -63,9 +63,13 @@ virtualisation.oci-containers.containers.purr = {
}; };
}; };
``` ```
5) Docker Stack 6) Docker Stack
1) Set environment variables in docker-stack.yml or mount a .env file. 1) Copy the docker-stack.yml example and edit as needed.
2) `docker stack deploy -c docker-stack.yml purr` 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 ## DEVELOPMENT & SUPPORT

@ -39,6 +39,9 @@ encKey = do
adminEmail :: IO String adminEmail :: IO String
adminEmail = getEnv "ADMINEMAIL" adminEmail = getEnv "ADMINEMAIL"
getRuntimeEnvironment :: IO String
getRuntimeEnvironment = getEnv "ENVIRONMENT"
appPort :: IO String appPort :: IO String
appPort = getEnv "APPLICATIONPORT" appPort = getEnv "APPLICATIONPORT"

@ -1,22 +1,28 @@
module Core.HTTP ( app ) where module Core.HTTP ( app ) where
import Core.Configuration (adminEmail, confLinkLength) import Core.Configuration ( adminEmail
, confLinkLength
, getRuntimeEnvironment)
import Core.Types import Core.Types
import Core.Templates (renderIndex, renderStyle) import Core.Templates (renderIndex, renderStyle)
import Feature.Generation.HTTP as Generation import Feature.Generation.HTTP as Generation
import Feature.Sharing.HTTP as Sharing import Feature.Sharing.HTTP as Sharing
import Control.Monad (void)
import Control.Monad.Trans (liftIO) import Control.Monad.Trans (liftIO)
import Data.Maybe (Maybe (Nothing)) import Data.Maybe (Maybe (Nothing))
import Network.Wai.Middleware.RequestLogger (logStdoutDev) import Network.Wai.Middleware.RequestLogger (logStdout, logStdoutDev)
import Network.Wai.Middleware.Static import Network.Wai.Middleware.Static
import Web.Scotty import Web.Scotty
app :: PurrApp () app :: String -> PurrApp ()
app = do app env = do
-- Middleware that are processed on every request -- 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") middleware $ staticPolicy (noDots >-> addBase "data/assets/public")
-- Core Routes -- Core Routes

@ -27,5 +27,6 @@ main = do
{- Get the configured port to run on and start the Scotty webserver app {- Get the configured port to run on and start the Scotty webserver app
defined in HTTP.app -} defined in HTTP.app -}
appPortStr <- Configuration.appPort appPortStr <- Configuration.appPort
env <- Configuration.getRuntimeEnvironment
let appPort = read appPortStr :: Int let appPort = read appPortStr :: Int
scotty appPort HTTP.app scotty appPort (HTTP.app env)