Skip to content

Commit 496be43

Browse files
chore: automate ballerine deployment
1 parent 995102f commit 496be43

File tree

3 files changed

+223
-37
lines changed

3 files changed

+223
-37
lines changed

ballerine_install.sh

Lines changed: 210 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,237 @@
1-
#!/usr/bin/env bash
1+
#!/bin/bash
22

33
set -e
44

5-
# Example Usage:
6-
# ./ballerine_install.sh <VITE_API_URL_DOMAIN_NAME>
7-
85
echo "Running as: $(id)"
6+
# Function to display help message
7+
show_help() {
8+
echo "Usage: $0 [OPTIONS]"
9+
echo ""
10+
echo "Options:"
11+
echo " -h, --help Display this help message."
12+
echo " -d, --domain vite_domain Vite Domain URL."
13+
echo " -v, --verbose Enable verbose output."
14+
echo ""
15+
echo "Examples:"
16+
echo " $0 --domain example.com"
17+
echo " $0 -v"
18+
}
19+
20+
21+
check_http_https() {
22+
local input=$1
23+
echo "checking domain if suitable $input"
24+
if [[ $input == *http://* && $input != *https://* ]]; then
25+
echo "The string contains 'http' but not 'https'."
26+
elif [[ $input == *https://* && $input != *http://* ]]; then
27+
echo "The string contains 'https' but not 'http'."
28+
elif [[ $input == *http://* && $input == *https://* ]]; then
29+
echo "The string contains both 'http' and 'https'."
30+
exit 1;
31+
else
32+
echo "The string contains neither 'http' nor 'https'."
33+
exit 1;
34+
fi
35+
}
36+
37+
deploy_ballerine() {
38+
local input=$1
39+
echo "checking domain if suitable $input"
40+
if [[ $input == *http://* && $input != *https://* ]]; then
41+
if [[ "$OSTYPE" == "darwin"* ]]; then
42+
cd deploy; sudo docker-compose -f docker-compose-build.yml up -d
43+
else
44+
cd deploy; sudo docker compose -f docker-compose-build.yml up -d
45+
fi
46+
elif [[ $input == *https://* && $input != *http://* ]]; then
47+
if [[ "$OSTYPE" == "darwin"* ]]; then
48+
cd deploy; sudo docker-compose -f docker-compose-build-https.yml up -d
49+
else
50+
cd deploy; sudo docker compose -f docker-compose-build-https.yml up -d
51+
fi
52+
elif [[ $input == *http://* && $input == *https://* ]]; then
53+
echo "The string contains both 'http' and 'https'."
54+
exit 1;
55+
else
56+
echo "The string contains neither 'http' nor 'https'."
57+
cd deploy; sudo docker-compose -f docker-compose-build.yml up -d
58+
fi
59+
}
60+
61+
# Check if no arguments are provided
62+
if [ $# -eq 0 ]; then
63+
echo "No arguments provided. Defaulting everything to localhost."
64+
fi
65+
66+
67+
install_docker_ubuntu(){
68+
echo "Installing docker..."
69+
# Add Docker's official GPG key:
70+
sudo apt-get update
71+
sudo apt-get install ca-certificates curl
72+
sudo install -m 0755 -d /etc/apt/keyrings
73+
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
74+
sudo chmod a+r /etc/apt/keyrings/docker.asc
75+
76+
# Add the repository to Apt sources:
77+
echo \
78+
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
79+
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
80+
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
81+
sudo apt-get update
82+
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
83+
}
84+
85+
86+
install_docker_macos(){
87+
echo "Install docker using the following docs"
88+
echo "https://docs.docker.com/desktop/setup/install/mac-install/"
89+
}
90+
991

10-
WORKFLOW_SERVICE_DOMAIN_NAME=$1
92+
check_os() {
93+
# Get the operating system name
94+
uname_out="$(uname -s)"
1195

12-
function update_frontend_build_variables() {
96+
case "${uname_out}" in
97+
Linux*)
98+
# Check if the Linux distro is Ubuntu
99+
if [ -f /etc/os-release ]; then
100+
. /etc/os-release
101+
if [[ $ID == "ubuntu" ]]; then
102+
echo "The host is running Ubuntu."
103+
install_docker_ubuntu
104+
else
105+
echo "The host is running a Linux distribution but not Ubuntu."
106+
echo "We do not support this Linux distribution"
107+
exit 1
108+
fi
109+
else
110+
echo "The host is running Linux but /etc/os-release is not available."
111+
fi
112+
;;
113+
Darwin*)
114+
echo "The host is running macOS."
115+
install_docker_macos
116+
;;
117+
*)
118+
echo "The operating system is not recognized."
119+
exit 1
120+
;;
121+
esac
122+
}
123+
124+
125+
update_frontend_build_variables() {
126+
echo "Updating env variables for frontend apps..."
127+
VITE_DOMAIN_NAME="$1"
13128
## Get frontend application env files
14129
echo "Updating frontend Build Variables"
130+
echo "Updating vite domain with $VITE_DOMAIN_NAME"
15131
env_files=$(find ./apps -name "*.env.example")
16132
echo $env_files
17133
for i in $env_files;
18134
do
19135
echo "Updating env variables of $i"
20-
sed -i "s/localhost/${WORKFLOW_SERVICE_DOMAIN_NAME}/g" $i
136+
if [[ "$OSTYPE" == "darwin"* ]]; then
137+
sed -i '' "s|http://localhost:3000|$VITE_DOMAIN_NAME|g" $i
138+
else
139+
sed -i "s|http://localhost:3000|$VITE_DOMAIN_NAME|g" $i
140+
fi
21141
done
22-
23142
}
24143

25-
function update_env_docker_compose(){
26-
## update env variables for docker-compose yaml
144+
145+
update_docker_compose(){
146+
echo "Updating Docker Compose..."
147+
WORKFLOW_SERVICE_DOMAIN=$1
148+
read -p "Enter the backoffice domain: " BACKOFFICE_DOMAIN
149+
check_http_https $BACKOFFICE_DOMAIN
150+
read -p "Enter the workflow dashboard domain: " WORKFLOW_DASHBOARD_DOMAIN
151+
check_http_https $WORKFLOW_DASHBOARD_DOMAIN
152+
read -p "Enter the kyb domain: " KYB_DOMAIN
153+
check_http_https $KYB_DOMAIN
154+
create_caddy_file $BACKOFFICE_DOMAIN $WORKFLOW_DASHBOARD_DOMAIN $KYB_DOMAIN $WORKFLOW_SERVICE_DOMAIN
27155
echo "Updating docker-compose env variables"
28-
env_files=$(find ./deploy -name "*.env")
156+
env_files=$(find ./deploy -name "docker-compose-build*")
29157
for i in $env_files;
30158
do
31-
echo "Updating env variables of $i"
32-
sed -i "s/DOMAIN_NAME=\"\"/DOMAIN_NAME=\"${WORKFLOW_SERVICE_DOMAIN_NAME}\"/g" $i;
159+
echo "Updating env variables for KYB in $i"
160+
if [[ "$OSTYPE" == "darwin"* ]]; then
161+
sed -i '' "s|http://localhost:3000|$VITE_DOMAIN_NAME|g" $i
162+
sed -i '' "s|http://localhost:5201|$KYB_DOMAIN|g" $i
163+
sed -i '' "s|http://localhost:5200|$WORKFLOW_DASHBOARD_DOMAIN|g" $i
164+
else
165+
sed -i "s|http://localhost:3000|$VITE_DOMAIN_NAME|g" $i
166+
sed -i "s|http://localhost:5201|$KYB_DOMAIN|g" $i
167+
sed -i "s|http://localhost:5200|$WORKFLOW_DASHBOARD_DOMAIN|g" $i
168+
fi
33169
done
34170
}
35171

36-
function install_docker(){
37-
sudo apt update;
38-
sudo apt install -y docker.io
39-
mkdir -p ~/.docker/cli-plugins/
40-
curl -SL https://github.com/docker/compose/releases/download/v2.3.3/docker-compose-linux-x86_64 -o ~/.docker/cli-plugins/docker-compose
41-
chmod +x ~/.docker/cli-plugins/docker-compose
42-
sudo mv ~/.docker/cli-plugins/docker-compose /usr/bin/docker-compose
172+
173+
create_caddy_file(){
174+
echo "Creating Caddy file..."
175+
BACKOFFICE_DOMAIN=$1
176+
WORKFLOW_DASHBOARD_DOMAIN=$2
177+
KYB_DOMAIN=$3
178+
WORKFLOW_SERVICE_DOMAIN=$4
179+
mkdir -p "$PWD/deploy/caddy"
180+
output_file="$PWD/deploy/caddy/Caddyfile"
181+
cat <<EOF > "$output_file"
182+
$BACKOFFICE_DOMAIN {
183+
reverse_proxy backoffice:80
184+
}
185+
186+
$WORKFLOW_SERVICE_DOMAIN {
187+
reverse_proxy workflow-service:3000
43188
}
44189
190+
$KYB_DOMAIN {
191+
reverse_proxy kyb-app:80
192+
}
45193
46-
install_docker
194+
$WORKFLOW_DASHBOARD_DOMAIN {
195+
reverse_proxy workflows-dashboard:80
196+
}
197+
EOF
47198

48-
if [[ ! -z "${WORKFLOW_SERVICE_DOMAIN_NAME}" ]]; then
49-
### Update frontend build variables only if domain_name is given
50-
update_frontend_build_variables
51-
update_env_docker_compose
52-
fi
199+
}
200+
201+
202+
# Parse arguments
203+
while [[ $# -gt 0 ]]; do
204+
case "$1" in
205+
-h|--help)
206+
show_help
207+
exit 0
208+
;;
209+
-d|--domain)
210+
if [ -n "$2" ]; then
211+
VITE_DOMAIN_NAME="$2"
212+
echo "VITE DOMAIN: $VITE_DOMAIN_NAME"
213+
check_http_https $VITE_DOMAIN_NAME
214+
update_frontend_build_variables $VITE_DOMAIN_NAME
215+
update_docker_compose $VITE_DOMAIN_NAME
216+
shift 2
217+
else
218+
echo "Error: --domain requires a domain name."
219+
exit 1
220+
fi
221+
;;
222+
-v|--verbose)
223+
VERBOSE=true
224+
echo "Verbose mode enabled."
225+
shift
226+
;;
227+
*)
228+
echo "Unknown option: $1"
229+
echo "Use -h or --help for usage information."
230+
exit 1
231+
;;
232+
esac
233+
done
234+
235+
check_os
53236

54-
## Bring docker-container up
55-
cd deploy; sudo docker-compose -f docker-compose-build.yml up -d
237+
deploy_ballerine $VITE_DOMAIN_NAME

deploy/docker-compose-build-https.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ services:
2323
- ballerine-workflow-service
2424
restart: on-failure
2525
environment:
26-
VITE_API_URL: 'http://${DOMAIN_NAME:-localhost:3000}/api/v1/'
26+
VITE_API_URL: 'http://localhost:3000/api/v1/'
2727
VITE_KYB_DEFINITION_ID: 'kyb_parent_kyc_session_example'
2828
ballerine-workflow-service:
2929
container_name: workflow-service
3030
platform: linux/amd64
31-
image: ghcr.io/ballerine-io/workflows-service:latest
31+
build:
32+
context: ../services/workflows-service/
3233
command:
3334
- /bin/sh
3435
- -c
@@ -49,10 +50,10 @@ services:
4950
DB_USER: ${DB_USER}
5051
DB_PASSWORD: ${DB_PASSWORD}
5152
SESSION_SECRET: ${SESSION_SECRET}
52-
BACKOFFICE_CORS_ORIGIN: http://${DOMAIN_NAME:-localhost}:${BACKOFFICE_PORT}
53-
WORKFLOW_DASHBOARD_CORS_ORIGIN: http://${DOMAIN_NAME:-localhost}:${WORKFLOW_DASHBOARD_PORT}
53+
BACKOFFICE_CORS_ORIGIN: http://localhost:5137
54+
WORKFLOW_DASHBOARD_CORS_ORIGIN: http://localhost:5200
5455
PORT: ${WORKFLOW_SVC_PORT}
55-
KYB_EXAMPLE_CORS_ORIGIN: http://${DOMAIN_NAME:-localhost}:${KYB_APP_PORT}
56+
KYB_EXAMPLE_CORS_ORIGIN: http://localhost:5201
5657
APP_API_URL: https://alon.ballerine.dev
5758
EMAIL_API_TOKEN: ''
5859
EMAIL_API_URL: https://api.sendgrid.com/v3/mail/send
@@ -97,6 +98,7 @@ services:
9798
timeout: 45s
9899
interval: 10s
99100
retries: 10
101+
restart: on-failure
100102
caddy:
101103
image: caddy:latest
102104
restart: unless-stopped
@@ -109,5 +111,6 @@ services:
109111
- "../deploy/./caddy/site:/srv"
110112
- "../deploy/caddy/caddy_data:/data"
111113
- "../deploy/caddy/caddy_config:/config"
114+
restart: on-failure
112115
volumes:
113116
postgres15: ~

deploy/docker-compose-build.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ services:
2323
- ballerine-workflow-service
2424
restart: on-failure
2525
environment:
26-
VITE_API_URL: 'http://${DOMAIN_NAME:-localhost:3000}/api/v1/'
26+
VITE_API_URL: 'http://localhost:3000/api/v1/'
2727
VITE_KYB_DEFINITION_ID: 'kyb_parent_kyc_session_example'
2828
ballerine-workflow-service:
2929
container_name: workflow-service
@@ -50,10 +50,10 @@ services:
5050
DB_USER: ${DB_USER}
5151
DB_PASSWORD: ${DB_PASSWORD}
5252
SESSION_SECRET: ${SESSION_SECRET}
53-
BACKOFFICE_CORS_ORIGIN: http://${DOMAIN_NAME:-localhost}:${BACKOFFICE_PORT}
54-
WORKFLOW_DASHBOARD_CORS_ORIGIN: http://${DOMAIN_NAME:-localhost}:${WORKFLOW_DASHBOARD_PORT}
53+
BACKOFFICE_CORS_ORIGIN: http://localhost:5137
54+
WORKFLOW_DASHBOARD_CORS_ORIGIN: http://localhost:5200
5555
PORT: ${WORKFLOW_SVC_PORT}
56-
KYB_EXAMPLE_CORS_ORIGIN: http://${DOMAIN_NAME:-localhost}:${KYB_APP_PORT}
56+
KYB_EXAMPLE_CORS_ORIGIN: http://localhost:5201
5757
APP_API_URL: https://alon.ballerine.dev
5858
EMAIL_API_TOKEN: ''
5959
EMAIL_API_URL: https://api.sendgrid.com/v3/mail/send
@@ -98,5 +98,6 @@ services:
9898
timeout: 45s
9999
interval: 10s
100100
retries: 10
101+
restart: on-failure
101102
volumes:
102103
postgres15: ~

0 commit comments

Comments
 (0)