-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-and-deploy.sh
More file actions
executable file
·61 lines (47 loc) · 1.72 KB
/
Copy pathsetup-and-deploy.sh
File metadata and controls
executable file
·61 lines (47 loc) · 1.72 KB
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
#!/bin/bash
# Configuration
REACT_APP_DIR="./Frontend"
DOCKER_COMPOSE_FILE="./docker-compose.yml"
# Find the Nginx config file (assuming only one file matches the pattern)
NGINX_CONF_FILE=$(find . -maxdepth 1 -name "nginx-*.conf" -print -quit)
# Check if an Nginx config file was found
if [ -z "$NGINX_CONF_FILE" ]; then
echo "No Nginx configuration file found."
exit 1
fi
# Extract the filename from the path
NGINX_CONF_FILENAME=$(basename "$NGINX_CONF_FILE")
# Extract app name from Nginx config file name (assumes format nginx-appname.conf)
APP_FOLDER_NAME=$(echo $NGINX_CONF_FILENAME | sed -e 's/^nginx-//' -e 's/\.conf$//')
NGINX_HTML_DIR="/usr/share/nginx/html/$APP_FOLDER_NAME"
# Copy Nginx configuration file and enable it
echo "Copying and setting up nginx configuration files..."
sudo cp $NGINX_CONF_FILE /etc/nginx/sites-available/
sudo ln -s /etc/nginx/sites-available/$NGINX_CONF_FILENAME /etc/nginx/sites-enabled/
# Reload or start Nginx
if sudo systemctl is-active --quiet nginx; then
echo "Reloading Nginx..."
sudo systemctl reload nginx
else
echo "Starting Nginx..."
sudo systemctl start nginx
fi
# Build the React application
echo "Building React application..."
cd $REACT_APP_DIR
npm install
npm run build
# Check if React build was successful
if [ $? -ne 0 ]; then
echo "React build failed."
exit 1
fi
cd - > /dev/null
# Create the app directory in Nginx's html folder and copy build files
echo "Deploying the app to Nginx..."
sudo mkdir -p $NGINX_HTML_DIR
sudo cp -r $REACT_APP_DIR/build/* $NGINX_HTML_DIR/
# Run Docker Compose for PostgreSQL and Backend
echo "Starting Docker services..."
docker-compose -f $DOCKER_COMPOSE_FILE up -d --build
echo "Initial deployment completed successfully!"