Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CI/CD pipeline with PostgreSQL failed with "Database is uninitialized and superuser password is not specified" error

I'm using Bitbucket pipeline with PosgreSQL for CI/CD. According to this documentation PostgreSQL service has been described in bitbucket-pipelines.yml this way:

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

It worked just fine until now. But all my latest pipelines failed with following error:

   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

How can I fix it? There was no changes in bitbucket-pipelines.yml file which could be the reason of such error..

like image 977
neverwalkaloner Avatar asked Feb 17 '20 12:02

neverwalkaloner


Video Answer


2 Answers

Looks like the reason is docker image's updates (github issue). Latest versions do not allow to connect to DB without a password from anywhere. So you need to specify username/password:

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

Or if you still don't want to use password, you can just set POSTGRES_HOST_AUTH_METHOD=trust environment variable:

definitions:
  services:
    postgres:
      image: postgres:9.6-alpine
      environment:
        POSTGRES_HOST_AUTH_METHOD: trust
like image 185
neverwalkaloner Avatar answered Oct 16 '22 19:10

neverwalkaloner


This is a very recent change, as of about a week ago. One way to avoid it is to hardcode your postgres version to not the latest, eg changing to postgres:9.5.18 or postgres:9.5.20-alpine

Another way is to pass a fake password:

services:
  db:
    image: postgres
    ports:
      - "8001:5432"
    environment:
      - POSTGRES_PASSWORD=fake_password

See the discussion here: https://github.com/docker-library/postgres/issues/681

like image 6
ehacinom Avatar answered Oct 16 '22 19:10

ehacinom