On Dec 29, 9:51 pm, Andrew Myers <
asm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> Thanks for bearing with me Greg, I've got something that hosts the
> default hello page on Heroku now. I'm quite sure it's not at all
> kosher though :p Maybe you can give me some pointers on a sane way to
> do it.
>
> All the code changes were in Application.hs generated by the
> scaffolding.
> Created this function for making keys that the
> `Database.Persist.Base.loadConfig` expects. There's only one
> different from what `Web.Heroku.dbConnParams` does so it doesn't
> actually do much.
>
> canonicalizeKey :: Text -> Text
> canonicalizeKey "dbname" = "database"
> canonicalizeKey key = key
>
> I then modified withYesodHeroku as follows.
>
> withYesodHeroku :: AppConfig DefaultEnv () -> Logger -> (Application -> IO ()) -> IO ()
>
> withYesodHeroku conf logger f = do
> s <- staticSite
> -- This line is pretty heinous. It seems like I should somehow get
> the port and poolsize from the yaml
> -- configs and then combine that with the parameters from
> `Web.Heroku.dbConnParams`
> -- This takes the parameters from the DATABASE_URL and puts them in
> the form that `loadConfig`
> -- expects, adding port and poolsize.
> dbparams <- Web.Heroku.dbConnParams >>= return . DO.Mapping .
> ([("port", DO.Scalar "5432"), ("poolsize", DO.Scalar "10")] ++) . map
> (\(key, val) -> (canonicalizeKey key, DO.Scalar val))
> -- Create the Database.Persist.PersistConfig with loadConfig of
> dbparams
> let dbconf = either error id $ Database.Persist.Base.loadConfig
> dbparams
> -- These two lines are how the original config was loaded.
> -- dbconf <- withYamlEnvironment "config/postgresql.yml" (appEnv
> conf)
> -- $ either error return .
> Database.Persist.Base.loadConfig
> Database.Persist.Base.withPool (dbconf :: Settings.PersistConfig)
> $ \p -> do
> Database.Persist.Base.runPool dbconf (runMigration migrateAll)
> p
> let h = YesodHeroku conf logger s p
> defaultRunner (f . logWare) h
> where
> #ifdef DEVELOPMENT
> logWare = logHandleDev (\msg -> logBS logger msg >> flushLogger
> logger)
> #else
> logWare = logStdout
> #endif
>
> As I said, it's pretty grotesque :p, but it at least allows me to see
> a webpage on my heroku site. I'm going to look at withYamlEnvironment
> and see if I can combine the parameters from the database variable and
> the yaml configs. Do you have any suggestions? Am I at least on the
> right track or am I doing something crazy?
>
> Thanks again,
> Andrew
>
> On Dec 29, 8:05 pm, Greg Weber <
g...-6Rig8Yl2aw4Die4ONvY22w@public.gmane.org> wrote:
>
>
>
>
>
>
>
> > On Thu, Dec 29, 2011 at 3:02 PM, Andrew Myers <
asm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> > > Some pointers on the postgre setup might be helpful if you don't
> > > mind. Not knowing anything about Yesod beyond what I've read in the
> > > book I don't really understand the instructions in the Procfile.
>
> > > From the instructions (pasted below) I have the following questions:
>
> > > - Why do I have to parse the DATABASE_URL variable in main?
>
> > You need to parse it and then used it to make the database connection.
>
> > I can't find any references to 'withConnectionPool' or 'loadConnStr' except
>
> > > inside Yesod itself. In the Scaffold generated Settings.hs there's a
> > > reference to Database.Persist.Base.withPool inside 'withYesodHeroku',
> > > is this what I want to pass arguments to? Right now they're read from
> > > the "config/postgresql.yml" file which of course is wrong when
> > > deployed to heroku with a free shared db.
>
> > > - Where does the `dbConnParams _ = Web.Heroku.dbConnParams` bit of
> > > code from the ProcFile fit? I can't find any references to it
> > > anywhere so adding that code to Settings.hs doesn't do anything.
> > > Web.Heroku.dbConnParams parses the DATABASE_URL variable itself, how
> > > does this relate to the parsing that's supposed to be done in main?
>
> > > - Looking at The Database.Persist.Postgresql [1] package docs it looks
> > > like a PersistConf is just a url and a pool size for PostGres, should
> > > I just create one of these in `withYesodHeroku?
>
> > Oh, the Procfile instructions are now out of date with the new scaffolding
> > changes. We need to override how Yesod connects to the database so that it
> > uses the parsed DATABASE_URL. I am busy at the moment, but will get back to
> > you soon.
>
> > > Thanks again for the help Greg!
>
> > > [1]
> > >
http://hackage.haskell.org/packages/archive/persistent-postgresql/0.6...
>
> > > # Postgresql Yesod setup:
> > > #
> > > # * add code to read DATABASE_URL environment variable.
> > > #
> > > # import System.Environment
> > > # main = do
> > > # durl <- getEnv "DATABASE_URL"
> > > # # parse env variable
> > > # # pass settings to withConnectionPool instead of directly using
> > > loadConnStr
> > > #
> > > # * add a dependency on the "heroku" package in your cabal file
> > > #
> > > # * add code in Settings.hs to turn that url into connection
> > > parameters. The below works for Postgresql.
> > > #
> > > # #ifdef !DEVELOPMENT
> > > # import qualified Web.Heroku
> > > # #endif
> > > #
> > > # dbConnParams :: AppEnvironment -> IO [(Text, Text)]
> > > # #ifdef !DEVELOPMENT
> > > # dbConnParams _ = Web.Heroku.dbConnParams
> > > # #else
> > > # dbConnParams env = do
> > > # ...
>
> > > On Dec 29, 11:58 am, Greg Weber <
g...-6Rig8Yl2aw4Die4ONvY22w@public.gmane.org> wrote:
> > > > yes that looks correct. I just modified the scaffolding Procfile to
> > > include
> > > > the environment argument. There is detailed information in the Procfile
> > > for
> > > > setting up the heroku port. Let us know if anything else needs to be
> > > > changed.
>
> > > > On Thu, Dec 29, 2011 at 1:25 PM, Andrew Myers <
asm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> > > > > I see, I now have
> > > > > web: ./dist/build/yesod-heroku/yesod-heroku -p $PORT production
> > > > > in my Procfile. This seems to work (in as much as the application now
> > > > > starts, need to point it at the right postgres db now) is this the
> > > > > correct way to do this?
> > > > > Thanks Greg
>
> > > > > On Dec 29, 11:01 am, Greg Weber <
g...-6Rig8Yl2aw4Die4ONvY22w@public.gmane.org> wrote:
> > > > > > yesod devel is somewhat magical. You should be able to compile your
> > > > > > application and run it without it though. It is `cabal install
> > > -fdev`.
> > > > > Then
> > > > > > run the binary created in the dist folder and give an environment
> > > > > argument
> > > > > > of "development". for production compile with no flags and give an
> > > > > > environment argument of "production". This definitely needs to be
> > > > > > incorporated into the book now.
>
> > > > > > On Thu, Dec 29, 2011 at 12:43 PM, Andrew Myers <
asm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> > > wrote:
> > > > > > > Sorry if I'm being dense but could you clarify that or point me to
> > > > > > > some documentation? I've been looking for documentation on that
> > > and
> > > > > > > trying to figure out how `yesod devel` starts the application but
> > > it
> > > > > > > hasn't been very fruitful so far.
> > > > > > > Thanks,
> > > > > > > Andrew
>
> > > > > > > On Dec 28, 6:23 pm, Greg Weber <
g...-6Rig8Yl2aw4Die4ONvY22w@public.gmane.org> wrote:
> > > > > > > > Glad SO could help you out. We now require an environment
> > > argument
> > > > > for
> > > > > > > the
> > > > > > > > executable. I think the poor error message is a limitation of
> > > > > cmdargs.
>
> > > > > > > > On Wed, Dec 28, 2011 at 8:04 PM, Andrew Myers <
asm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> > > > > wrote:
> > > > > > > > > Thanks Greg,
>
> > > > > > > > > I posted on SO as suggested and someone helped me out.
> > > > > > > > > Turned out the problem was that by libc is newer than the libc
> > > on
> > > > > > > > > Heroku hosts (Archlinux is a rolling release distro). I
> > > solved the
> > > > > > > > > problem
> > > > > > > > > by creating an ubuntu virtual machine and building/deploying
> > > from
> > > > > > > > > there.
>
> > > > > > > > > The relevant answer is herehttp://
> > > > >
stackoverflow.com/a/8658468/166732
>
> > > > > > > > > Now I'm getting an error from the application processing
> > > arguments,
> > > > > > > > > not sure what it means or why yet.
>
> > > > > > > > > 2011-12-28T22:51:49+00:00 heroku[web.1]: Starting process with
> > > > > command
> > > > > > > > > `./dist/build/yesod-heroku/yesod-heroku -p 23748`
> > > > > > > > > 2011-12-28T22:51:49+00:00 app[web.1]: Requires at least 1
> > > > > arguments,
> > > > > > > > > got 0
>
> > > > > > > > > Has anyone seen that? I haven't figured out what code I'm
> > > > > supposed to
> > > > > > > > > modify from
> > > > > > > > > the directions in the Procfile yet. The indicated changes in
> > > > > > > > > Settings.hs don't seem
> > > > > > > > > to be relevant to what's actually there and I'm not sure what
> > > file
> > > > > the
> > > > > > > > > other code
> > > > > > > > > block is referencing. It could be that though.
>
> > > > > > > > > Thanks,
> > > > > > > > > Andrew
>
> > > > > > > > > On Dec 28, 6:11 am, Greg Weber <
g...-6Rig8Yl2aw4Die4ONvY22w@public.gmane.org> wrote:
> > > > > > > > > > Hi Andrew,
>
> > > > > > > > > > For my deployment I used a very simple application, and
> > > building
> > > > > with
> > > > > > > > > > -static just worked for me. I have definitely heard that it
> > > > > tends to
> > > > > > > be
> > > > > > > > > > much harder. I think you will be better off engaging the
> > > wider
> > > > > > > Haskell
> > > > > > > > > > community more experienced with static builds, perhaps by
> > > posting
> > > > > > > your
> > > > > > > > > > question to StackOverflow. Let us know how it turns out - we
> > > > > should
> > > > > > > be
> > > > > > > > > able
> > > > > > > > > > to point people to documentation on how to perform a static
> > > > > build.
>
> > > > > > > > > > Greg Weber
>
> > > > > > > > > > On Tue, Dec 27, 2011 at 11:21 PM, Andrew Myers <
> > >
asm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
>
> > > > > > > wrote:
> > > > > > > > > > > I'm very new to Yesod and I'm having trouble building Yesod
> > > > > > > statically
> > > > > > > > > > > so I can deploy to Heroku.
>
> > > > > > > > > > > I have changed the default .cabal file to reflect static
>