Documentation section of deploying to heroku <http...
# ktor
n
Documentation section of deploying to heroku https://ktor.io/servers/deploy.html#heroku does not say anything about modifying build.gradle to add this line of code
task stage(dependsOn: ['shadowJar'])
Newbie user can stuck with it a little bit) more info here: https://devcenter.heroku.com/articles/deploying-gradle-apps-on-heroku#verify-that-your-build-file-is-set-up-correctly
📝 1
@Deactivated User , Hello. Will be this doc editing note applied?
d
It seems that I missed this. Thanks for noticing!
👍 1
I am reviewing this. I can’t see why
stage
task is needed. If you are providing the binaries and you are specifying a
Procfile
already that just runs that jar. In fact, I did the tutorial without it and it worked. Have you followed the tutorial step by step?
n
From this link : https://devcenter.heroku.com/articles/deploying-gradle-apps-on-heroku#verify-that-your-build-file-is-set-up-correctly The Gradle buildpack will run different build tasks depending on the frameworks it detects in your app. For Spring Boot, it will run ./gradlew build -x test. For Ratpack, it will run ./gradlew installDist -x test. If no known web frameworks are detected, it will run ./gradlew stage.
If you are providing the binaries
No, I do not provide binaries. Binaries excluded in .gitignore and heroku compile fatjar by himself. And it compile it by calling stage gradle task. This task depends on shadowJar. And shadowJar produce fatJar that will be runned by command specified in Procfile
Copy code
remote: -----> Gradle app detected
remote: -----> Installing JDK 1.8... done
remote: -----> Building Gradle app...
remote: -----> executing ./gradlew stage
remote:        :compileKotlin
remote:        :compileJava NO-SOURCE
remote:        :processResources
remote:        :classes
remote:        :shadowJar
remote:        :stage
remote:        
remote:        BUILD SUCCESSFUL in 22s
remote:        3 actionable tasks: 3 executed
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote: 
remote: -----> Compressing...
remote:        Done: 59.3M
remote: -----> Launching...
remote:        Released v5
remote:        <https://afternoon-sierra-23732.herokuapp.com/> deployed to Heroku
remote: 
remote: Verifying deploy... done.
To <https://git.heroku.com/afternoon-sierra-23732.git>
   ffff2df..878d4d0  master -> master
