从Github Actions运行从docker镜像到PostgreSQL服务器的EF迁移时出现问题

92vpleto  于 2023-08-03  发布在  Docker
关注(0)|答案(1)|浏览(117)

我想做什么#

将EF Core C#数据库迁移(创建/更新数据库/表)从Github操作中CI/CD yml中的Docker映像(在PR创建)应用到Azure PostgreSQL Flexible Server。

问题

我已经得到了到目前为止,能够看到postgresSQL服务器,但当试图连接我m得到以下错误

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

  Exception data:
    Severity: FATAL
    SqlState: 28P01
    MessageText: password authentication failed for user "***"
    File: auth.c
    Line: 418
    Routine: auth_failed

字符串
在GitHub Actions中运行以下代码时

deploy-development:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Login to Azure
    uses: azure/login@v1
    with:
    creds: ${{ secrets.DEV_AZURE_CREDENTIALS }}

- name: Login to ACR (Development)
    run: az acr login --name myAzureContainerRegistry

- name: Run Migrations (Development)
    run: |

    #1.  Get the image that I have already built in previous step.
    docker pull myAzureContainerRegistry/dbmigrator:${{ github.sha }}
        
    #2. Create a connection string to pass into the migration container 
    #    so it can run it against Azure PostgreSQL server.

    connection_string="Server=myPostgreSQLServer.postgres.database.azure.com;
    Database=dbToBeCreatedByMigration;Port=5432;
    User Id=MyAdminUser;Password=LegalWorkingPassWord;Ssl Mode=Require;
    Trust Server Certificate=true;"

    #3. Run the migrations. This is where the error accurse 
    docker run --rm \
    -e ConnectionStrings:Default="$connection_string" \
    myAzureContainerRegistry/dbmigrator:${{ github.sha }}


类似于connection_string="Host=${{ env.DEV_POSTGRESQL_SERVER_NAME }}.postgres.database.azure.com;Username=${{ env.DEV_POSTGRESQL_ADMIN_LOGIN }};Password=${{ env.DEV_POSTGRESQL_ADMIN_PASSWORD }};Database=${{ env.DEV_POSTGRESQL_DATABASE_NAME }};Ssl Mode=Require;Trust Server Certificate=true;"的连接字符串格式也不起作用。
我已经验证了并确保

**1.用户ID和密码正确。我更改了它们,并在管道中硬编码,还设法从我的本地计算机使用相同的密码使用此psql命令连接到服务器。

psql "--host=myPostgreSQLServer.postgres.database.azure.com" "--port=5432" "--dbname=postgres" "--username=MyAdminUser" "--set=sslmode=require"

**2.**灵活的postgresql服务器具有所有所需的GitHub Actions Ip´s设置作为防火墙规则。GitHub操作无法连接,直到我添加了这个

这些是ips '192.30.252.0','185.199.108.0', '140.82.112.0', '143.55.64.0', '20.201.28.148', '20.205.243.168', '20.87.225.211', '20.248.137.49', '20.207.73.85', '20.27.177.116', '20.200.245.245','20.233.54.49'

**3.**灵活的postgresql服务器具有以下设置

  • 已启用SSL/TLS
  • 连接方法为公共访问(允许的IP地址)
  • 防火墙规则将其打开到GitHub操作
    4.Azure日志包含任何更多信息(它们不包含),并使用以下查询
let start_time = datetime("2023-07-28T07:42:08Z");
let end_time = datetime("2023-07-28T07:42:30Z");
AzureDiagnostics
| where TimeGenerated >= start_time and TimeGenerated <= end_time
| where Category == "PostgreSQLLogs"
//| where Message contains "FATAL:  password authentication failed for user"
| project TimeGenerated, Message

**5.**Docker文件中有任何有趣的事情发生。它基本上是这样的

FROM mcr.microsoft.com/dotnet/runtime:7.0 AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
COPY ["myProject/aNuGet.Config", "."]
COPY ["myProject/myproject.DbMigrator.csproj", "myProject/myProject.DbMigrator/"]
RUN dotnet restore "myProjectDbMigrator/myProjectDbMigrator.csproj"
COPY . .
WORKDIR "/myProjectDbMigrator"
RUN dotnet build "myProject.DbMigrator.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "myProject.DbMigrator.csproj" -c Release -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "myProjectDbMigrator.dll"]

我的堆栈

  • .net 7.0 Linux容器映像
  • Azure中的可突发PostgreSQL灵活服务器
  • GitHub操作
  • abp.io框架
    更新

它看起来像是abp.io正在做的事情(或想让我做的事情),这是导致它,因为这与香草EF核心工程。我会更新这个问题,当我有一些回复my support question

8wtpewkr

8wtpewkr1#

这个错误的原因是我在密码中使用了$,运行docker run的**bash命令将'$'作为一个变量进行处理,并跳过将其及其后续字符发送到docker镜像中。
由于GitHub Actions没有显示值(user/pass),除了这种格式“*”,我只是假设()它是正确的。

相关问题