Upgrading From Deprecated Docker Convenience Image openjdk Connecting To Postgres

I am trying to upgrade away from my deprecated Docker convenience images.

This build works:

version: 2.1
jobs:
  build:
    docker:
      - image: circleci/openjdk:11
        environment:
          SPRING_DATASOURCE_USERNAME: springuser
          REPO_NAME: danielahedges/circleci
      - image: circleci/postgres:10.11-alpine-ram
        environment:
          POSTGRES_USER: postgresuser
          POSTGRES_DB: db
    steps:
      - run:
          name: Install psql
          command: |
            echo 'deb http://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main' | sudo tee --append /etc/apt/sources.list.d/pgdg.list
            sudo wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
            sudo apt-get update
            sudo apt-get install -y postgresql-client-10
      - setup_remote_docker
      - checkout
      - run:
          name: Query DB
          command: psql -d db -U postgresuser -h localhost -c "select count(1) from information_schema.schemata;"

However, if I just change the openjdk container from circleci/openjdk:11 to cimg/openjdk:11.0, the simple database query hangs, apparently unable to contact the database.

Is there a difference between the two containers that would explain how to connect to the database?

Thanks!

Hi,

Thanks for your post. I did some research and I figured out how to get this example to work. With the next-gen OpenJDK image, set the environment variable pager to cat. Also, in this example, you are installing a package for PostgreSQL meant for Debian Stretch. The new image is Ubuntu 20.04 based. So I’d change stretch to focal. Here’s the updated example:

version: 2.1
jobs:
  build:
    docker:
      - image: circleci/openjdk:11
        environment:
          SPRING_DATASOURCE_USERNAME: springuser
          REPO_NAME: danielahedges/circleci
          PAGER: cat
      - image: circleci/postgres:10.11-alpine-ram
        environment:
          POSTGRES_USER: postgresuser
          POSTGRES_DB: db
    steps:
      - run:
          name: Install psql
          command: |
            echo 'deb http://apt.postgresql.org/pub/repos/apt/ focal-pgdg main' | sudo tee --append /etc/apt/sources.list.d/pgdg.list
            sudo wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
            sudo apt-get update
            sudo apt-get install -y postgresql-client-10
      - setup_remote_docker
      - checkout
      - run:
          name: Query DB
          command: psql -d db -U postgresuser -h localhost -c "select count(1) from information_schema.schemata;"

I will get this environment variable set in cimg/base. The change will take some time to trickle down to the rest of the images but new PostgreSQL images released starting in April will have the change. In the meantime, setting this in your config like I showed should do the trick.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.