首页 > 解决方案 > 带有 PostgreSQL 的 CI/CD 管道因“数据库未初始化且未指定超级用户密码”错误而失败

问题描述

我将 Bitbucket 管道与 PosgreSQL 一起用于 CI/CD。根据这个文档PostgreSQL 服务是这样描述的bitbucket-pipelines.yml

definitions:
  services:
    postgres:
      image: postgres:9.6-alpine

直到现在它工作得很好。但是我所有最新的管道都失败了,并出现以下错误:

   Error: Database is uninitialized and superuser password is not specified.
   You must specify POSTGRES_PASSWORD for the superuser. Use
   "-e POSTGRES_PASSWORD=password" to set it in "docker run".

   You may also use POSTGRES_HOST_AUTH_METHOD=trust to allow all connections
   without a password. This is *not* recommended. See PostgreSQL
   documentation about "trust":
   https://www.postgresql.org/docs/current/auth-trust.html

我该如何解决?文件没有变化,bitbucket-pipelines.yml这可能是导致此类错误的原因..

标签: postgresqldockerpipeline

解决方案


看起来原因是 docker 图像的更新(github问题)。最新版本不允许在没有密码的情况下从任何地方连接到数据库。所以你需要指定用户名/密码:

definitions:
  services:
    postgres:
      image: postgres:9.6-alpine
      environment:
         POSTGRES_DB: pipelines
         POSTGRES_USER: test_user
         POSTGRES_PASSWORD: test_user_password

或者如果您仍然不想使用密码,您可以设置POSTGRES_HOST_AUTH_METHOD=trust环境变量:

definitions:
  services:
    postgres:
      image: postgres:9.6-alpine
      environment:
        POSTGRES_HOST_AUTH_METHOD: trust

推荐阅读