Automation container with Posgres service (dotnet)
Hello,
I rode your documentation http:// https://www.jetbrains.com/help/space/automation.html. Then I successfully created one where it has build and test my dotnet code.
However some of my tests required an PostgreSQL database. I tried to add a service but I didn't succeed :/ ...
I don't know if the problem come from the service declaration, some missing configuration or from my source code.
Below it's my .space.kts
job("Test") {
container(image = "mcr.microsoft.com/dotnet/sdk:6.0") {
service("postgres:14.2") {
alias("db")
env["POSTGRES_USER"] = Secrets("postgres_user")
env["POSTGRES_PASSWORD"] = Secrets("postgres_password")
env["POSTGRES_PORT"] = "888"
env["POSTGRES_DB"] = Secrets("postgres_database")
}
shellScript {
content = """
echo Run build...
dotnet build ./ServerSrc/
echo Run tests...
dotnet test ./ServerTest/
"""
}
}
}
Then below it's my dotnet code to connect to the PostgreSQL database using the Dotnet Entity Framework.
.UseNpgsql($@"Server={AppSettings.DatabaseHost};Port=888;Username={AppSettings.DatabaseUsername};Password={AppSettings.DatabasePassword};Database={AppSettings.DatabaseName};IncludeErrorDetails=true;")
When the job is running it got this error
----- Inner Stack Trace #1 (Npgsql.NpgsqlException) -----
at Npgsql.Internal.NpgsqlConnector.Connect(NpgsqlTimeout timeout)
[...]
Error Message:
System.AggregateException : One or more errors occurred. (Failed to connect to [::1]:888)
---- Npgsql.NpgsqlException : Failed to connect to [::1]:888
-------- System.Net.Internals.SocketExceptionFactory+ExtendedSocketException : Cannot assign requested address [::1]:888
I don't know if anyone could help.
Anyway I will updated this post If I found a solution.
Please sign in to leave a comment.
Spectral, could you please let me know which value do you pass in the following parameter:
Server={AppSettings.DatabaseHost}
Please note that it should either be postgres or db in your example. Apart from this, I noticed that the *Host* parameter is stated in the documentation, could it be the case?
https://www.npgsql.org/doc/connection-string-parameters.html#basic-connection
Looking forward to hearing from you soon!
I removed the followings line and everything worked
I had to remove the port in the connection string too
Server={AppSettings.DatabaseHost} was equals to localhost. I tried with "db" it worked.
Thanks for your time it helped me.