0

I have a docker development workflow where I have a sort of adhoc container that handles database migrations using prisma and shutdown. The migrations are supposed to deploy to a postgres database (also spun up within the same docker environment). All these are setup using a docker-compose. Below is a snippet of the setup.

      init:
        build:
          context: .
          dockerfile: ./init/Dockerfile
        volumes:
          - ./secrets:/out/cert
        environment:
          DB_HOST: postgres
          DB_USER: $DB_USER
      postgres:
        command:
        - -cssl=on 
        - -cssl_cert_file=/pg_certs/server.crt
        - -cssl_key_file=/pg_certs/server.key
        - -cssl_ca_file=/pg_certs/ca.crt
        depends_on:
          init:
            condition: service_started
        image: postgres:13
        restart: always
        volumes:
        - db_data:/var/lib/postgresql/data
        - ./secrets:/pg_certs
        environment:
          POSTGRES_PASSWORD: $DB_PASSWORD
          POSTGRES_USER: $DB_USER
          POSTGRES_DB: $DB_NAME
        ports:
        - "8081:5432"
        healthcheck:
          test: ["CMD-SHELL", "pg_isready"]
          interval: 10s
          timeout: 30s
          retries: 5
          start_period: 30s
      prisma:
        depends_on:
          postgres:
            condition: service_healthy
        build:
          context: .
          dockerfile: prisma/Dockerfile
        environment:
          DB_NAME: $DB_NAME
          DB_USER: $DB_USER
          DB_PASSWORD: $DB_PASSWORD
          DB_HOST: postgres:5432
          DATABASE_URL: postgres://$DB_USER:$DB_PASSWORD@postgres:5432/$DB_NAME?sslmode=require&sslcert=../secrets/ca.crt&sslidentity=../ssl/client-identity.p12
        volumes:
          - ./secrets:/work/secrets

Now I know the obvious question is "why did I decide to complicate my life by using SSL for development?"

This is an inherited project deployed in a kubernetes environment so this is my attempt at mimicking the deployment flow.

The problem is that anytime I run this the prisma service is only successful intermittently which has gotten to a point of frustration after scouring the internet to no avail. I'd really appreciate it if someone could save me from this googling loop.

toonday
  • 501
  • 4
  • 13

1 Answers1

0

I had a similar issue which seemed to only occur when I connected to my MySQL database through Docker. I used connect_timeout=300 in my MySQL connection URL which made connections more reliable (you may want to increase this if there is poor network connectivity).

I provide more information in my other answer on Stackoverflow.

Jed Peel
  • 166
  • 5