【问题标题】:Install Postgres extensions in bitbucket pipeline在 bitbucket 管道中安装 Postgres 扩展
【发布时间】:2017-05-29 12:49:57
【问题描述】:

所以我为我的 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 似乎没有启动并运行。

【问题讨论】:

    标签: postgresql bitbucket bitbucket-pipelines


    【解决方案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/找到适合您要求的图片

    【讨论】:

      【解决方案2】:

      这对我有用,无需构建我自己的图像(我向 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套接字来完成它,这似乎没有工作)。

      【讨论】:

        猜你喜欢
        • 2020-08-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-01-17
        • 2021-07-27
        • 2022-11-17
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多