update for pc server
This commit is contained in:
@@ -7,12 +7,17 @@ set -e # Exit on error
|
|||||||
|
|
||||||
echo "Starting deployment..."
|
echo "Starting deployment..."
|
||||||
|
|
||||||
# Check for required commands
|
# Function to run docker-compose with correct permissions
|
||||||
if ! command -v npm &> /dev/null; then
|
run_compose() {
|
||||||
echo "Error: npm is not installed. Please install Node.js and npm."
|
if groups | grep -q '\bdocker\b'; then
|
||||||
exit 1
|
docker-compose "$@"
|
||||||
|
else
|
||||||
|
echo "User not in docker group, using sudo for docker-compose..."
|
||||||
|
sudo docker-compose "$@"
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check for docker-compose
|
||||||
if ! command -v docker-compose &> /dev/null; then
|
if ! command -v docker-compose &> /dev/null; then
|
||||||
echo "Error: docker-compose is not installed."
|
echo "Error: docker-compose is not installed."
|
||||||
exit 1
|
exit 1
|
||||||
@@ -22,12 +27,9 @@ fi
|
|||||||
echo "Pulling latest changes from git..."
|
echo "Pulling latest changes from git..."
|
||||||
git pull
|
git pull
|
||||||
|
|
||||||
# 2. Build Frontend
|
# 2. Build Frontend using Docker (No local Node.js required)
|
||||||
echo "Building frontend..."
|
echo "Building frontend using Docker..."
|
||||||
cd frontend
|
run_compose run --rm frontend-builder
|
||||||
npm install
|
|
||||||
npm run build
|
|
||||||
cd ..
|
|
||||||
|
|
||||||
# 3. Deploy Frontend
|
# 3. Deploy Frontend
|
||||||
echo "Deploying frontend to /var/www/testarena..."
|
echo "Deploying frontend to /var/www/testarena..."
|
||||||
@@ -48,15 +50,8 @@ fi
|
|||||||
|
|
||||||
# 4. Restart Backend
|
# 4. Restart Backend
|
||||||
echo "Restarting backend services..."
|
echo "Restarting backend services..."
|
||||||
# Use sudo for docker-compose if needed
|
run_compose down
|
||||||
if groups | grep -q '\bdocker\b'; then
|
run_compose up -d --build
|
||||||
docker-compose down
|
|
||||||
docker-compose up -d --build
|
|
||||||
else
|
|
||||||
echo "User not in docker group, using sudo..."
|
|
||||||
sudo docker-compose down
|
|
||||||
sudo docker-compose up -d --build
|
|
||||||
fi
|
|
||||||
|
|
||||||
# 5. Reload Nginx (Optional, if config changed)
|
# 5. Reload Nginx (Optional, if config changed)
|
||||||
echo "Reloading Nginx..."
|
echo "Reloading Nginx..."
|
||||||
|
|||||||
@@ -24,12 +24,21 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
- DATABASE_URL=postgresql://user:password@db/testarena
|
- DATABASE_URL=postgresql://user:password@db/testarena
|
||||||
- SCRIPTS_DIR=/app/scripts
|
- SCRIPTS_DIR=/app/scripts
|
||||||
depends_on:
|
|
||||||
- db
|
|
||||||
networks:
|
networks:
|
||||||
- app-network
|
- app-network
|
||||||
restart: always
|
restart: always
|
||||||
|
|
||||||
|
frontend-builder:
|
||||||
|
image: node:18-alpine
|
||||||
|
working_dir: /app
|
||||||
|
volumes:
|
||||||
|
- ./frontend:/app
|
||||||
|
command: sh -c "npm install && npm run build"
|
||||||
|
profiles:
|
||||||
|
- tools
|
||||||
|
networks:
|
||||||
|
- app-network
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
app-network:
|
app-network:
|
||||||
driver: bridge
|
driver: bridge
|
||||||
|
|||||||
Reference in New Issue
Block a user