Starts in:
1 DAY
12 HRS
57 MIN
40 SEC
Starts in:
1 D
12 H
57 M
40 S
Open Closed

Something is missing to be able to run EF migration to Azure PostgreSQL from within a docker in Github Actions #5492


User avatar
0
Sturla created

The details of my issue are listed up in this StackOverflow question (please don´t make me repeat it here)

But basically get this error

Npgsql.PostgresException (0x80004005): 28P01: password authentication failed for user "***"

But if I create a clean EF core project (no abp.io) I´m able to connect to the server and apply migrations using my user/pass that doesn´t work with the abp.io migrator. This here is the code that is working from within a docker

So what do I need to do or add to make this work?

  • ABP Framework version: v7.2.2
  • UI Type: Blazor Server
  • Database System: EF Core (PostgreSQL

7 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You can configure the ConnectionStrings of AbpDbConnectionOptions.

  • User Avatar
    0
    Sturla created

    Hi maliming sorry I don´t understand what you are referring to?

    I am able to get the connection string into my docker image and it is able to try to connect to the server (if I put e.g. a wrong server it reports that there is no such server etc.)

    And from the AbpDbConnectionOptions code and its documentation I can´t see anything that could help me there.

    But there is something in the abp.io framework interfering in the connection but what and why?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    If you are using the MyProjectName.DbMigrator you need to put your connection string to appsettings.json.

    https://github.com/abpframework/abp/blob/dev/templates/app/aspnet-core/src/MyCompanyName.MyProjectName.DbMigrator/appsettings.json#L3

    If you already did that, you can write some logs when running the DbMigrator.

    eg: print current connection string.

    please share it if you have custom the code of DbMigrator

    Thanks

  • User Avatar
    0
    Sturla created

    Ok that worked BUTI don´t want to have the database password hardcoded in the docker file/source control. That is not a a future solution!

    I would think that the environment variable should take precedence over the appsettings.json file, correct? It seems like its getting part of the connection string at least since it tries to connect to the server (so it has read that part of the env connection string) but has problem with the password... I don´t get this..

    And I don´t have any custom code at all in my DbMigrator.

    So what do you recommend I do here?

  • User Avatar
    0
    Sturla created

    I managed to make this work but only by using Environment.GetEnvironmentVariable("ConnectionStrings:Default")

    I tried to add AddEnvironmentVariables() to CreateHostBuilder but that didn´t take.

    So here is what I had to do.

    docker run --rm \
    -e ConnectionStrings:Default="$connection_string" \
    ${{ env.DEV_AZURE_CONTAINER_REGISTRY }}/dbmigrator:${{ github.sha }}
    

    and the StartAsync()

    public async Task StartAsync(CancellationToken cancellationToken)
    {
            var envConnectionString = Environment.GetEnvironmentVariable("ConnectionStrings:Default");    
            if (!string.IsNullOrEmpty(envConnectionString))
            {
                _configuration["ConnectionStrings:Default"] = envConnectionString;
                Log.Logger.Information("Using ConnectionStrings:Default from environmental variable");
            }
            
            .... rest of the code..
        }
    }
    

    There was also one other issue and that is I was using a $ in my password and that doesn´t work because the docker run command is running in Linux using bash and then the $ is handled as a variable and it (and following letters) are skipped!

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    So this is a question of how to set and get environment variables. Thanks.

  • User Avatar
    0
    Sturla created

    Yes that´s correct. I chose probably the only symbol that didn´t work.

    But it would be great to know how to enable the env´s and I would even go so far to say that they should be enabled by default...

Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06