Software-as-a-service deployment and authentication portal for M-Lab's Piecewise.
- Node.js of version
>=12 npm
Piecewise SaaS is composed of 2 different parts:
- A React-based frontend.
- A Koa-based backend that renders & serves the frontend and exposes an API used by the frontend.
These parts are located here in this repository:
src/backend # The backend components
src/common # Common code and assets
src/frontend # The React frontend
Piecewise SaaS is configured via variables either specified in the environment
or defined in a .env file (see env.example for an example configuration that
may be edited and copied to .env).
The backend parses the following configuration variables:
PIECEWISE_SAAS_LOG_LEVEL # Logging level (default: error)
PIECEWISE_SAAS_DOMAIN # The domain at which Piecewise SaaS is being hosted
PIECEWISE_SAAS_HOST # The host Piecewise runs on (default: localhost)
PIECEWISE_SAAS_PORT # The port to bind to (default: 3000)
PIECEWISE_SAAS_DB_HOST # Postgres database host (default: localhost)
PIECEWISE_SAAS_DB_PORT # Postgres port (default: 5432)
PIECEWISE_SAAS_DB_DATABASE # Postgres database name (default: piecewise)
PIECEWISE_SAAS_DB_USERNAME # Postgres user (default: piecewise)
PIECEWISE_SAAS_DB_PASSWORD # Postgres password
PIECEWISE_SAAS_DB_POOL_MIN # Postgres minimum connections (default: 0)
PIECEWISE_SAAS_DB_POOL_MAX # Postgres max connections (default: 10)
PIECEWISE_SAAS_DB_TIMEOUT # Postgres connection timeout (default: 0)
PIECEWISE_SAAS_MAPBOX_KEY # The Mapbox API key to which to default Piecewise instances
Additionally, we use the semi-standard NODE_ENV variable for defining test,
staging, and production.In development mode Piecewise SaaS uses sqlite3, but
uses Postgres in production.
First, clone this repository and from the root of the resulting directory install Piecewise SaaS's dependencies:
npm install
Then, build all components:
npm run build
Create the database:
npm run db:migrations
and to optionally populate it with test data:
npm run db:seeds
And start the running processes (with necessary environment variables if not
defined in .env):
npm run start
(use npm run start:dev to run in development mode)
Additionally, components can be built or started individually using for example
npm run build:backend, npm run start:worker, etc.
You can deploy this tool using Docker. There is an included
docker-compose.yml file that will allow you to run it in a production
configuration. First, clone the repo and from this directory run docker-compose:
docker-compose up --build -d
This will build the docker container from the current repository, download the
official Postgres docker image, and configure them both (the -d flag will
detach from the current shell so that you can leave it running, but you can omit
it in order to leave the log output attached).
If this is the first time you've run it on this system, you'll want to run the database migrations to initialize the database:
docker-compose run piecewise-saas db:migrations
and then optionally seed the database with a default admin user:
docker-compose run piecewise-saas db:seeds
By default, it runs behind Traefik on ports 80 & 443, and Traefik will take care of issuing certificates via Letsencrypt.
Piecewise SaaS maintains Piecewise instances with OAuth2 for authentication. This support was made and tested for use with Piecewise, YMMV when using a different backend.
Piecewise-SaaS takes care of configuring the OAuth2 parameters for the Piecewise instances it manages.
To backup an instance of Piecewise running in a Docker container, run the following command:
docker exec <name of postgres container> pg_dumpall -c -U <database user, default piecewise> dump_`date +%d-%m-%Y"_"%H_%M_%S`.sql
To restore:
cat <backup file>.sql | docker exec -t <name of postgres container> pg_dumpall -c -U <database user, default piecewise > dump_`date +%d-%m-%Y"_"%H_%M_%S`.sql
Piecewise SaaS is an open-source software project licensed under the Apache License v2.0 by Measurement Lab and Throneless Tech.