68 lines
1.8 KiB
Bash
Executable File
68 lines
1.8 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# This script deploys the portfolio website from Gitea to the VPS
|
|
|
|
# Load environment variables
|
|
if [ -f .env ]; then
|
|
source .env
|
|
else
|
|
echo "Error: .env file not found. Please create it based on .env.example."
|
|
exit 1
|
|
fi
|
|
|
|
# Check if sshpass is installed
|
|
if ! command -v sshpass &> /dev/null; then
|
|
echo "Error: sshpass is not installed. Please run 'sudo apt-get install sshpass' first."
|
|
exit 1
|
|
fi
|
|
|
|
# Set SSH and SCP commands with password
|
|
SSH_CMD="sshpass -p $SERVER_PASSWORD ssh -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP"
|
|
SCP_CMD="sshpass -p $SERVER_PASSWORD scp -o StrictHostKeyChecking=no"
|
|
|
|
# Set variables
|
|
REMOTE_DIR="/var/www/boilerhaus.org"
|
|
TEMP_DIR="./portfolio-temp"
|
|
|
|
# Create a temporary directory for the website files
|
|
echo "Creating temporary directory..."
|
|
mkdir -p $TEMP_DIR
|
|
|
|
# Check if TypeScript is installed
|
|
if ! command -v tsc &> /dev/null; then
|
|
echo "Installing TypeScript globally..."
|
|
npm install -g typescript
|
|
fi
|
|
|
|
# Build the project
|
|
echo "Building the project..."
|
|
npm run build
|
|
|
|
# Check if dist directory exists
|
|
if [ ! -d "dist" ]; then
|
|
echo "Error: Build failed. The dist directory does not exist."
|
|
exit 1
|
|
fi
|
|
|
|
# Create a tarball of the built files
|
|
echo "Creating tarball of the built files..."
|
|
cd dist
|
|
tar -czf ../portfolio-dist.tar.gz .
|
|
cd ..
|
|
|
|
# Upload the tarball to the server
|
|
echo "Uploading to server..."
|
|
$SCP_CMD portfolio-dist.tar.gz $SERVER_USER@$SERVER_IP:/tmp/
|
|
|
|
# Extract the tarball on the server
|
|
echo "Extracting files on server..."
|
|
$SSH_CMD "mkdir -p $REMOTE_DIR && \
|
|
tar -xzf /tmp/portfolio-dist.tar.gz -C $REMOTE_DIR && \
|
|
chown -R www-data:www-data $REMOTE_DIR && \
|
|
rm /tmp/portfolio-dist.tar.gz"
|
|
|
|
# Clean up local files
|
|
echo "Cleaning up..."
|
|
rm -rf $TEMP_DIR portfolio-dist.tar.gz
|
|
|
|
echo "Portfolio website deployed successfully!" |