towards docker container

This commit is contained in:
Filip Gralinski 2018-06-01 07:48:04 +02:00
parent 0662522a44
commit f771b04f69
5 changed files with 48 additions and 6 deletions

View File

@ -2,6 +2,7 @@
module Application module Application
( getApplicationDev ( getApplicationDev
, appMain , appMain
, appSelfContainedMain
, develMain , develMain
, makeFoundation , makeFoundation
-- * for DevelMain -- * for DevelMain
@ -21,8 +22,6 @@ import Network.Wai.Handler.Warp (Settings, defaultSettings,
defaultShouldDisplayException, defaultShouldDisplayException,
runSettings, setHost, runSettings, setHost,
setOnException, setPort, getPort) setOnException, setPort, getPort)
import Network.Wai.Handler.FastCGI (run)
import Network.Wai.Middleware.RequestLogger (Destination (Logger), import Network.Wai.Middleware.RequestLogger (Destination (Logger),
IPAddrSource (..), IPAddrSource (..),
OutputFormat (..), destination, OutputFormat (..), destination,
@ -149,7 +148,6 @@ develMain :: IO ()
develMain = develMainHelper getApplicationDev develMain = develMainHelper getApplicationDev
-- | The @main@ function for an executable running this site. -- | The @main@ function for an executable running this site.
appMain :: IO ()
appMain = do appMain = do
-- Get the settings from all relevant sources -- Get the settings from all relevant sources
settings <- loadAppSettingsArgs settings <- loadAppSettingsArgs
@ -167,7 +165,27 @@ appMain = do
-- Run the application with Warp -- Run the application with Warp
-- runSettings (warpSettings foundation) app -- 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) -- Functions for DevelMain.hs (a way to run the app from GHCi)

5
app/main-bin.hs Normal file
View File

@ -0,0 +1,5 @@
import Prelude (IO)
import Application (appSelfContainedMain)
main :: IO ()
main = appSelfContainedMain

View File

@ -1,5 +1,8 @@
import Prelude (IO) import Prelude (IO)
import Network.Wai.Handler.FastCGI (run)
import Application (appMain) import Application (appMain)
main :: IO () main :: IO ()
main = appMain main = do
app <- appMain
run app

View File

@ -126,7 +126,6 @@ library
, yesod-table , yesod-table
, regex-tdfa , regex-tdfa
, optparse-applicative , optparse-applicative
, wai-handler-fastcgi
, blaze-markup , blaze-markup
, blaze-html , blaze-html
, conduit-extra , conduit-extra
@ -145,10 +144,21 @@ executable gonito
main-is: main.hs main-is: main.hs
hs-source-dirs: app 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 build-depends: base, gonito
ghc-options: -threaded -O2 -rtsopts -with-rtsopts=-N ghc-options: -threaded -O2 -rtsopts -with-rtsopts=-N
test-suite test test-suite test
type: exitcode-stdio-1.0 type: exitcode-stdio-1.0
main-is: Spec.hs main-is: Spec.hs

View File

@ -10,3 +10,9 @@ packages:
extra-dep: true extra-dep: true
extra-deps: [../geval,wai-handler-fastcgi-3.0.0.2,murmur3-1.0.3] extra-deps: [../geval,wai-handler-fastcgi-3.0.0.2,murmur3-1.0.3]
resolver: lts-11.9 resolver: lts-11.9
image:
container:
name: filipg/gonito
base: fpco/stack-run
add:
executables: /usr/local/bin/gonito-bin