Merge pull request #69 from PentabyteDevAlign/refactor #45
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 "==========================================" |