0

I cannot get postgresql to run using travis, WITHIN A NESTED JOB

I have read all the posts I can find, and have tried everything. I think the problem is the jobs, as I did get postgresql to connect but only if I set it up in the outer layers.

I'm sorry I am not a travis expert so my terminology is probably all wrong:

Here is the yml file:

This is for this CI build 
https://travis-ci.com/github/hyperstack-org/hyperstack

I cannot get postgresql running... have followed all instructions, have tried all different versions.  I would ultimately like to get postgresql 11.2 running.  Please help 

I believe the problem has to do with the way we have these 'nested jobs'  but that is necessary for our build structure.

Here is my yml file:

language: bash
cache:
  bundler: true
  directories:
    - node_modules # NPM packages
_test_gem: &_test_gem
  # env:
  #   global:
  #   - PGPORT=5433
  stage: test
  services:
    - postgresql
  addons:
    apt:
      sources:
        - sourceline: 'deb http://dl.yarnpkg.com/debian/ stable main'
          key_url: 'http://dl.yarnpkg.com/debian/pubkey.gpg'
        - sourceline: 'deb http://dl.google.com/linux/chrome/deb/ stable main'
          key_url: 'https://dl-ssl.google.com/linux/linux_signing_key.pub'
      packages:
        - chromium-chromedriver
        - google-chrome-stable
        - yarn
        - redis-server
    # mariadb: '10.3' # mariadb works fine...
    postgresql: "9.6"
  before_install:
    - echo installing $COMPONENT
    - sudo rm -f /usr/local/bin/yarn
    - nvm install 10
    - rvm install 2.6.3  # was 2.5.1
    - gem install bundler
    - ln -s /usr/lib/chromium-browser/chromedriver ~/bin/chromedriver
  before_script:
    - echo creating pg database hyper_mesh_test_db
    - psql --version
    # reports pg is there... but following line breaks with:
    #    psql: could not connect to server: No such file or directory
    - psql -c 'CREATE DATABASE hyper_mesh_test_db;' -U postgres
    - psql -c 'CREATE ROLE travis SUPERUSER LOGIN CREATEDB;' -U postgres
    - echo before_script $COMPONENT
    - cd ruby/$COMPONENT
    - bundle install --jobs=3 --retry=3
    - bundle exec rake spec:prepare
    - google-chrome --version
    - which google-chrome
    - yarn install
  script:
    - echo running script $COMPONENT
    - DRIVER=travis bundle exec rake $TASK

_deploy_gem: &_deploy_gem
  stage: release gems
  before_script:
    - cd ruby/$COMPONENT
  script:
    - echo deploying $COMPONENT
  deploy:
    - provider: rubygems
      api_key:...
      on:
        tags: true
jobs:
  include:
    - <<: *_test_gem
      env: COMPONENT=hyper-model       RUBY_VERSION=2.5.1 TASK=part1
Mitch VanDuyn
  • 2,838
  • 1
  • 22
  • 29
  • Hmm, I've only ever used `services` on the top-level. Would be nice to have a slightly more minimal example. – Greg Schmit Feb 23 '21 at 17:41
  • Do you need to run `service postgresql start` before `psql` if it's in the `before_script`? https://stackoverflow.com/questions/42653690/psql-could-not-connect-to-server-no-such-file-or-directory-5432-error – Greg Schmit Feb 23 '21 at 17:44
  • Yeah, I would try putting `services` on the top-level and see if that helps. – Greg Schmit Feb 23 '21 at 18:06
  • previously tried all of the above... If I try setting things up outside the job, it still fails. – Mitch VanDuyn Feb 23 '21 at 22:29

1 Answers1

0

after a lot of trial and error I have come up with the solution. Its a matter of placing the correct incantations inside and outside the job. Hope this can help someone else:

dist: xenial  # not sure if this absolutely necessary...

# The following lines had to be commented out.
# It is possible that language: bash can be kept outside, and that
# the cache directive could be put inside the job.
# language: bash
# cache:
#   bundler: true
#   directories:
#   - node_modules # NPM packages


addons:
  apt:
    # any sources you need (this is nothing to do with postgre, just showing 
    # what should be out here.
    sources:
      - sourceline: 'deb http://dl.yarnpkg.com/debian/ stable main'
        key_url: 'http://dl.yarnpkg.com/debian/pubkey.gpg'
      - sourceline: 'deb http://dl.google.com/linux/chrome/deb/ stable main'
        key_url: 'https://dl-ssl.google.com/linux/linux_signing_key.pub'
    # now load up your packages including postgresql-11
    packages:
      - postgresql-11
      - chromium-chromedriver
      - google-chrome-stable
      - yarn
      - redis-server
  # and finally indicate you want postgresql
  postgresql: '11'

_test_gem_pg: &_test_gem_pg
  # the rest of the postgresql setup goes INSIDE the job:
  before_install:
    - echo 'installing postgresql'
    - sudo sed -i 's/port = 5433/port = 5432/' /etc/postgresql/11/main/postgresql.conf
    - sudo cp /etc/postgresql/{9.6,11}/main/pg_hba.conf
    - sudo service postgresql stop
    - sudo service postgresql start 11
    - postgres --version
    # any other before_install you need
    - sudo rm -f /usr/local/bin/yarn
    - nvm install 10
    - rvm install 2.6.3  # was 2.5.1
    - gem install bundler
    - ln -s /usr/lib/chromium-browser/chromedriver ~/bin/chromedriver
    - echo 'install completed'

  before_script:
    # any other before_script you need
    - echo before_script $COMPONENT
    - cd ruby/$COMPONENT
    - bundle install --jobs=3 --retry=3
    - bundle exec rake spec:prepare
    - google-chrome --version
    - which google-chrome
    - yarn install
  script:
    # finally your script
    - echo running script $COMPONENT
    - DRIVER=travis bundle exec rake $TASK
# if some jobs use a different db, you set that up as a different description
# and change the before_script so it doesn't setup pg...
_test_gem: &_test_gem
  stage: test
  addons:
  # ... etc... 

jobs:
  include:
    - <<: *_test_gem_pg
      env: COMPONENT=hyper-model       RUBY_VERSION=2.5.1 TASK=part1 DB=hyper_mesh_test_db
    - <<: *_test_gem
      env: COMPONENT=rails-hyperstack  RUBY_VERSION=2.5.1
Mitch VanDuyn
  • 2,838
  • 1
  • 22
  • 29