diff --git a/Application.hs b/Application.hs index cdf1f20..15018c5 100644 --- a/Application.hs +++ b/Application.hs @@ -2,6 +2,7 @@ module Application ( getApplicationDev , appMain + , appSelfContainedMain , develMain , makeFoundation -- * for DevelMain @@ -21,8 +22,6 @@ import Network.Wai.Handler.Warp (Settings, defaultSettings, defaultShouldDisplayException, runSettings, setHost, setOnException, setPort, getPort) -import Network.Wai.Handler.FastCGI (run) - import Network.Wai.Middleware.RequestLogger (Destination (Logger), IPAddrSource (..), OutputFormat (..), destination, @@ -149,7 +148,6 @@ develMain :: IO () develMain = develMainHelper getApplicationDev -- | The @main@ function for an executable running this site. -appMain :: IO () appMain = do -- Get the settings from all relevant sources settings <- loadAppSettingsArgs @@ -167,7 +165,27 @@ appMain = do -- Run the application with Warp -- runSettings (warpSettings foundation) app - run app + return app + +-- | The @main@ function for an executable running this site. +appSelfContainedMain :: IO () +appSelfContainedMain = do + -- Get the settings from all relevant sources + settings <- loadAppSettingsArgs + -- fall back to compile-time values, set to [] to require values at runtime + [configSettingsYmlValue] + + -- allow environment variables to override + useEnv + + -- Generate the foundation from the settings + foundation <- makeFoundation settings + + -- Generate a WAI Application from the foundation + app <- makeApplication foundation + + -- Run the application with Warp + runSettings (warpSettings foundation) app -------------------------------------------------------------- -- Functions for DevelMain.hs (a way to run the app from GHCi) diff --git a/app/main-bin.hs b/app/main-bin.hs new file mode 100644 index 0000000..a31b3d7 --- /dev/null +++ b/app/main-bin.hs @@ -0,0 +1,5 @@ +import Prelude (IO) +import Application (appSelfContainedMain) + +main :: IO () +main = appSelfContainedMain diff --git a/app/main.hs b/app/main.hs index 4ffa93d..a4896ed 100644 --- a/app/main.hs +++ b/app/main.hs @@ -1,5 +1,8 @@ import Prelude (IO) +import Network.Wai.Handler.FastCGI (run) import Application (appMain) main :: IO () -main = appMain +main = do + app <- appMain + run app diff --git a/gonito.cabal b/gonito.cabal index c6e3693..90aa0c6 100644 --- a/gonito.cabal +++ b/gonito.cabal @@ -126,7 +126,6 @@ library , yesod-table , regex-tdfa , optparse-applicative - , wai-handler-fastcgi , blaze-markup , blaze-html , conduit-extra @@ -145,10 +144,21 @@ executable gonito main-is: main.hs hs-source-dirs: app + build-depends: base, gonito, wai-handler-fastcgi + + ghc-options: -threaded -O2 -rtsopts -with-rtsopts=-N + +executable gonito-bin + if flag(library-only) + Buildable: False + + main-is: main-bin.hs + hs-source-dirs: app build-depends: base, gonito ghc-options: -threaded -O2 -rtsopts -with-rtsopts=-N + test-suite test type: exitcode-stdio-1.0 main-is: Spec.hs diff --git a/stack.yaml b/stack.yaml index 53de6f8..aaad00d 100644 --- a/stack.yaml +++ b/stack.yaml @@ -10,3 +10,9 @@ packages: extra-dep: true extra-deps: [../geval,wai-handler-fastcgi-3.0.0.2,murmur3-1.0.3] resolver: lts-11.9 +image: + container: + name: filipg/gonito + base: fpco/stack-run + add: + executables: /usr/local/bin/gonito-bin