1

I want to deploy my grails app to heroku.

I have created a stack and am now at the stage where I want to push it: git push heroku master

However, I receive that:

       Done precompiling AST Transformations!
       | Compiling 3 source files
       | Compiling 3 source files.
       | Compiling 3 source files..
       | Compiling 3 source files...
       | Compiling 3 source files....
       | Compiling 3 source files.....
-----> Executing ./grailsw -plain-output -Divy.default.ivy.user.dir=/app/tmp/cac
he war --non-interactive
       |Loading Grails 2.3.4
       |Configuring classpath
       .
       |Environment set to production
       .................................
       |Packaging Grails application
       Precompiling AST Transformations ...
       src /tmp/build_f6c7df12-acc1-407e-84b0-95928c52c3ff/target/work/plugins/p
ostgresql-extensions-0.6.1 /tmp/build_f6c7df12-acc1-407e-84b0-95928c52c3ff/targe
t/classes
       Done precompiling AST Transformations!
       ..
       |Compiling 3 source files
       ..................Error
       |
       Error packaging application: Error loading DataSource.groovy: 1 (Use --st
acktrace to see the full trace)
 !     Failed to build app

 !     Push rejected, failed to compile Grails app

To git@heroku.com:quiet-coast-2715.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@heroku.com:quiet-coast-2715.git'

I thought that my datasource is broken, so I thats my DataSource.groovy:

dataSource {
    pooled = true
    driverClassName = "org.postgresql.Driver"
    dialect = org.hibernate.dialect.PostgreSQLDialect
    username = "admin"
    password = "******"
}

hibernate {
    cache.use_second_level_cache = true
    cache.use_query_cache = false
    cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory' // Hibernate 3
    //    cache.region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory' // Hibernate 4
}

// environment specific settings
environments {

//...

    production {
        dataSource {
            dbCreate = "update"
            driverClassName = "org.postgresql.Driver"
            dialect = org.hibernate.dialect.PostgreSQLDialect

            uri = new URI(System.env.DATABASE_URL?:"postgres://myHerokuUsername:myPassoword@5432/TestDB")

            url = "jdbc:postgresql://"+uri.host+uri.path
            username = uri.userInfo.split(":")[0]
            password = uri.userInfo.split(":")[1]
        }
    }
}

Furthermore, I have also added to my BuildConfig.groovy:

runtime postgresql:postgresql:8.4-702.jdbc3'

I do not see what I have done wrong in my datasource?

I appreciate your answer!

PS.: Any recommendations how to get the full stacktrace in git?

saw303
  • 8,051
  • 7
  • 50
  • 90
Carol.Kar
  • 4,581
  • 36
  • 131
  • 264
  • What is your `myHerokuUsername` in the `uri`? – MKB May 18 '14 at 07:39
  • I just followed this tutorial: https://devcenter.heroku.com/articles/getting-started-with-grails#set-up-the-database – Carol.Kar May 18 '14 at 07:55
  • 1
    I have tried with your mentioned tutorial and it is working for me with `postgres://myHerokuUsername:myPassoword@5432/TestDB`. I have not change anything in this i.e, not replace myHerokuUsername and myPassword. When I enter my email address in place of `myHerokuUsername` then it given me `null` in `host`. That`s why I want to know what you have in place of `myHerokuUsername`? – MKB May 18 '14 at 08:19
  • Thx. I have just used my heroku email address as username and my login passoword. For the Port I have used: 5432 and the db name is the same as in `DataSource.groovy`... – Carol.Kar May 18 '14 at 08:49

1 Answers1

2

The URI Class take [user-info@]host[:port] syntax and you are providing your email address which itself have a @ symbol that's why uri.host and uri.userInfo is null and your build fails.

Try to print uri.host and uri.userInfo and you can see these are null. Add following code in your data source

dataSource {
  ...
  uri = new URI(System.env.DATABASE_URL ?: "postgres://test@gmail.com:pass@5432/TestDB")
  println "---1---${uri}---${uri.host}---${uri.path}---${uri.userInfo}---"
  url = "jdbc:postgresql://" + uri.host + uri.path
  ...
}

To resolve the issue just take any string that does not contain @ symbol for your username and password. I have taken test as username and pass as password. like:

uri = new URI(System.env.DATABASE_URL ?: "postgres://test:pass@5432/TestDB")

and it works.

MKB
  • 7,587
  • 9
  • 45
  • 71