Can't create Postgres db as postgres user on custom-built image

bundler
ruby
postgresql
circle.yml
cci-20

#1

I built a custom docker image because the prebuilt ones had compatibility problems with the stack we use. The image

  • is ubuntu xenial based
  • uses /bin/bash as the shell
  • installs redis-server, postgres 10, ruby (via rvm), and the app’s dependencies via bundler

The Circle CI instance’s tasks are (config.yml):

  • start redis and postgres servers (run: service postgresql start)
  • setup the database
  • run the specs

The servers start fine, however, the database setup fails:
- run: /usr/local/rvm/bin/rvm-shell -c 'bundle exec rake db:create db:structure:load --trace'
Fails:
FATAL: role "root" does not exist Couldn't create database for {"adapter"=>"postgis", "encoding"=>"unicode", "pool"=>5, "database"=>"xxx_test"} rake aborted! ActiveRecord::NoDatabaseError: FATAL: role "root" does not exist

One suggested solution to this is running the process as the user postgres:
- run: sudo -u postgres -i "bundle exec rake db:create db:structure:load --trace"
Fails:
-bash: bundle exec rake db:create db:structure:load --trace: command not found

I also tried using the RVM shell:
- run: sudo chmod 755 /usr/local/rvm/bin/rvm-shell - run: sudo -u postgres -i "/usr/local/rvm/bin/rvm-shell -c 'bundle exec rake db:create db:structure:load --trace'"
Fails:
-bash: /usr/local/rvm/bin/rvm-shell -c 'bundle exec rake db:create db:structure:load --trace': No such file or directory

Is this an issue with using sudo -u postgres on a circleci instance? Perhaps there is a problem with the setup as a whole? The reason I chose to build a custom image is that none of the prebuilt images were compatible with all of the stack we use. We use Postgres 10.4 with the postgis, geos (libgeos-dev) and proj4 (libproj-dev) libraries, which are not supported on the alpine based postgres images.


#2

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