gpt4 book ai didi

postgresql - 在 bitbucket 管道中安装 Postgres 扩展

转载 作者:行者123 更新时间:2023-11-29 12:25:07 26 4
gpt4 key购买 nike

所以我为我的 python 应用程序设置了一个 bitbucket-pipelines.yml。它需要一个 postgres 数据库,所以我已经按照这里的教程 (https://confluence.atlassian.com/bitbucket/test-with-databases-in-bitbucket-pipelines-856697462.html) 进行了操作,这让我得到了以下配置:

image: node 
pipelines:
default:
- step:
script:
- npm install
- npm test
services:
- postgres

definitions:
services:
postgres:
image: postgres
environment:
POSTGRES_DB: 'pipelines'
POSTGRES_USER: 'test_user'
POSTGRES_PASSWORD: 'test_user_password'

我的数据库中需要一些特定的扩展,我该如何添加这些。我试图在安装它们的脚本中添加一个额外的,但那时 postgres 似乎没有启动和运行。

最佳答案

这对我有用,无需构建我自己的图像(我向 postgres 添加了 2 个扩展):

image: node:8.11.1 # or any image you need

clone:
depth: 1 # include the last commit

definitions:
services:
postgres:
image: postgres
environment:
POSTGRES_DB: test
POSTGRES_USER: postgres
POSTGRES_PASSWORD: your_password

pipelines:
default:
- step:
caches:
- node
script:
- npm install
- apt-get update
- apt-get -y install postgresql-client
- ./bin/utilities/wait-for-it.sh -h localhost -p 5432 -t 30
- PGPASSWORD=your_password psql -h localhost -p 5432 -c "create extension if not exists \"uuid-ossp\"; create extension if not exists pg_trgm;" -U postgres test;
- npm test test/drivers/* test/helpers/* test/models/*
services:
- postgres

wait-for-it.sh 确保 postgres 已准备好运行,您可以在这里找到它:https://github.com/vishnubob/wait-for-it

然后,我运行 psql 在测试数据库中创建扩展。这里注意我在运行之前设置的变量 PGPASSWORD 并且我使用 -h-p 参数连接到正在运行的 postgres 实例(否则它将尝试使用 unix 套接字来完成它,这似乎不起作用)。

关于postgresql - 在 bitbucket 管道中安装 Postgres 扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44242940/

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