Skip to content

Merge pull request #64 from PentabyteDevAlign/config/dns #41

Merge pull request #64 from PentabyteDevAlign/config/dns

Merge pull request #64 from PentabyteDevAlign/config/dns #41

name: Deploy Frontend to EC2
on:
push:
branches:
- dev
paths:
- 'Frontend/**'
- '.github/workflows/deploy-frontend.yml'
jobs:
deploy-frontend:
name: Deploy Frontend with Nginx
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Deploy to Frontend EC2
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.FRONTEND_HOST }}
username: ubuntu
key: ${{ secrets.FRONTEND_SSH_KEY }}
script: |
echo "=========================================="
echo "πŸš€ Starting Frontend Deployment"
echo "=========================================="
echo "πŸ“ Frontend Server: 18.141.166.14"
echo ""
# Navigate to deployment directory
cd /var/www/frontend || exit 1
# Backup old version (if exists)
if [ -d "DevAlign" ]; then
echo "πŸ“¦ Backing up current version..."
rm -rf DevAlign-backup
cp -r DevAlign DevAlign-backup
echo "βœ… Backup created"
fi
# Clone or pull latest code from dev branch
if [ -d "DevAlign" ]; then
echo "πŸ“₯ Pulling latest changes from dev branch..."
cd DevAlign
git fetch origin dev
git reset --hard origin/dev
git pull origin dev
else
echo "πŸ“₯ Cloning repository..."
git clone -b dev https://github.com/PentabyteDevAlign/DevAlign.git
cd DevAlign
fi
echo "βœ… Code updated successfully"
echo ""
# Navigate to Frontend directory
cd Frontend
# Use .env.production from repository (it's already in the code)
echo "βš™οΈ Using production environment from repository..."
if [ -f ".env.production" ]; then
echo "βœ… Production environment file found in repository"
cat .env.production
else
echo "⚠️ Warning: .env.production not found in repository"
fi
echo ""
# Install dependencies
echo "πŸ“¦ Installing dependencies..."
npm install
echo "βœ… Dependencies installed"
echo ""
# Build for production
echo "πŸ”¨ Building frontend for production..."
npm run build
# Verify build was created
if [ ! -d "dist" ]; then
echo "❌ Build failed - dist folder not found!"
exit 1
fi
echo "βœ… Build complete"
echo ""
# Show build directory contents
echo "πŸ“‚ Build output (dist/):"
ls -lh dist/ | head -10
echo ""
# Copy build to nginx serve directory
echo "πŸ“‹ Deploying build to Nginx..."
sudo rm -rf /var/www/html/*
sudo cp -r dist/* /var/www/html/
echo "βœ… Build deployed to /var/www/html/"
echo ""
# Set proper permissions
echo "πŸ” Setting permissions..."
sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www/html
echo "βœ… Permissions set"
echo ""
# Test Nginx configuration
echo "πŸ” Testing Nginx configuration..."
sudo nginx -t
# Reload Nginx
echo "πŸ”„ Reloading Nginx..."
sudo systemctl reload nginx
# Check Nginx status
echo ""
echo "πŸ“Š Nginx Status:"
sudo systemctl status nginx --no-pager | head -10
echo ""
echo "=========================================="
echo "βœ… Frontend Deployment Complete!"
echo "=========================================="
echo "🌐 Frontend URL: http://18.141.166.14"
echo "πŸ”— API Endpoint: http://13.250.231.18:5000"
echo ""
echo "πŸ“Š Check Nginx logs with:"
echo " sudo tail -f /var/log/nginx/access.log"
echo " sudo tail -f /var/log/nginx/error.log"
echo ""
echo "πŸ”„ Manage Nginx with:"
echo " sudo systemctl status nginx"
echo " sudo systemctl restart nginx"
echo "=========================================="