From 15aa1cb943bb26b701bfbc87b68ce89e3bda7585 Mon Sep 17 00:00:00 2001 From: Pratapa Lakshmi Date: Sun, 1 Dec 2024 18:35:22 +0530 Subject: [PATCH 1/6] chore: automate ballerine deployment --- ballerine_install.sh | 177 ++++++++++++++++++++++++++------ deploy/docker-compose-build.yml | 9 +- 2 files changed, 151 insertions(+), 35 deletions(-) diff --git a/ballerine_install.sh b/ballerine_install.sh index 98cdbf8d1e..36a29174e8 100755 --- a/ballerine_install.sh +++ b/ballerine_install.sh @@ -1,55 +1,170 @@ -#!/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 +} + + +# Check if no arguments are provided +if [ $# -eq 0 ]; then + echo "No arguments provided. Defaulting everything to localhost." +fi + + +install_docker_ubuntu(){ + # 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 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/" +} + +check_os() { + # Get the operating system name + uname_out="$(uname -s)" + + 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" + 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." + ;; + esac +} -WORKFLOW_SERVICE_DOMAIN_NAME=$1 -function update_frontend_build_variables() { +update_frontend_build_variables() { + 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 + sed -i '' "s|http://localhost:3000|$VITE_DOMAIN_NAME|g" $i done } -function update_env_docker_compose(){ - ## update env variables for docker-compose yaml + +update_docker_compose(){ + 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 echo "Updating docker-compose env variables" - env_files=$(find ./deploy -name "*.env") + env_files=$(find ./deploy -name "docker-compose-build.yml") 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; - 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 -} + echo "Updating env variables for KYB in $i" + sed -i '' "s|http://localhost:5201|$KYB_DOMAIN|g" $i + echo "Updating env variables for Workflow Dashboard in $i" + sed -i '' "s|http://localhost:5200|$WORKFLOW_DASHBOARD_DOMAIN|g" $i -install_docker + echo "Updating env variables for Backoffice in $i" + sed -i '' "s|http://localhost:5137|$BACKOFFICE_DOMAIN|g" $i + done +} -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 + 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 -## Bring docker-container up -cd deploy; sudo docker-compose -f docker-compose-build.yml up -d +check_os +# ## Bring docker-container up +# cd deploy; sudo docker-compose -f docker-compose-build.yml up -d 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: ~ From 59477bc26aa7a1787d3defb818d7d17841422ef2 Mon Sep 17 00:00:00 2001 From: Pratapa Lakshmi Date: Thu, 5 Dec 2024 17:34:44 +0530 Subject: [PATCH 2/6] chore: make changes to docker-compose https file --- deploy/docker-compose-build-https.yml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) 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: ~ From 0ad21b57e725937d42fa7e984546fb43f8718bdc Mon Sep 17 00:00:00 2001 From: Pratapa Lakshmi Date: Thu, 5 Dec 2024 17:46:54 +0530 Subject: [PATCH 3/6] chore: automate ballerine installation --- ballerine_install.sh | 60 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 56 insertions(+), 4 deletions(-) diff --git a/ballerine_install.sh b/ballerine_install.sh index 36a29174e8..34976dcebb 100755 --- a/ballerine_install.sh +++ b/ballerine_install.sh @@ -34,6 +34,21 @@ check_http_https() { fi } +deploy_ballerine() { + local input=$1 + echo "checking domain if suitable $input" + if [[ $input == *http://* && $input != *https://* ]]; then + cd deploy; sudo docker-compose -f docker-compose-build.yml up -d + elif [[ $input == *https://* && $input != *http://* ]]; then + cd deploy; sudo docker-compose -f docker-compose-build-https.yml up -d + 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 +} # Check if no arguments are provided if [ $# -eq 0 ]; then @@ -42,6 +57,7 @@ fi install_docker_ubuntu(){ + echo "Installing docker..." # Add Docker's official GPG key: sudo apt-get update sudo apt-get install ca-certificates curl @@ -58,11 +74,13 @@ install_docker_ubuntu(){ sudo apt-get install 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/" } + check_os() { # Get the operating system name uname_out="$(uname -s)" @@ -95,6 +113,7 @@ check_os() { 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" @@ -111,14 +130,17 @@ update_frontend_build_variables() { 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 "docker-compose-build.yml") + env_files=$(find ./deploy -name "docker-compose-build*") for i in $env_files; do echo "Updating env variables for KYB in $i" @@ -132,6 +154,36 @@ update_docker_compose(){ done } + +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 +} + +$WORKFLOW_DASHBOARD_DOMAIN { + reverse_proxy workflows-dashboard:80 +} +EOF + +} + + # Parse arguments while [[ $# -gt 0 ]]; do case "$1" in @@ -145,7 +197,7 @@ while [[ $# -gt 0 ]]; do echo "VITE DOMAIN: $VITE_DOMAIN_NAME" check_http_https $VITE_DOMAIN_NAME update_frontend_build_variables $VITE_DOMAIN_NAME - update_docker_compose + update_docker_compose $VITE_DOMAIN_NAME shift 2 else echo "Error: --domain requires a domain name." @@ -166,5 +218,5 @@ while [[ $# -gt 0 ]]; do done check_os -# ## Bring docker-container up -# cd deploy; sudo docker-compose -f docker-compose-build.yml up -d + +deploy_ballerine $VITE_DOMAIN_NAME From d8269c5efe60bcd1746f8b77afe116907975d376 Mon Sep 17 00:00:00 2001 From: Pratapa Lakshmi Date: Thu, 5 Dec 2024 17:57:27 +0530 Subject: [PATCH 4/6] chore: update sed commands --- ballerine_install.sh | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/ballerine_install.sh b/ballerine_install.sh index 34976dcebb..1a158b0ef1 100755 --- a/ballerine_install.sh +++ b/ballerine_install.sh @@ -96,6 +96,7 @@ check_os() { 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." @@ -107,6 +108,7 @@ check_os() { ;; *) echo "The operating system is not recognized." + exit 1 ;; esac } @@ -123,9 +125,12 @@ update_frontend_build_variables() { for i in $env_files; do echo "Updating env variables of $i" - sed -i '' "s|http://localhost:3000|$VITE_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 - } @@ -144,13 +149,15 @@ update_docker_compose(){ for i in $env_files; do echo "Updating env variables for KYB in $i" - sed -i '' "s|http://localhost:5201|$KYB_DOMAIN|g" $i - - echo "Updating env variables for Workflow Dashboard in $i" - sed -i '' "s|http://localhost:5200|$WORKFLOW_DASHBOARD_DOMAIN|g" $i - - echo "Updating env variables for Backoffice in $i" - sed -i '' "s|http://localhost:5137|$BACKOFFICE_DOMAIN|g" $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 } From d7d099c973e085ae577deea78d8c7bc7ef4bb7da Mon Sep 17 00:00:00 2001 From: Pratapa Lakshmi Date: Thu, 5 Dec 2024 18:16:49 +0530 Subject: [PATCH 5/6] chore: deploy ballerine for default option --- ballerine_install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ballerine_install.sh b/ballerine_install.sh index 1a158b0ef1..fe5bf6900c 100755 --- a/ballerine_install.sh +++ b/ballerine_install.sh @@ -46,7 +46,7 @@ deploy_ballerine() { exit 1; else echo "The string contains neither 'http' nor 'https'." - exit 1; + cd deploy; sudo docker-compose -f docker-compose-build.yml up -d fi } From 849e36992fbe45e8f1531e03e6857d079cef93ca Mon Sep 17 00:00:00 2001 From: Pratapa Lakshmi Date: Thu, 5 Dec 2024 23:59:41 +0530 Subject: [PATCH 6/6] chore: cosmetic changes to work with ubuntu --- ballerine_install.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ballerine_install.sh b/ballerine_install.sh index fe5bf6900c..7cf3e87d08 100755 --- a/ballerine_install.sh +++ b/ballerine_install.sh @@ -38,9 +38,17 @@ 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; @@ -71,7 +79,7 @@ install_docker_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 docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin + sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin }