Unable to `bundle exec rake db:structure:load` with 2.0

When running a brand new Rails app configured with a structure.sql file instead of a schema.rb file, I get the error

rake aborted!
failed to execute:
psql -v ON_ERROR_STOP=1 -q -f /home/circleci/circleci-demo-ruby-rails/db/structure.sql circle-test_test
Please check the output above for any errors and make sure that `psql` is installed in your PATH and has proper permissions.

Should be as vanilla as a rails app gets, so I’m not sure what the issue is here. Here’s the link to the failed build. https://circleci.com/gh/chrismanderson/circle-test/3 and here is my config.yml. Works fine on CircleCi 1.0.

version: 2
    working_directory: ~/circleci-demo-ruby-rails
      - image: circleci/ruby:2.4.1-node
          RAILS_ENV: test
          PGUSER: root
      - image: circleci/postgres:9.6.2-alpine
          POSTGRES_USER: root
          POSTGRES_DB: circle-test_test
      - checkout

      # Restore bundle cache
      - type: cache-restore
        key: rails-demo-{{ checksum "Gemfile.lock" }}

      # Bundle install dependencies
      - run: bundle install --path vendor/bundle

      # Store bundle cache
      - type: cache-save
        key: rails-demo-{{ checksum "Gemfile.lock" }}
          - vendor/bundle

      # Database setup
      - run: bundle exec rake db:create
      - run: bundle exec rake db:structure:load

      # Run rspec in parallel
      - type: shell
        command: |
          bin/rails test

      # Save artifacts
      - type: store_test_results
        path: /tmp/test-results

The issue is in the error message:

Please check the output above for any errors and make sure that psql is installed in your PATH and has proper permissions.

Looks like you are using the circleci/ruby:2.4.1-node which does not have psql installed by default. You can install it by adding:

sudo apt install postgresql-client

To your dependency phase. I think the reason why this is not included is because most languages/frameworks use native bindings for db access (i.e. the pg gem) rather than cli clients like psql.

I get a version type mismatch:

pg_dump: server version: 9.6.2; pg_dump version: 9.4.12

I’m not sure how to get postgresql-client-9.6. Although it appears to be an existing package, I keep getting that it doesn’t exist.

E: Unable to locate package postgresql-client-9.6

Is there any way to avoid having to install this manually? As you can imagine, this feels brittle to me and likely to cause issues down the road, and, as far as I can tell, slows down the build as well as it is an additional unnecessary step. Feels weird to me that the default ubuntu image you provide in CircleCI 1.0 has this functionality, whereas the newer one does not.


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