2

所以我bitbucket-pipelines.yml为我的 python 应用程序设置了一个。它需要一个 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 似乎没有启动并运行。

4

2 回答 2

1

您需要基于 postgres 创建自己的图像,然后将其推送到存储库并在管道中使用

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

您还可以在https://hub.docker.com/中找到适合您要求的图像

于 2017-07-18T08:01:18.663 回答
0

这对我有用,无需构建我自己的图像(我向 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,并且我使用-hand-p参数连接到正在运行的 postgres 实例(否则它将尝试使用 unix 套接字来执行此操作,这似乎不起作用)。

于 2018-04-30T22:21:42.043 回答