Travis - Postgresql内部的嵌套作业



我不能让postgresql运行使用travis,在一个嵌套的作业

我已经阅读了我能找到的所有帖子,并尝试了所有的方法。我认为问题是工作,因为我确实得到了postgresql连接,但只有当我把它设置在外层。

很抱歉,我不是特拉维斯专家,所以我的术语可能都错了:

下面是yml文件:

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

经过反复试验,我终于想出了解决办法。这是一个在工作内外放置正确咒语的问题。希望能对别人有所帮助:

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

最新更新