Build from source

Instructions on building Garnet from source

Prerequisites

Building Garnet from source

  1. Install git

    sudo apt-get update && sudo apt-get install git
  2. To clone the Garnet repository and enter the new directory, run:

    git clone https://github.com/garnet-labs/garnet-oss.git && cd garnet-oss
  3. Generate a ENCRYPTION_KEY that is unique to your instance. Please follow the instructions on this page for creating a custom encryption key.

  4. Set environment variables. A detailed guide for Garnet's env variable configuration is here.

    #set DB config
    export DB_HOST = '<Your Database Host>' #default = localhost
    export DB_USERNAME = '<Your Database Username>' #default = postgres
    export DB_PASSWORD = '<Your Database Password>' #default = ""
    export DB_NAME = '<Your Database Name>' #default = development
    export DB_TYPE= "postgres"
    export DB_LOGGING= "true"
    export FRONTEND_URL= "http://localhost:3000"
    export BACKEND_URL= "http://localhost:8080/api"
    #set encryption keys
    export ENCRYPTION_KEY= '<randomly generated 32 byte / 256 bit key>'
    export AUTH_JWT_SECRET= '<randomly generated UUID string>'
    # misc
    export AUTH_SOCIAL_GITHUB_CLIENT_ID= '<GitHub OAuth client ID>'
    export AUTH_SOCIAL_GITHUB_CLIENT_SECRET= '<GitHub OAuth client secret>'
    export AUTH_SOCIAL_GITHUB_CALLBACK_URL= 'http://localhost:8080/api/auth/social/github/callback'
    export TENANT_MODE= 'multi'
    export AUTH_JWT_EXPIRES_IN= '365 days'
    export API_DOCUMENTATION_ENABLED= "true"
    # if you need email relay
    SENDGRID_EMAIL_FROM= '<your-sender-email>'
    SENDGRID_KEY= '<your-sendgrid-key>'
    SENDGRID_TEMPLATE_EMAIL_ADDRESS_VERIFICATION= '<verification-template-id>'
    SENDGRID_TEMPLATE_INVITATION= '<invitation-template-id>'
    SENDGRID_TEMPLATE_PASSWORD_RESET= '<password-reset-template-id>'

    Note: To comply with conventions, default environment variables can also be stored in thebackend/.env file. However, it is not recommended to store your env variables locally or in your code. You can either export them before running the app, or use a configuration manager such as Garnet Cloud

  5. Navigate to the /backend directory, and install the backend server

    cd backend && npm install
  6. Initialize the DB

    npm run db:create
  7. Start the backend server

    npm run start
  8. Navigate to the /frontend directory, and install the frontend server

    cd garnet-oss/frontend && npm install
  9. Start the frontend server

    npm start

    Once your the server is up, you can navigate to the Dashboard at http://localhost:3000 (if running locally) or http://<your-instance-ip-OR-domain-name>:3000 otherwise.

Building from source (using Docker)

Prerequisites

You must have Docker and Docker Compose installed on your local machine. Steps

  1. To clone the Garnet repository and enter the new directory, run:

    git clone https://github.com/garnet-labs/garnet-oss.git && cd garnet-oss
  2. Generate an ENCRYPTION_KEY that is unique to your instance. Please follow the instructions on this page for creating a custom encryption key.

  3. Customize the provided docker-compose.dev.yml based on your setup. This builds images for the dashboard and server based on the dev.Dockerfile files provided in the respective /frontend and /backend directories. Provided below is an example of a template that you can customize:

version: '3'
services:
db:
container_name: postgres
environment:
# POSTGRES_DB: garnet
POSTGRES_PASSWORD: garnet
POSTGRES_USER: garnet
image: postgres:13
ports:
- 5432:5432
volumes:
- postgres-data:/var/lib/postgresql/data
backend:
container_name: garnet_backend
environment:
#these are dev mode placeholders (not for prod use)
DB_USERNAME: garnet
DB_PASSWORD: garnet
DB_NAME: garnet
DB_HOST: db
DB_TYPE: postgres
DB_LOGGING: "true"
API_DOCUMENTATION_ENABLED: "true"
FRONTEND_URL: http://localhost:3000
BACKEND_URL: http://localhost:8080/api
AUTH_JWT_EXPIRES_IN: 365 days
ENCRYPTION_KEY: <randomly-generated-256-bit-key>
AUTH_JWT_SECRET: <randomly-generated-UUID-string>
AUTH_SOCIAL_GITHUB_CLIENT_ID: <GitHub-OAuth-client-ID>
AUTH_SOCIAL_GITHUB_CLIENT_SECRET: <GitHub-OAuth-client-secret>
AUTH_SOCIAL_GITHUB_CALLBACK_URL: http://localhost:8080/api/auth/social/github/callback
TENANT_MODE: multi
build:
context: ./backend
dockerfile: dev.Dockerfile
links:
- db:db
ports:
- 8080:8080
working_dir: /app
command: npm run start:db
frontend:
container_name: garnet_frontend
build:
context: ./frontend
dockerfile: dev.Dockerfile
ports:
- 3000:3000
working_dir: /app
command: npm start
volumes:
postgres-data:

4. Run Garnet in dev mode

docker-compose -f docker-compose.dev.yml up

5. You are good to go! Once the server is up, you can navigate to the Dashboard at http://localhost:3000 (if running locally) or http://<your-instance-ip-OR-domain-name>:3000 otherwise.

Based on the above docker-compose.dev.ymlfile, a local Postgres instance will be set up. For testing purposes, it can be accessed athttp://<your-instance-ip-OR-domain-name>:5432