Skip to content

crane-cloud/backend

Repository files navigation

Crane Cloud

Test Build codecov

Managed Kubernetes Platform

Project Setup

Follow these steps to have a local running copy of the app.

Clone The Repo

git clone https://github.com/crane-cloud/backend.git

Directly on your machine


Install PostgreSQL

Here's a great resource to check out: How To Install and Use PostgreSQL

Create the two databases:

  • cranecloud (for development)
  • cranecloud_test_db (for unit testing)

Create a Virtual Environment

App was developed with Python 3.6.

Make sure you have pip installed on your machine.

Create a pip virtual environment called venv.

python -m venv venv

Activate the virtual environment:

.\venv\Scripts\activate

Install the dependencies:

pip install -r requirements.txt

Create a .env file (which defines the environment variables used) at the root of the app.

Add the following details, customizing as needed:

export FLASK_APP=server.py
export FLASK_ENV=development
export FLASK_DEBUG=1
export FLASK_RUN_PORT=5000
export FLASK_APP_SECRET=<app_secret>

Run the application:

flask run

Running application with Docker


make is a build automation tool that is used to manage the build process of a software project.

  • In the project directory, running make shows you a list of commands to use.
  • Run make start to start the application and required services.
  • Run make connect-to-container to connect to the Flask application container after running make start.

Application should be running on http://localhost:5000 and apidocs on http://localhost:5000/apidocs/#/

Finishing up

To run with Docker, you have to ssh into the container first by running make connect-to-container, and then execute the following commands.

Running Migrations

The application uses SQLAlchemy ORM to manage and run database migrations.

To run migration upgrade against the database relations, use the following command:

flask db upgrade

To run migrations in case there are changes in the schema, use the following command:

flask db migrate

Testing and Coverage

This app uses nose to run tests.

To run tests with coverage:

nosetests --with-coverage --cover-package=routes

To run tests without coverage:

nosetests

Creating default roles

To create the default roles, run:

flask create_roles

Creating default admin account

To create an admin account, run:

flask admin_user --email=<email> --password=<password> --confirm_password=<password>

To add clusters locally

Run the application using flask run and visit http://127.0.0.1:5000/apidocs/#/clusters/post_clusters

Use the following JSON payload:

{
  "description": "string",
  "host": "string",
  "name": "string",
  "token": "string"
}

Reach out to the backend team to get token and host values.

Optional things

Add image repositories

To add image repositories to the database, run:

flask create_registries

Starting celery workers

Run celery worker and beat on Linux

celery -A server.celery worker --loglevel=info
celery -A server.celery beat --loglevel=info

Run celery worker and beat on Windows

celery -A server.celery worker --pool=solo --loglevel=info
celery -A server.celery beat --loglevel=info