Bash CircleCI测试因以下原因而失败;hstore";未安装Postgres扩展
我正试图通过CircleCI的测试,但我仍然在努力解决与本地环境的一些差异。以下是Bash CircleCI测试因以下原因而失败;hstore";未安装Postgres扩展,bash,postgresql,docker,yaml,circleci,Bash,Postgresql,Docker,Yaml,Circleci,我正试图通过CircleCI的测试,但我仍然在努力解决与本地环境的一些差异。以下是/circleci/config.yml文件: version: 2 jobs: build: working_directory: ~/lucy/lucy_web/ docker: - image: python:3.6.0 environment: DATABASE_URL: postgresql://my_app:my_password@lo
/circleci/config.yml
文件:
version: 2
jobs:
build:
working_directory: ~/lucy/lucy_web/
docker:
- image: python:3.6.0
environment:
DATABASE_URL: postgresql://my_app:my_password@localhost/my_db?sslmode=disable
- image: jannkleen/docker-postgres-gis-hstore
environment:
POSTGRES_USER: my_app
POSTGRES_DB: my_db
POSTGRES_PASSWORD: my_password
steps:
- checkout
- restore_cache:
key: deps1-{{ .Branch }}-{{ checksum "lucy-web/requirements.txt" }}
- run:
name: Install Python deps in a venv
command: |
cd lucy-web
python3 -m venv venv
. venv/bin/activate
pip3 install -r requirements.txt
- save_cache:
key: deps1-{{ .Branch }}-{{ checksum "lucy-web/requirements.txt" }}
paths:
- "venv"
- run:
command: |
cd lucy-web
source venv/bin/activate
python manage.py compilescss --verbosity 0
python manage.py collectstatic --clear --no-input --verbosity 0
python manage.py makemigrations --no-input --verbosity 0
python manage.py migrate --no-input --verbosity 0
python manage.py test
- store_artifacts:
path: test-reports/
destination: tr1
- store_test_results:
path: test-reports/
问题在于,由于hstore
类型不存在,测试出错:
django.db.utils.ProgrammingError: type "hstore" does not exist
LINE 1: ..., "options" varchar(255)[] NOT NULL, "conditions" hstore NOT...
^
Exited with code 1
在我的本地机器上,我通过运行psqlmy_db
然后运行createextensionhstore来解决这个问题代码>。查看PostgreSQL映像的源代码(),我相信它运行以下bash脚本:
#!/bin/sh
POSTGRES="gosu postgres"
echo "******CREATING EXTENSIONS******"
${POSTGRES} psql -d postgres -c "UPDATE pg_database SET datallowconn = TRUE WHERE datname = 'template0';"
${POSTGRES} psql -d postgres -c "UPDATE pg_database SET datallowconn = TRUE WHERE datname = 'template1';"
${POSTGRES} psql -d template1 -c "CREATE EXTENSION IF NOT EXISTS hstore;"
${POSTGRES} psql -d template1 -c "CREATE EXTENSION IF NOT EXISTS postgis;"
${POSTGRES} psql -d template1 -c "CREATE EXTENSION IF NOT EXISTS postgis_topology;"
echo ""
echo "******DATABASE EXTENSIONS******"
据我所知,如果扩展是在template1
数据库中创建的,那么它也应该应用my_db
数据库,对吗?(参见)
如何修复此错误?我遇到了类似的问题,下面是我如何解决的。我的应用程序是一个节点应用程序,但基本思想应该是相同的。除了Postgres设置之外,我已经删掉了我的项目的所有特定内容
版本:2
工作:
建造:
码头工人:
-图片:circleci/postgres:10.3-10
环境:
-POSTGRES_用户:root
-研究生考试及格
-POSTGRES_DB:循环测试
步骤:
-结帐
-运行:
姓名:Postgres客户端
命令:sudo apt安装postgresql客户端
-运行:
名称:隐藏PG密码
命令:echo“test”>.pgpass
-运行:
名称:正在等待PostgreSQL启动
命令:|
对于'seq 110'中的i;
做
nc-z localhost 5432&&echo成功&&exit 0
echo-n。
睡眠2
完成
echo在等待Postgres时失败&&退出1
-运行:
名称:在Postgres中启用hstore
命令:psql-U root-d circle test-h localhost-p 5432-c“如果不存在hstore,则创建扩展