-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlaunch.sh
executable file
·77 lines (62 loc) · 1.66 KB
/
launch.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/sh
# Function to handle script termination
cleanup() {
echo "Script terminated by user."
exit 1
}
# Trap SIGINT signal (Ctrl+C)
trap cleanup SIGINT
# Function to check if the application is ready
check_application_ready() {
URL=$1
while ! curl -s "$URL" > /dev/null ; do
echo "Waiting for the application to be ready..."
sleep 5
done
echo "Application is ready!"
}
# Function to load environment variables from .env file
load_env_file() {
ENV_FILE=$1
if [ -f "$ENV_FILE" ]; then
export $(grep -v '^#' "$ENV_FILE" | xargs)
else
echo ".env file not found in the directory."
exit 1
fi
}
# Check if the directory argument is provided
if [ -z "$1" ]; then
echo "Usage: $0 <directory>"
exit 1
fi
# Assign the directory argument to a variable
DIRECTORY=$1
# Check if the directory exists
if [ ! -d "$DIRECTORY" ]; then
echo "Directory $DIRECTORY does not exist."
exit 1
fi
# Navigate to the specified directory
cd "$DIRECTORY" || exit
# Check if the docker-compose.yaml file exists in the directory
if [ ! -f "docker-compose.yaml" ]; then
echo "docker-compose.yaml file not found in directory $DIRECTORY."
exit 1
fi
# Load environment variables from .env file
ENV_FILE=".env"
load_env_file "$ENV_FILE"
# Run the docker-compose command
docker compose up -d
# Check if the necessary environment variables are set
if [ -z "$SERVICE_PORT" ]; then
echo "SERVICE_PORT must be set in the .env file."
exit 1
fi
# URL to check
URL="http://localhost:$SERVICE_PORT"
# Wait until the application is ready
check_application_ready "$URL"
# Output the port the application is running on
echo "Application is running on port: $SERVICE_PORT"