diff --git a/ballerine_install.sh b/ballerine_install.sh index 98cdbf8d1e..7cf3e87d08 100755 --- a/ballerine_install.sh +++ b/ballerine_install.sh @@ -1,55 +1,237 @@ -#!/usr/bin/env bash +#!/bin/bash set -e -# Example Usage: -# ./ballerine_install.sh - echo "Running as: $(id)" +# Function to display help message +show_help() { + echo "Usage: $0 [OPTIONS]" + echo "" + echo "Options:" + echo " -h, --help Display this help message." + echo " -d, --domain vite_domain Vite Domain URL." + echo " -v, --verbose Enable verbose output." + echo "" + echo "Examples:" + echo " $0 --domain example.com" + echo " $0 -v" +} + + +check_http_https() { + local input=$1 + echo "checking domain if suitable $input" + if [[ $input == *http://* && $input != *https://* ]]; then + echo "The string contains 'http' but not 'https'." + elif [[ $input == *https://* && $input != *http://* ]]; then + echo "The string contains 'https' but not 'http'." + elif [[ $input == *http://* && $input == *https://* ]]; then + echo "The string contains both 'http' and 'https'." + exit 1; + else + echo "The string contains neither 'http' nor 'https'." + exit 1; + fi +} + +deploy_ballerine() { + local input=$1 + echo "checking domain if suitable $input" + if [[ $input == *http://* && $input != *https://* ]]; then + if [[ "$OSTYPE" == "darwin"* ]]; then + cd deploy; sudo docker-compose -f docker-compose-build.yml up -d + else + cd deploy; sudo docker compose -f docker-compose-build.yml up -d + fi + elif [[ $input == *https://* && $input != *http://* ]]; then + if [[ "$OSTYPE" == "darwin"* ]]; then + cd deploy; sudo docker-compose -f docker-compose-build-https.yml up -d + else + cd deploy; sudo docker compose -f docker-compose-build-https.yml up -d + fi + elif [[ $input == *http://* && $input == *https://* ]]; then + echo "The string contains both 'http' and 'https'." + exit 1; + else + echo "The string contains neither 'http' nor 'https'." + cd deploy; sudo docker-compose -f docker-compose-build.yml up -d + fi +} + +# Check if no arguments are provided +if [ $# -eq 0 ]; then + echo "No arguments provided. Defaulting everything to localhost." +fi + + +install_docker_ubuntu(){ + echo "Installing docker..." + # Add Docker's official GPG key: + sudo apt-get update + sudo apt-get install ca-certificates curl + sudo install -m 0755 -d /etc/apt/keyrings + sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc + sudo chmod a+r /etc/apt/keyrings/docker.asc + + # Add the repository to Apt sources: + echo \ + "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \ + $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ + sudo tee /etc/apt/sources.list.d/docker.list > /dev/null + sudo apt-get update + sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin +} + + +install_docker_macos(){ + echo "Install docker using the following docs" + echo "https://docs.docker.com/desktop/setup/install/mac-install/" +} + -WORKFLOW_SERVICE_DOMAIN_NAME=$1 +check_os() { + # Get the operating system name + uname_out="$(uname -s)" -function update_frontend_build_variables() { + case "${uname_out}" in + Linux*) + # Check if the Linux distro is Ubuntu + if [ -f /etc/os-release ]; then + . /etc/os-release + if [[ $ID == "ubuntu" ]]; then + echo "The host is running Ubuntu." + install_docker_ubuntu + else + echo "The host is running a Linux distribution but not Ubuntu." + echo "We do not support this Linux distribution" + exit 1 + fi + else + echo "The host is running Linux but /etc/os-release is not available." + fi + ;; + Darwin*) + echo "The host is running macOS." + install_docker_macos + ;; + *) + echo "The operating system is not recognized." + exit 1 + ;; + esac +} + + +update_frontend_build_variables() { + echo "Updating env variables for frontend apps..." + VITE_DOMAIN_NAME="$1" ## Get frontend application env files echo "Updating frontend Build Variables" + echo "Updating vite domain with $VITE_DOMAIN_NAME" env_files=$(find ./apps -name "*.env.example") echo $env_files for i in $env_files; do echo "Updating env variables of $i" - sed -i "s/localhost/${WORKFLOW_SERVICE_DOMAIN_NAME}/g" $i + if [[ "$OSTYPE" == "darwin"* ]]; then + sed -i '' "s|http://localhost:3000|$VITE_DOMAIN_NAME|g" $i + else + sed -i "s|http://localhost:3000|$VITE_DOMAIN_NAME|g" $i + fi done - } -function update_env_docker_compose(){ - ## update env variables for docker-compose yaml + +update_docker_compose(){ + echo "Updating Docker Compose..." + WORKFLOW_SERVICE_DOMAIN=$1 + read -p "Enter the backoffice domain: " BACKOFFICE_DOMAIN + check_http_https $BACKOFFICE_DOMAIN + read -p "Enter the workflow dashboard domain: " WORKFLOW_DASHBOARD_DOMAIN + check_http_https $WORKFLOW_DASHBOARD_DOMAIN + read -p "Enter the kyb domain: " KYB_DOMAIN + check_http_https $KYB_DOMAIN + create_caddy_file $BACKOFFICE_DOMAIN $WORKFLOW_DASHBOARD_DOMAIN $KYB_DOMAIN $WORKFLOW_SERVICE_DOMAIN echo "Updating docker-compose env variables" - env_files=$(find ./deploy -name "*.env") + env_files=$(find ./deploy -name "docker-compose-build*") for i in $env_files; do - echo "Updating env variables of $i" - sed -i "s/DOMAIN_NAME=\"\"/DOMAIN_NAME=\"${WORKFLOW_SERVICE_DOMAIN_NAME}\"/g" $i; + echo "Updating env variables for KYB in $i" + if [[ "$OSTYPE" == "darwin"* ]]; then + sed -i '' "s|http://localhost:3000|$VITE_DOMAIN_NAME|g" $i + sed -i '' "s|http://localhost:5201|$KYB_DOMAIN|g" $i + sed -i '' "s|http://localhost:5200|$WORKFLOW_DASHBOARD_DOMAIN|g" $i + else + sed -i "s|http://localhost:3000|$VITE_DOMAIN_NAME|g" $i + sed -i "s|http://localhost:5201|$KYB_DOMAIN|g" $i + sed -i "s|http://localhost:5200|$WORKFLOW_DASHBOARD_DOMAIN|g" $i + fi done } -function install_docker(){ - sudo apt update; - sudo apt install -y docker.io - mkdir -p ~/.docker/cli-plugins/ - curl -SL https://github.com/docker/compose/releases/download/v2.3.3/docker-compose-linux-x86_64 -o ~/.docker/cli-plugins/docker-compose - chmod +x ~/.docker/cli-plugins/docker-compose - sudo mv ~/.docker/cli-plugins/docker-compose /usr/bin/docker-compose + +create_caddy_file(){ + echo "Creating Caddy file..." + BACKOFFICE_DOMAIN=$1 + WORKFLOW_DASHBOARD_DOMAIN=$2 + KYB_DOMAIN=$3 + WORKFLOW_SERVICE_DOMAIN=$4 + mkdir -p "$PWD/deploy/caddy" + output_file="$PWD/deploy/caddy/Caddyfile" + cat < "$output_file" +$BACKOFFICE_DOMAIN { + reverse_proxy backoffice:80 +} + +$WORKFLOW_SERVICE_DOMAIN { + reverse_proxy workflow-service:3000 } +$KYB_DOMAIN { + reverse_proxy kyb-app:80 +} -install_docker +$WORKFLOW_DASHBOARD_DOMAIN { + reverse_proxy workflows-dashboard:80 +} +EOF -if [[ ! -z "${WORKFLOW_SERVICE_DOMAIN_NAME}" ]]; then - ### Update frontend build variables only if domain_name is given - update_frontend_build_variables - update_env_docker_compose -fi +} + + +# Parse arguments +while [[ $# -gt 0 ]]; do + case "$1" in + -h|--help) + show_help + exit 0 + ;; + -d|--domain) + if [ -n "$2" ]; then + VITE_DOMAIN_NAME="$2" + echo "VITE DOMAIN: $VITE_DOMAIN_NAME" + check_http_https $VITE_DOMAIN_NAME + update_frontend_build_variables $VITE_DOMAIN_NAME + update_docker_compose $VITE_DOMAIN_NAME + shift 2 + else + echo "Error: --domain requires a domain name." + exit 1 + fi + ;; + -v|--verbose) + VERBOSE=true + echo "Verbose mode enabled." + shift + ;; + *) + echo "Unknown option: $1" + echo "Use -h or --help for usage information." + exit 1 + ;; + esac +done + +check_os -## Bring docker-container up -cd deploy; sudo docker-compose -f docker-compose-build.yml up -d +deploy_ballerine $VITE_DOMAIN_NAME diff --git a/deploy/docker-compose-build-https.yml b/deploy/docker-compose-build-https.yml index 2a9bf9f998..76265fc234 100644 --- a/deploy/docker-compose-build-https.yml +++ b/deploy/docker-compose-build-https.yml @@ -23,12 +23,13 @@ services: - ballerine-workflow-service restart: on-failure environment: - VITE_API_URL: 'http://${DOMAIN_NAME:-localhost:3000}/api/v1/' + VITE_API_URL: 'http://localhost:3000/api/v1/' VITE_KYB_DEFINITION_ID: 'kyb_parent_kyc_session_example' ballerine-workflow-service: container_name: workflow-service platform: linux/amd64 - image: ghcr.io/ballerine-io/workflows-service:latest + build: + context: ../services/workflows-service/ command: - /bin/sh - -c @@ -49,10 +50,10 @@ services: DB_USER: ${DB_USER} DB_PASSWORD: ${DB_PASSWORD} SESSION_SECRET: ${SESSION_SECRET} - BACKOFFICE_CORS_ORIGIN: http://${DOMAIN_NAME:-localhost}:${BACKOFFICE_PORT} - WORKFLOW_DASHBOARD_CORS_ORIGIN: http://${DOMAIN_NAME:-localhost}:${WORKFLOW_DASHBOARD_PORT} + BACKOFFICE_CORS_ORIGIN: http://localhost:5137 + WORKFLOW_DASHBOARD_CORS_ORIGIN: http://localhost:5200 PORT: ${WORKFLOW_SVC_PORT} - KYB_EXAMPLE_CORS_ORIGIN: http://${DOMAIN_NAME:-localhost}:${KYB_APP_PORT} + KYB_EXAMPLE_CORS_ORIGIN: http://localhost:5201 APP_API_URL: https://alon.ballerine.dev EMAIL_API_TOKEN: '' EMAIL_API_URL: https://api.sendgrid.com/v3/mail/send @@ -97,6 +98,7 @@ services: timeout: 45s interval: 10s retries: 10 + restart: on-failure caddy: image: caddy:latest restart: unless-stopped @@ -109,5 +111,6 @@ services: - "../deploy/./caddy/site:/srv" - "../deploy/caddy/caddy_data:/data" - "../deploy/caddy/caddy_config:/config" + restart: on-failure volumes: postgres15: ~ diff --git a/deploy/docker-compose-build.yml b/deploy/docker-compose-build.yml index 1c094cf596..a56529633f 100644 --- a/deploy/docker-compose-build.yml +++ b/deploy/docker-compose-build.yml @@ -23,7 +23,7 @@ services: - ballerine-workflow-service restart: on-failure environment: - VITE_API_URL: 'http://${DOMAIN_NAME:-localhost:3000}/api/v1/' + VITE_API_URL: 'http://localhost:3000/api/v1/' VITE_KYB_DEFINITION_ID: 'kyb_parent_kyc_session_example' ballerine-workflow-service: container_name: workflow-service @@ -50,10 +50,10 @@ services: DB_USER: ${DB_USER} DB_PASSWORD: ${DB_PASSWORD} SESSION_SECRET: ${SESSION_SECRET} - BACKOFFICE_CORS_ORIGIN: http://${DOMAIN_NAME:-localhost}:${BACKOFFICE_PORT} - WORKFLOW_DASHBOARD_CORS_ORIGIN: http://${DOMAIN_NAME:-localhost}:${WORKFLOW_DASHBOARD_PORT} + BACKOFFICE_CORS_ORIGIN: http://localhost:5137 + WORKFLOW_DASHBOARD_CORS_ORIGIN: http://localhost:5200 PORT: ${WORKFLOW_SVC_PORT} - KYB_EXAMPLE_CORS_ORIGIN: http://${DOMAIN_NAME:-localhost}:${KYB_APP_PORT} + KYB_EXAMPLE_CORS_ORIGIN: http://localhost:5201 APP_API_URL: https://alon.ballerine.dev EMAIL_API_TOKEN: '' EMAIL_API_URL: https://api.sendgrid.com/v3/mail/send @@ -98,5 +98,6 @@ services: timeout: 45s interval: 10s retries: 10 + restart: on-failure volumes: postgres15: ~