我在执行.gitlab-ci.yml时在gitlab上出现错误
$ bundle exec rspec
在.gitlab-ci.yml中
在本地,我有用于开发和测试环境的PostgreSQL。所有rspec测试都通过了。
但是在gitlab上载项目后,它会引发错误:
An error occurred while loading ./spec/requests/api/packages_spec.rb.
Failure/Error: ActiveRecord::Migration.maintain_test_schema!
PG::ConnectionBad:
could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"
在我拥有sqlite3数据库之前。但是比我迁移到pg。
database.yml:
default: &default
adapter: postgresql
encoding: unicode
# For details on connection pooling, see Rails configuration guide
# https://guides.rubyonrails.org/configuring.html#database-pooling
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
development:
<<: *default
database: pg_app_development
test:
<<: *default
database: pg_app_test
添加database.yml端口和主机变量:
test:
<<: *default
database: pg_app_test
user: postgres
host: <%= ENV.fetch("DATABASE_HOST") { 'localhost' } %>
port: 5432
和.gitlab-ci.yml的db变量
variables:
RAILS_ENV: test
POSTGRES_DB: pg_app_test
POSTGRES_USER: postgres
POSTGRES_HOST_AUTH_METHOD: trust
DATABASE_HOST: postgres