Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setup Postgres database schema for python Bitbucket Pipeline

I am trying to integrate bitbucket pipeline with my python package that use Postgres database.

To achieve this I am using Postgres service but I am not able to find any way in bitbucket-pipelines.yml to populate database schema.

Below is my bitbucket-pipeline.yml and now I am getting error "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/
like image 600
uinvent Avatar asked Feb 25 '26 13:02

uinvent


1 Answers

This worked for me (I had to remove the sudos for before the apt-get)

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

Make sure services is intented correctly, otherwise, the db won't start.

Julien

like image 169
JulienCoo Avatar answered Feb 27 '26 04:02

JulienCoo