Unable to `rake db:structure:load` without breaking bundle cache

rails
postgresql
2.0

#1

I have not been able to get my build past rake db:structure:load without adding a line to my config to pull in some stuff via apt-get. However, doing this seems to cause my bundle cache to not be used.

Without the apt-get line, I get the error:

** Execute db:structure:load
rake aborted!
failed to execute:
psql -q -f /home/circleci/midroll/db/structure.sql myapp_test

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

Any ideas? Including config.yml below:

version: 2
jobs:
  build:
    working_directory: ~/myapp
    docker:
      - image: circleci/ruby:2.3.3-node
        environment:
          RAILS_ENV: test
          RACK_ENV: test
          PG_HOST: localhost
          PGUSER: ubuntu
      - image: postgres:9.4.7
        environment:
          POSTGRES_USER: ubuntu
          POSTGRES_DB: myapp_test
      - image: redis:3.2.6
        environment:
          POSTGRES_USER: root

    steps:
      - checkout
      - run: sudo apt-get update -qq && sudo apt-get install -y build-essential nodejs redis-tools postgresql

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

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

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

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

      # Run rspec in parallel
      - type: shell
        command: |
          bundle exec rspec --profile 10 \
                            --out /tmp/test-results/rspec.xml \
                            --format progress \
                            $(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)

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

#2

That is all 100% correct. You are using psql and we’re not including it on the image at this time. You can definitely build your own image, though. Just extend the image in your config right now, install those packages, commit & push it to Docker Hub (or the registry of your choosing).


#3

Very helpful, thanks! :slight_smile:


#4

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