我有一个带有以下.gitlab-ci.yml
文件的symfony项目:
test:
image: registry.gitlab.com/MYIMAGEURL:latest
variables:
# POSTGRES - Use the values from the .env.test file.
POSTGRES_DB: db
POSTGRES_USER: postgres
POSTGRES_PASSWORD: asdfasdf
# MISC
APP_ENV: test
services:
- name: postgres:10
# "postgresql" is what we use in the .env.test file
alias: postgresql
before_script:
- cd my-project
script:
- cp .env.test .env
- composer install
当教义试图建立连接时,Symfony的cache:clear --env=test
失败:
SQLSTATE[08006] [7] could not connect to server: Connection refused
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
could not connect to server: Address not available
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
我的.env.test文件具有以下URL:
DATABASE_URL=pgsql://postgres:asdfasdf@postgresql:5432/db
所以我知道它应该在寻找postgresql
主机。
我进一步使用php bin/console debug:config doctrine
确认了教义配置,并且定义的默认连接URL为:url: '%env(resolve:DATABASE_URL)%'
。我还设置并确认cache:clear
命令正在test
环境中运行。为什么resolve:DATABASE_URL
解析为本地主机?
我不知道还能尝试什么。它始终连接到localhost
,而不是postgresql
。我还应该尝试什么?
编辑:此外,我使用手动服务链接遵循了testing a job locally上的指南,一切运行正常。
答案 0 :(得分:0)
问题是APP_ENV: test
配置变量。 bin/console
文件中包含代码,该代码检查是否设置了该env变量,并且只有在未设置该变量的情况下,它才会加载.env文件。删除此变量后,dotenv会根据需要加载.env文件。