Code Monkey home page Code Monkey logo

postgraas_server's Introduction

postgraas_server

https://travis-ci.org/blue-yonder/postgraas_server.svg?branch=master https://coveralls.io/repos/github/blue-yonder/postgraas_server/badge.svg?branch=master

Postgraas is a super simple PostgreSQL-as-a-service

What is Postgraas?

Postgraas offers CRUD operations for complete PostgreSQL database instances via a simple REST api. The database instances are docker containers and the API server is a few hundred LoC Flask application. It is not meant as a production ready solution, but more as a proof-of-concept to spread the idea of creating "as-a-service" services easily yourself and should inspire you to start working on your own cloud infrastructure today. But in fact, it proofs the concept very well and it turned out to be super useful for delivering a PostgreSQL instance if you need one fast, e.g. for integration tests, for playing around with fancy ShowHN projects or other experiments. The CRUD management via REST api is of course also a necessary prerequisite for building an automated continuous delivery pipeline for a modern software project.

Installation

You can find detailed instructions in the docs

Install via pip:

pip install postgraas_server

Start the WSGI api server for example via gunicorn:

pip install gunicorn
gunicorn -w 4 -b 0.0.0.0:8080 postgraas_server.postgraas_api:app

Usage

We need to send all the required parameters for the creation as an http request. This is quite convenient by creating a file e.g. my_postgraas.json:

{
    "postgraas_instance_name": "my_postgraas",
    "db_name": "my_db",
    "db_username": "db_user",
    "db_pwd": "secret"
}

and making a POST request to the collection resource with curl:

curl -H "Content-Type: application/json" -X POST --data @my_postgraas.json http://localhost:8080/api/v2/postgraas_instances

now your instance is created and as a response you get the details of your instance:

{
     "postgraas_instance_id": 1,
     "container_id": "193f0d94d49fa26626fdbdb583e9453f923468b01eac59207b4852831a105c03",
     "db_pwd": "secret",
     "host": "not imlemented yet",
     "db_name": "my_db",
     "db_username": "db_user",
     "port": 54648
}

We are now able to connect to the database for example via psql:

psql -h localhost -p 54648 -U db_user my_db

Awesome, isn’t it?

Development

Run the tests

You need to have docker installed

Make sure you pull the right docker image:

docker pull postgres:9.4

Make a virtualenv and install the requirements including the dev requirements and a local editable install of the package, for convenience you can install the requirements.in

pip install -r requirements.in
pip install -r requirements_dev.txt
pip install -e .

For the tests you need a running postgres meta database and set some environment variables accordingly. There is a convenience script to set this all up using a docker postgres database:

. setup_integration_test_docker.sh

Now you should be able to execute the tests:

pytest tests/

postgraas_server's People

Contributors

sebastianneubauer avatar matthias-bach-by avatar fra-nk avatar treebee avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.