gpt4 book ai didi

bash - 由于未安装 "hstore"Postgres 扩展,CircleCI 测试失败

转载 作者:行者123 更新时间:2023-11-29 13:16:22 27 4
gpt4 key购买 nike

我正在尝试获得某个提交以通过 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@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

在我的本地机器上,我通过运行 psql my_db 然后运行 ​​create extension hstore; 解决了这个问题。查看 PostgreSQL 图像的源代码 ( https://github.com/JannKleen/docker-postgres-gis-hstore ),我相信它运行以下 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 数据库,对吗? (参见 https://www.postgresql.org/docs/9.5/static/manage-ag-templatedbs.html)

我该如何修复这个错误?

最佳答案

我遇到了类似的问题,下面是我的解决方法。我的应用程序是一个节点应用程序,但基本思想应该是相同的。除了 Postgres 设置之外,我已经删除了任何特定于我的项目的内容。

version: 2

jobs:
build:
docker:
- image: circleci/postgres:10.3-alpine
environment:
- POSTGRES_USER: root
- POSTGRES_PASS: test
- POSTGRES_DB: circle-test

steps:
- checkout

- run:
name: Postgres Client
command: sudo apt install postgresql-client

- run:
name: Stash the PG Password
command: echo "test" > .pgpass

- run:
name: Waiting for PostgreSQL to start
command: |
for i in `seq 1 10`;
do
nc -z localhost 5432 && echo Success && exit 0
echo -n .
sleep 2
done
echo Failed waiting for Postgres && exit 1

- run:
name: Enable hstore in Postgres
command: psql -U root -d circle-test -h localhost -p 5432 -c "CREATE EXTENSION IF NOT EXISTS hstore;"

关于bash - 由于未安装 "hstore"Postgres 扩展,CircleCI 测试失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48411971/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com