d
I’m going to add a new sample for heroku here: https://github.com/ktorio/ktor-samples/tree/master/deployment Also I will try to follow the steps described in https://ktor.io/servers/deploy.html#heroku to see if I can reproduce the problem you have.
n
sources for project where I have problem is here https://github.com/nailgilaziev/wsUpper this sources uploaded to heroku with command
git push heroku master
after this command console output tail is:
Copy code
BUILD SUCCESSFUL in 27s
remote:        3 actionable tasks: 3 executed
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote: 
remote: -----> Compressing...
remote:        Done: 59.3M
remote: -----> Launching...
remote:        Released v6
remote:        <https://afternoon-sierra-23732.herokuapp.com/> deployed to Heroku
remote: 
remote: Verifying deploy... done.
But this url doesn't return text - It's alive from ktor.
port in application.conf changed to 80. port 8080 behave the same.
yeah, finally I found where I can see logs in herocu. ) here are the logs:
Copy code
2018-05-03T10:13:46.914241+00:00 heroku[router]: at=error code=H20 desc="App boot timeout" method=GET path="/" host=<http://afternoon-sierra-23732.herokuapp.com|afternoon-sierra-23732.herokuapp.com> request_id=72205859-48b7-4cef-a2ea-cf7d8a7c191c fwd="37.139.13.226" dyno= connect= service= status=503 bytes= protocol=https
2018-05-03T10:14:26.810037+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 90 seconds of launch
2018-05-03T10:14:26.810118+00:00 heroku[web.1]: Stopping process with SIGKILL
2018-05-03T10:14:26.881145+00:00 heroku[web.1]: Process exited with status 137
2018-05-03T10:14:27.070536+00:00 heroku[web.1]: State changed from starting to crashed
2018-05-03T10:18:40.696127+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=<http://afternoon-sierra-23732.herokuapp.com|afternoon-sierra-23732.herokuapp.com> request_id=ba58ad5a-20d0-4254-863b-bbc7967303b8 fwd="37.139.13.226" dyno= connect= service= status=503 bytes= protocol=https
2018-05-03T10:18:41.169479+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=<http://afternoon-sierra-23732.herokuapp.com|afternoon-sierra-23732.herokuapp.com> request_id=2cadd1be-54fb-4612-9f52-d3ee752a5fe0 fwd="37.139.13.226" dyno= connect= service= status=503 bytes= protocol=https
2018-05-03T10:18:42.093798+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=<http://afternoon-sierra-23732.herokuapp.com|afternoon-sierra-23732.herokuapp.com> request_id=fdf4bd5e-57c3-4fe5-920b-949e372ad049 fwd="37.139.13.226" dyno= connect= service= status=503 bytes= protocol=https
2018-05-03T10:18:42.213904+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=<http://afternoon-sierra-23732.herokuapp.com|afternoon-sierra-23732.herokuapp.com> request_id=dc39b497-63ed-475d-8c77-76343be9e141 fwd="37.139.13.226" dyno= connect= service= status=503 bytes= protocol=https
2018-05-03T10:18:42.921045+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=<http://afternoon-sierra-23732.herokuapp.com|afternoon-sierra-23732.herokuapp.com> request_id=63228b88-d17d-4bd0-8c59-2775385c0aee fwd="37.139.13.226" dyno= connect= service= status=503 bytes= protocol=https
d
you are forcing a specific PORT
but heroku provides the port using the PORT environment variable right?
have you tried port = $PORT?
n
How can you see I'm new to heroku. Give me a moment, I read a docs abouut PORT env var and trying to redeploy
d
https://ktor.io/servers/deploy.html#running-locally And a file called .env along the other files with (just required for development). This will contain environment variables that Heroku will pass to the application. For example, for the quickstart:
Still. I will recheck the heroku tutorial to make it clearer
and will make a pre-baked sample
in the samples repo
In that page there is a link to a sample that you can deploy and use as quick start: “There is a quickstart repository for Heroku: https://github.com/orangy/ktor-heroku-start
as you can see in this sample, it doesn’t specify a specific port, but get it from the PORT env: https://github.com/orangy/ktor-heroku-start/blob/master/src/main/kotlin/org/jetbrains/ktor/heroku/Main.kt#L83
n
yes I see
Copy code
val port = Integer.valueOf(System.getenv("PORT"))
embeddedServer(Netty, port, reloadPackages = listOf("heroku"), module = Application::module).start()
But how to configure it with HOCON application.conf because this file is not valid
Copy code
ktor {
  deployment {
    port = $PORT
  }

  application {
    modules = [ru.gs.tests.wsupper.AppKt.main]
  }
}
And after deploying you get this error
Copy code
Exception in thread "main" com.typesafe.config.ConfigException$Parse: application.conf @ jar:file:/app/build/libs/wsupper-0.1-all.jar!/application.conf: 3: Expecting a value but got wrong token: 'P' ('$' not followed by {, 'P' not allowed after '$') (if you intended 'P' ('$' not followed by {, 'P' not allowed after '$') to be part of a key or string value, try enclosing the key or value in double quotes, or you may be able to rename the file .properties rather than .conf)
d
Sorry my fault
${PORT}
n
Yeah, it's alive now! Thanks for help, this is very valuable to me! So, now we know, that documantation section must contain this line of code snippet:
Copy code
ktor {
  deployment {
    port = ${PORT}
  }
}
d
🙂🎉
actually I used the ktor-heroku-start that didn’t use the application.conf
but I agree that it is not clear, so I’m going to rework it
👍 1