Railways is not injecting env vars at runtime into my ktor application
nickbeginner
HOBBYOP

a year ago

Hello i'm building and deploying this docker file:

# ---- Build Stage ---- FROM eclipse-temurin:21-jdk AS build WORKDIR /app COPY . . RUN ./gradlew clean shadowJar # ---- Run Stage ---- FROM eclipse-temurin:21-jre WORKDIR /app COPY --from=build /app/build/libs/displate-mail.jar app.jar RUN useradd ktoruser USER ktoruser EXPOSE 8080 ENTRYPOINT ["java", "-jar", "app.jar"]

but the deploy keep failing this this error

at io.ktor.server.engine.CommandLineKt.commandLineEnvironment(CommandLine.kt:98)

Jun 22 17:32:39

at io.ktor.server.netty.EngineMain.main(EngineMain.kt:20)

Jun 22 17:32:39

Exception in thread "main" java.util.NoSuchElementException: Char sequence is empty.

Jun 22 17:32:39

at kotlin.text.StringsKt___StringsKt.first(_Strings.kt:76)

Jun 22 17:32:39

at io.ktor.server.config.yaml.YamlConfigKt.resolveValue(YamlConfig.kt:173)

Jun 22 17:32:39

at io.ktor.server.config.yaml.YamlConfigKt.access$resolveValue(YamlConfig.kt:1)

Jun 22 17:32:39

at io.ktor.server.config.yaml.YamlConfig.checkEnvironmentVariables$check(YamlConfig.kt:132)

Jun 22 17:32:39

at io.ktor.server.config.yaml.YamlConfig.checkEnvironmentVariables$check(YamlConfig.kt:134)

Jun 22 17:32:39

at io.ktor.server.config.yaml.YamlConfig.checkEnvironmentVariables$check(YamlConfig.kt:134)

Jun 22 17:32:39

at io.ktor.server.config.yaml.YamlConfig.checkEnvironmentVariables$check(YamlConfig.kt:134)

Jun 22 17:32:39

at io.ktor.server.config.yaml.YamlConfig.checkEnvironmentVariables(YamlConfig.kt:139)

Jun 22 17:32:39

at io.ktor.server.config.yaml.YamlConfigJvmKt.configFromString(YamlConfigJvm.kt:39)

Jun 22 17:32:39

seems that env vars are not injected

Solved

5 Replies

nickbeginner
HOBBYOP

a year ago

If i hardcode values, for example like this (with dummies values)

ktor: deployment: port: 8080 development: true auth: apiKey: internal: "S2Levonh3AWRYdPkQiNwLsF2YYTSHJVJNEnxW5GMuJCyTe42j9LyDuau3R5vcpZyCzCwuv" providers: mailgun: user: "admin" apiKey: "S2Levonh3AWRYdPkQiNwLsF2YYTSHJVJNEnxW5GMuJCyTe42j9LyDuau3R5vcpZyCzCwuv" endpoint: "https://default.mailgun.endpoint" the service is deployed withous issues


nickbeginner
HOBBYOP

a year ago

i need an answer since we are deciding if we want to host our infrastructure on railways since we have a lot of microservices written using ktor


nickbeginner
HOBBYOP

a year ago

could the issue be related to this

https://docs.railway.com/guides/start-command

?


nickbeginner
HOBBYOP

a year ago

solved, for reference, if you declare env variables without using {}, everything working fine:

ktor: deployment: port: $PORT development: $IS_DEV auth: apiKey: internal: $AUTH_API_KEY_INTERNAL providers: mailgun: user: $MAILGUN_USER apiKey: $MAILGUN_API_KEY endpoint: $MAILGUN_ENDPOINT

thanks anyways!


a year ago

I am glad you have solved the issue, I'll mark this thread as solved.


Status changed to Solved uxuz 11 months ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...