From a2563c8d05fff121c1ae6823ba969f81e53c4cdf Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Sun, 21 Sep 2014 10:42:53 +0300 Subject: [PATCH 1/2] yesod keter: support for new config file format --- yesod-bin/Keter.hs | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/yesod-bin/Keter.hs b/yesod-bin/Keter.hs index 7837ab4f..61b7d8cb 100644 --- a/yesod-bin/Keter.hs +++ b/yesod-bin/Keter.hs @@ -17,6 +17,8 @@ import qualified Codec.Archive.Tar as Tar import Control.Exception import qualified Data.ByteString.Lazy as L import Codec.Compression.GZip (compress) +import qualified Data.Foldable as Fold +import Control.Monad.Trans.Writer (tell, execWriter) run :: String -> [String] -> IO () run a b = do @@ -36,7 +38,12 @@ keter cabal noBuild = do case Map.lookup "host" value of Just (String s) | "<<" `T.isPrefixOf` s -> error $ "Please set your hostname in " ++ ketercfg - _ -> return value + _ -> + case Map.lookup "user-edited" value of + Just (Bool False) -> + error $ "Please edit your Keter config file at " + ++ ketercfg + _ -> return value Just _ -> error $ ketercfg ++ " is not an object" files <- getDirectoryContents "." @@ -46,10 +53,14 @@ keter cabal noBuild = do [] -> error "No cabal file found" _ -> error "Too many cabal files found" - exec <- - case Map.lookup "exec" value of - Just (String s) -> return $ F.collapse $ "config" F. F.fromText s - _ -> error $ "exec not found in " ++ ketercfg + let findExecs (Object v) = + mapM_ go $ Map.toList v + where + go ("exec", String s) = tell [F.collapse $ "config" F. F.fromText s] + go (_, v') = findExecs v' + findExecs (Array v) = Fold.mapM_ findExecs v + findExecs _ = return () + execs = execWriter $ findExecs $ Object value unless noBuild $ do run cabal ["clean"] @@ -58,7 +69,7 @@ keter cabal noBuild = do _ <- try' $ F.removeTree "static/tmp" - archive <- Tar.pack "" [F.encodeString exec, "config", "static"] + archive <- Tar.pack "" $ "config" : "static" : map F.encodeString execs let fp = T.unpack project ++ ".keter" L.writeFile fp $ compress $ Tar.write archive From eda8597039e8f0eafade753b5e5798b6402ec9cc Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Sun, 21 Sep 2014 10:56:22 +0300 Subject: [PATCH 2/2] Better keter.yml in scaffolding --- yesod-bin/hsfiles/mongo.hsfiles | 56 ++++++++++++++-- yesod-bin/hsfiles/mysql.hsfiles | 91 +++++++++++++++++--------- yesod-bin/hsfiles/postgres-fay.hsfiles | 65 ++++++++++++++++-- yesod-bin/hsfiles/postgres.hsfiles | 65 ++++++++++++++++-- yesod-bin/hsfiles/simple.hsfiles | 56 ++++++++++++++-- yesod-bin/hsfiles/sqlite.hsfiles | 56 ++++++++++++++-- 6 files changed, 339 insertions(+), 50 deletions(-) diff --git a/yesod-bin/hsfiles/mongo.hsfiles b/yesod-bin/hsfiles/mongo.hsfiles index 1ec3ae44..073ef1c8 100644 --- a/yesod-bin/hsfiles/mongo.hsfiles +++ b/yesod-bin/hsfiles/mongo.hsfiles @@ -705,15 +705,63 @@ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== {-# START_FILE config/keter.yml #-} -exec: ../dist/build/PROJECTNAME/PROJECTNAME -args: - - production -host: <> +# After you've edited this file, remove the following line to allow +# `yesod keter` to build your bundle. +user-edited: false + +# A Keter app is composed of 1 or more stanzas. The main stanza will define our +# web application. See the Keter documentation for more information on +# available stanzas. +stanzas: + + # Your Yesod application. + - type: webapp + + # Name of your executable. You are unlikely to need to change this. + # Note that all file paths are relative to the keter.yml file. + exec: ../dist/build/PROJECTNAME/PROJECTNAME + + # Command line options passed to your application. + args: + - production + + hosts: + # You can specify one or more hostnames for your application to respond + # to. The primary hostname will be used for generating your application + # root. + - www.PROJECTNAME.com + + # Static files. + - type: static-files + hosts: + - static.PROJECTNAME.com + root: ../static + + # Uncomment to turn on directory listings. + # directory-listing: true + + # Redirect plain domain name to www. + - type: redirect + + hosts: + - PROJECTNAME.com + actions: + - host: www.PROJECTNAME.com + # secure: false + # port: 80 + + # Uncomment to switch to a non-permanent redirect. + # status: 303 # Use the following to automatically copy your bundle upon creation via `yesod # keter`. Uses `scp` internally, so you can set it to a remote destination # copy-to: user@host:/opt/keter/incoming +# If you would like to have Keter automatically create a PostgreSQL database +# and set appropriate environment variables for it to be discovered, uncomment +# the following line. +# postgres: true + {-# START_FILE config/models #-} User ident Text diff --git a/yesod-bin/hsfiles/mysql.hsfiles b/yesod-bin/hsfiles/mysql.hsfiles index f3f0e37f..37b32749 100644 --- a/yesod-bin/hsfiles/mysql.hsfiles +++ b/yesod-bin/hsfiles/mysql.hsfiles @@ -711,15 +711,63 @@ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== {-# START_FILE config/keter.yml #-} -exec: ../dist/build/PROJECTNAME/PROJECTNAME -args: - - production -host: <> +# After you've edited this file, remove the following line to allow +# `yesod keter` to build your bundle. +user-edited: false + +# A Keter app is composed of 1 or more stanzas. The main stanza will define our +# web application. See the Keter documentation for more information on +# available stanzas. +stanzas: + + # Your Yesod application. + - type: webapp + + # Name of your executable. You are unlikely to need to change this. + # Note that all file paths are relative to the keter.yml file. + exec: ../dist/build/PROJECTNAME/PROJECTNAME + + # Command line options passed to your application. + args: + - production + + hosts: + # You can specify one or more hostnames for your application to respond + # to. The primary hostname will be used for generating your application + # root. + - www.PROJECTNAME.com + + # Static files. + - type: static-files + hosts: + - static.PROJECTNAME.com + root: ../static + + # Uncomment to turn on directory listings. + # directory-listing: true + + # Redirect plain domain name to www. + - type: redirect + + hosts: + - PROJECTNAME.com + actions: + - host: www.PROJECTNAME.com + # secure: false + # port: 80 + + # Uncomment to switch to a non-permanent redirect. + # status: 303 # Use the following to automatically copy your bundle upon creation via `yesod # keter`. Uses `scp` internally, so you can set it to a remote destination # copy-to: user@host:/opt/keter/incoming +# If you would like to have Keter automatically create a PostgreSQL database +# and set appropriate environment variables for it to be discovered, uncomment +# the following line. +# postgres: true + {-# START_FILE config/models #-} User ident Text @@ -735,6 +783,15 @@ Email -- By default this file is used in Model.hs (which is imported by Foundation.hs) {-# START_FILE config/mysql.yml #-} +# NOTE: These settings can be overridden by environment variables as well, in +# particular: +# +# MYSQL_HOST +# MYSQL_PORT +# MYSQL_USER +# MYSQL_PASSWORD +# MYSQL_DATABASE + Default: &defaults user: PROJECTNAME password: PROJECTNAME @@ -760,32 +817,6 @@ Production: poolsize: 100 <<: *defaults -{-# START_FILE config/postgresql.yml #-} -Default: &defaults - user: PROJECTNAME - password: PROJECTNAME - host: localhost - port: 5432 - database: PROJECTNAME - poolsize: 10 - -Development: - <<: *defaults - -Testing: - database: PROJECTNAME_test - <<: *defaults - -Staging: - database: PROJECTNAME_staging - poolsize: 100 - <<: *defaults - -Production: - database: PROJECTNAME_production - poolsize: 100 - <<: *defaults - {-# START_FILE config/robots.txt #-} User-agent: * diff --git a/yesod-bin/hsfiles/postgres-fay.hsfiles b/yesod-bin/hsfiles/postgres-fay.hsfiles index c0f3a608..22251e2f 100644 --- a/yesod-bin/hsfiles/postgres-fay.hsfiles +++ b/yesod-bin/hsfiles/postgres-fay.hsfiles @@ -760,15 +760,63 @@ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== {-# START_FILE config/keter.yml #-} -exec: ../dist/build/PROJECTNAME/PROJECTNAME -args: - - production -host: <> +# After you've edited this file, remove the following line to allow +# `yesod keter` to build your bundle. +user-edited: false + +# A Keter app is composed of 1 or more stanzas. The main stanza will define our +# web application. See the Keter documentation for more information on +# available stanzas. +stanzas: + + # Your Yesod application. + - type: webapp + + # Name of your executable. You are unlikely to need to change this. + # Note that all file paths are relative to the keter.yml file. + exec: ../dist/build/PROJECTNAME/PROJECTNAME + + # Command line options passed to your application. + args: + - production + + hosts: + # You can specify one or more hostnames for your application to respond + # to. The primary hostname will be used for generating your application + # root. + - www.PROJECTNAME.com + + # Static files. + - type: static-files + hosts: + - static.PROJECTNAME.com + root: ../static + + # Uncomment to turn on directory listings. + # directory-listing: true + + # Redirect plain domain name to www. + - type: redirect + + hosts: + - PROJECTNAME.com + actions: + - host: www.PROJECTNAME.com + # secure: false + # port: 80 + + # Uncomment to switch to a non-permanent redirect. + # status: 303 # Use the following to automatically copy your bundle upon creation via `yesod # keter`. Uses `scp` internally, so you can set it to a remote destination # copy-to: user@host:/opt/keter/incoming +# If you would like to have Keter automatically create a PostgreSQL database +# and set appropriate environment variables for it to be discovered, uncomment +# the following line. +# postgres: true + {-# START_FILE config/models #-} User ident Text @@ -784,6 +832,15 @@ Email -- By default this file is used in Model.hs (which is imported by Foundation.hs) {-# START_FILE config/postgresql.yml #-} +# NOTE: These settings can be overridden by environment variables as well, in +# particular: +# +# PGHOST +# PGPORT +# PGUSER +# PGPASS +# PGDATABASE + Default: &defaults user: PROJECTNAME password: PROJECTNAME diff --git a/yesod-bin/hsfiles/postgres.hsfiles b/yesod-bin/hsfiles/postgres.hsfiles index 0634535a..221ac810 100644 --- a/yesod-bin/hsfiles/postgres.hsfiles +++ b/yesod-bin/hsfiles/postgres.hsfiles @@ -711,15 +711,63 @@ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== {-# START_FILE config/keter.yml #-} -exec: ../dist/build/PROJECTNAME/PROJECTNAME -args: - - production -host: <> +# After you've edited this file, remove the following line to allow +# `yesod keter` to build your bundle. +user-edited: false + +# A Keter app is composed of 1 or more stanzas. The main stanza will define our +# web application. See the Keter documentation for more information on +# available stanzas. +stanzas: + + # Your Yesod application. + - type: webapp + + # Name of your executable. You are unlikely to need to change this. + # Note that all file paths are relative to the keter.yml file. + exec: ../dist/build/PROJECTNAME/PROJECTNAME + + # Command line options passed to your application. + args: + - production + + hosts: + # You can specify one or more hostnames for your application to respond + # to. The primary hostname will be used for generating your application + # root. + - www.PROJECTNAME.com + + # Static files. + - type: static-files + hosts: + - static.PROJECTNAME.com + root: ../static + + # Uncomment to turn on directory listings. + # directory-listing: true + + # Redirect plain domain name to www. + - type: redirect + + hosts: + - PROJECTNAME.com + actions: + - host: www.PROJECTNAME.com + # secure: false + # port: 80 + + # Uncomment to switch to a non-permanent redirect. + # status: 303 # Use the following to automatically copy your bundle upon creation via `yesod # keter`. Uses `scp` internally, so you can set it to a remote destination # copy-to: user@host:/opt/keter/incoming +# If you would like to have Keter automatically create a PostgreSQL database +# and set appropriate environment variables for it to be discovered, uncomment +# the following line. +# postgres: true + {-# START_FILE config/models #-} User ident Text @@ -735,6 +783,15 @@ Email -- By default this file is used in Model.hs (which is imported by Foundation.hs) {-# START_FILE config/postgresql.yml #-} +# NOTE: These settings can be overridden by environment variables as well, in +# particular: +# +# PGHOST +# PGPORT +# PGUSER +# PGPASS +# PGDATABASE + Default: &defaults user: PROJECTNAME password: PROJECTNAME diff --git a/yesod-bin/hsfiles/simple.hsfiles b/yesod-bin/hsfiles/simple.hsfiles index ec1ccb2a..59ecdaba 100644 --- a/yesod-bin/hsfiles/simple.hsfiles +++ b/yesod-bin/hsfiles/simple.hsfiles @@ -626,15 +626,63 @@ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== {-# START_FILE config/keter.yml #-} -exec: ../dist/build/PROJECTNAME/PROJECTNAME -args: - - production -host: <> +# After you've edited this file, remove the following line to allow +# `yesod keter` to build your bundle. +user-edited: false + +# A Keter app is composed of 1 or more stanzas. The main stanza will define our +# web application. See the Keter documentation for more information on +# available stanzas. +stanzas: + + # Your Yesod application. + - type: webapp + + # Name of your executable. You are unlikely to need to change this. + # Note that all file paths are relative to the keter.yml file. + exec: ../dist/build/PROJECTNAME/PROJECTNAME + + # Command line options passed to your application. + args: + - production + + hosts: + # You can specify one or more hostnames for your application to respond + # to. The primary hostname will be used for generating your application + # root. + - www.PROJECTNAME.com + + # Static files. + - type: static-files + hosts: + - static.PROJECTNAME.com + root: ../static + + # Uncomment to turn on directory listings. + # directory-listing: true + + # Redirect plain domain name to www. + - type: redirect + + hosts: + - PROJECTNAME.com + actions: + - host: www.PROJECTNAME.com + # secure: false + # port: 80 + + # Uncomment to switch to a non-permanent redirect. + # status: 303 # Use the following to automatically copy your bundle upon creation via `yesod # keter`. Uses `scp` internally, so you can set it to a remote destination # copy-to: user@host:/opt/keter/incoming +# If you would like to have Keter automatically create a PostgreSQL database +# and set appropriate environment variables for it to be discovered, uncomment +# the following line. +# postgres: true + {-# START_FILE config/robots.txt #-} User-agent: * diff --git a/yesod-bin/hsfiles/sqlite.hsfiles b/yesod-bin/hsfiles/sqlite.hsfiles index 0d3772b6..11017119 100644 --- a/yesod-bin/hsfiles/sqlite.hsfiles +++ b/yesod-bin/hsfiles/sqlite.hsfiles @@ -711,15 +711,63 @@ AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA== {-# START_FILE config/keter.yml #-} -exec: ../dist/build/PROJECTNAME/PROJECTNAME -args: - - production -host: <> +# After you've edited this file, remove the following line to allow +# `yesod keter` to build your bundle. +user-edited: false + +# A Keter app is composed of 1 or more stanzas. The main stanza will define our +# web application. See the Keter documentation for more information on +# available stanzas. +stanzas: + + # Your Yesod application. + - type: webapp + + # Name of your executable. You are unlikely to need to change this. + # Note that all file paths are relative to the keter.yml file. + exec: ../dist/build/PROJECTNAME/PROJECTNAME + + # Command line options passed to your application. + args: + - production + + hosts: + # You can specify one or more hostnames for your application to respond + # to. The primary hostname will be used for generating your application + # root. + - www.PROJECTNAME.com + + # Static files. + - type: static-files + hosts: + - static.PROJECTNAME.com + root: ../static + + # Uncomment to turn on directory listings. + # directory-listing: true + + # Redirect plain domain name to www. + - type: redirect + + hosts: + - PROJECTNAME.com + actions: + - host: www.PROJECTNAME.com + # secure: false + # port: 80 + + # Uncomment to switch to a non-permanent redirect. + # status: 303 # Use the following to automatically copy your bundle upon creation via `yesod # keter`. Uses `scp` internally, so you can set it to a remote destination # copy-to: user@host:/opt/keter/incoming +# If you would like to have Keter automatically create a PostgreSQL database +# and set appropriate environment variables for it to be discovered, uncomment +# the following line. +# postgres: true + {-# START_FILE config/models #-} User ident Text