Giter Site home page Giter Site logo

postgres-api's Introduction

tsuru-postgresapi

A PostgreSQL API for tsuru PaaS

Build Status

Installation

Install PostgreSQL server (Debian/Ubuntu)

First you should have a PostgreSQL server. In Debian/Ubuntu, use apt-get to install it.

$ sudo apt-get install postgresql

Create database for postgresapi

After install PostgreSQL, you need to create a user and a database for postgresapi, that is needed to store informations about created instances.

Here is an example:

$ sudo -u postgres createuser postgresapi -P
# "Enter password for new role"
# "Enter it again"
# "Shall the new role be a superuser?" No
# "Shall the new role be allowed to create databases?", No
# "Shall the new role be allowed to create more new roles?", No

$ sudo -u postgres createdb postgresapi -O postgresapi

Create superuser to manage databases

You can use another host to provide PostgreSQL to other applications.

$ sudo -u postgres createuser postgresadmin -P
# "Enter password for new role"
# "Enter it again"
# "Shall the new role be a superuser?" Yes

Access control

You may have to edit server's pg_hba.conf and postgresql.conf to allow accessing from external IPs. See PostgreSQL's document for more.

# change "9.3" to the version of your current PostgreSQL cluster

# add this line (change "10.0.2.0/24" to the allowed CIDR):
# host    all    all    10.0.2.0/24    md5
$ sudo editor /etc/postgresql/9.3/main/pg_hba.conf

# change "listen_addresses" to "0.0.0.0" to listen on all interfaces
$ sudo editor /etc/postgresql/9.3/main/postgresql.conf

$ sudo service postgresql restart

Install service

Now you can install postgresapi service. In your tsuru client machine (with crane installed):

$ git clone https://github.com/tsuru/postgres-api
$ tsuru app-create postgresapi python

Export these environment variables:

# postgresapi's database configure
$ tsuru env-set -a postgresapi POSTGRESAPI_DATABASE=postgresapi
$ tsuru env-set -a postgresapi POSTGRESAPI_USER=postgresapi
$ tsuru env-set -a postgresapi POSTGRESAPI_PASSWORD=******
$ tsuru env-set -a postgresapi POSTGRESAPI_HOST=localhost
$ tsuru env-set -a postgresapi POSTGRESAPI_PORT=5432

# salt used to hash the username/password
$ tsuru env-set -a postgresapi POSTGRESAPI_SALT=******

# Tsuru API access username & password
$ tsuru env-set -a postgresapi POSTGRESAPI_BROKER_USERNAME=admin
$ tsuru env-set -a postgresapi POSTGRESAPI_BROKER_PASSWORD=******

We are only support shared mode currently. Export these variables to specify the shared cluster:

# these settings can be different with postgresapi's database
$ tsuru env-set -a postgresapi POSTGRESAPI_SHARED_HOST=localhost
$ tsuru env-set -a postgresapi POSTGRESAPI_SHARED_PORT=5432
$ tsuru env-set -a postgresapi POSTGRESAPI_SHARED_ADMIN=postgresadmin
$ tsuru env-set -a postgresapi POSTGRESAPI_SHARED_ADMIN_PASSWORD=******
$ tsuru env-set -a postgresapi POSTGRESAPI_SHARED_PUBLIC_HOST=pg.example.com

Configuration are finished now. Deploy the service.

# Find out git repository then deploy the service
$ cd postgres-api
$ tsuru app-info -a postgresapi | grep Repository
$ git remote add tsuru [email protected]:postgresapi.git
$ git push tsuru master

# The database is ready. Upgrade it!
$ tsuru app-run --app postgresapi -- python manage.py upgrade_db

Configure the service template and point it to your application:

$ cp service.yaml.example service.yaml
# you can find out production address from app-info
$ tsuru app-info -a postgresapi | grep Address
# set production address
$ editor service.yaml
$ crane create service.yaml

To list your services:

$ crane list
# OR
$ tsuru service-list

Dedicated instances

This API provide dedicated instances if needed: a new dedicated Docker container is created with a running PostgreSQL database. To enable this feature, you need to set the DOCKER_HOST environment variable with the address of docker server on which to start instances.

tsuru env-set -a postgresapi DOCKER_HOST="tcp://tsuru.cluster.example.com:4243"

Set the Docker image to user:

tsuru env-set -a postgresapi DEDICATED_IMAGE_NAME="sroze/tsuru-postgresql"

Note: hosts will be used in a random way to create instances on.

Usage

Please see tsuru's document.

TODO

  • EC2 supporting

postgres-api's People

Contributors

actionjack avatar andrewsmedina avatar dcarley avatar dhilton avatar fsouza avatar pedrosnk avatar philiptzou avatar richardknop avatar scorphus avatar sroze avatar

Watchers

 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.