Skip to content

amitech/spinup

 
 

Repository files navigation

SPINUP

An open source alternative to AWS RDS, Cloud SQL.

Architecture

The idea is simple. Spinup creates multiple containers through docker-compose. Spinup can be deployed anywhere. System requirements are Go and docker-compose. Once this issue has been fixed then you don't need to have Go installed. It can run on Digital Ocean droplet, Azure Compute, Oracle Compute, Raspberry Pi etc.

We are currently using Github Authentication. We should be able to support other authentication methods.

Currently we only support Postgres dbms, but we should be able to support other open source databases like MySQL, MariaDB etc.

architecture

Installation

Linux

To get started with Spinup on Linux:

  • Run the installation script using the command below:
bash < <(curl -s https://raw.githubusercontent.com/spinup-host/spinup/main/scripts/install-spinup.sh)
  • Add the Spinup installation directory (default is $HOME/.local/spinup) to your shell PATH to use Spinup from your terminal.
  • Start the Spinup servers (both API and frontend) by running:
spinup start
  • (Optional) If you want to use Github Authentication, create a project in github. Next, export the project's client ID and Secret as environment variables
export CLIENT_ID=<GITHUB_CLIENT_ID>
export CLIENT_SECRET=<GITHUB_CLIENT_SECRET>
  • (Optional) You can change the API_KEY value using enviornment variable. Default value is spinup
export SPINUP_API_KEY=<YOUR_API_KEY>

Others

To create a private key

visi@visis-MacBook-Pro spinup % openssl genrsa -out /${SPINUP_PROJECT_DIR}/app.rsa 4096 
Generating RSA private key, 4096 bit long modulus
...++
...................++
e is 65537 (0x10001)

To create a public key

visi@visis-MacBook-Pro spinup % openssl rsa -in /${SPINUP_PROJECT_DIR}/app.rsa -pubout > /${SPINUP_PROJECT_DIR}/app.rsa.pub
writing RSA key

Create a config.yaml file

common:
  ports: [
    5432, 5433, 5434, 5435, 5436, 5437
  ]
  architecture: amd64
  projectDir: <PROJECT_DIR>
  client_id: <CLIENT_ID>
  client_secret: <CLIENT_SECRET>
  api_key: <API_KEY> //if not using github authentication

To run spinup

go run main.go

Authentication

We use JWT for verification. You need to have a private and public key that you can create using OpenSSL:

On another terminal you can start the dash to access the backend.

To check the API endpoint:

curl -X POST https://localhost:4434/createservice \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer reaplaceyourtokenhere" \
    --data '{
        "userId": "viggy28",
        "db": {
            "type": "postgres",
            "name": "localtest",
            "username": "spinup",
            "password": "spinup",
            "memory": 6000, //In Megabytes
            "cpu": 2
            },
        "version": {"maj":9,"min":6}
        }'

Once you created a cluster, you can connect using psql or any other postgres client

visi@visis-MacBook-Pro ~ % psql -h localhost -U postgres -p <port>
Password for user postgres:
psql (9.6.18, server 13.3 (Debian 13.3-1.pgdg100+1))
WARNING: psql major version 9.6, server major version 13.
         Some psql features might not work.
Type "help" for help.

postgres=# \dt

API Documentation

Endpoints

Github Auth

  • URL

/githubAuth

  • Method:

POST

  • Data Params
{
    "code": "githubcode"
}
  • Success Response:

    • Code: 200
    • Content: {"login":"","avatar_url":"","name":"","token":""}
  • Error Response:

    • Code: 404 NOT FOUND

      Content: { error : "User doesn't exist" }

    OR

    • Code: 401 UNAUTHORIZED

      Content: { error : "You are unauthorized to make this request." }

Simple Auth

  • URL

/altauth

  • Method:

POST

Api Key Header

x-api-key: <API_KEY>

  • Success Response:

    • Code: 200
    • Content: {Valid Api Key}
  • Error Response:

    • Code: 401 UNAUTHORIZED

      Content: { error : "error validating api key" }

Create Service

/createservice - Creates a new database service. Only Postgres databases are supported at the moment

Authentication Header

Bearer <GITHUB_TOKEN>

Api Key Header

x-api-key: <API_KEY>

Method:

POST

Data Params

  • userId=[String]: GitHub username of the user.(Necessary only if using github authentication)
  • version=[Object]: Preferred database version. It must have the following properties:
    • maj=[Integer]: Database major version. E.g for Postgres:9.6, the value here is 9.
    • min=[Integer]: Database major version. E.g for Postgres:9.6, the value here is 6.
  • db=[Object]: A JSON object describing the properties of the database to be created. The properties are:
    • type=[String]: Type of the database service to be created. Only postgres is supported for now.
    • name=[String]: Name of the database service
    • monitoring=[String]: Optional. Must be either of enable or disable when present. When enabled, it turns on prometheus metrics for the database on port 9187.
{
  "userId": "viggy28",
  "db": {
    "type": "postgres",
    "name": "localtest",
    "monitoring": "enable"
  },
  "version": {
    "maj": 9,
    "min": 6
  }
}

Success Response:

Code: 200

Error Response:

Code: 500 INTERNALSERVER ERROR

Get service

/cluster?cluster_id=<CLUSTER_ID> - Fetches specific details of a service or cluster

Method:

GET

Authentication Header

Bearer <GITHUB_TOKEN>

Api Key Header

x-api-key: <API_KEY>

Path Parameters

  • cluster_id=[String]: ID of the cluster to be retrieved.

Responses

200:

{
    "data": {
        "cluster_id": "a130e42a09f4\n",
        "id": 2,
        "name": "localtest",
        "port": 5432,
        "username": "localtest"
    }
}

404:

{
    "message": "no cluster found with matching id"
}

JWT

  • URL

/jwt?data=replaceme

  • Method:

GET

  • Success Response:
    • Code: 200
    • Content: {jwtofreplaceme}

About

spinup repository

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 90.9%
  • Shell 7.5%
  • Dockerfile 1.6%