postgresql - 如何为 python Bitbucket Pipeline 设置 Postgres 数据库模式
问题描述
我正在尝试将 bitbucket 管道与使用 Postgres 数据库的 python 包集成。
为了实现这一点,我正在使用 Postgres 服务,但我无法在 bitbucket-pipelines.yml 中找到任何方法来填充数据库模式。
下面是我的 bitbucket-pipeline.yml,现在我收到错误“bash: psql: command not found”
image: python:2.7.13
definitions:
services:
postgres:
image: postgres
pipelines:
default:
- step:
caches:
- pip
script:
- python setup.py sdist
services:
- postgres
branches:
master:
- step:
name: Run unit/integration tests
deployment: test
caches:
- pip
script:
- sudo apt-get update && sudo apt-get install -y postgresql-client
- psql -c 'drop database if exists testdb;' -U postgres
- psql -c 'create database testdb;' -U postgres
- python setup.py sdist
- python -m unittest discover tests/
解决方案
这对我有用(我必须在 apt-get 之前删除 sudo)
image: atlassian/default-image:2
clone:
depth: 5 # include the last five commits
definitions:
services:
postgres:
image: postgres
environment:
POSTGRES_DB: test_annotation
POSTGRES_USER: user
POSTGRES_PASSWORD: password
pipelines:
default:
- step:
caches:
- node
script:
- apt-get update && apt-get install -y postgresql-client
- PGPASSWORD=password psql -h localhost -p 5432 -U user test_annotation;
- chmod 755 ./scripts/create-test-database.sh
- ./scripts/create-test-database.sh
services:
- postgres
确保服务的意图正确,否则数据库将无法启动。
朱利安
推荐阅读
- php - 在codeigniter中批量上传图片
- python - 如何用python下载python?
- apache-poi - 如何使用 POI 4.0.0 绘制 2 线时间序列?
- java - SparkSession 从哪里获取 AWS 凭证?SparkSession 还是 HadoopConfiguration?
- qt - Qt5 什么是 const QModelIndex &sourceParent
- javascript - 工作量大时如何让express Node.JS回复请求?
- c++ - 如何使用 c++ 在 tensorflow 中更改 per_process_gpu_memory_fraction?
- javascript - JavaScript - 生成 1 到 5 之间的随机数,但绝不会连续两次相同的数字
- java - hadoop自定义可写未产生预期输出
- javascript - 在可折叠设备上使用多个砌体网格