Files
ksef-pdf-generator/deploy.sh

78 lines
2.1 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# Skrypt deploymentu KSEF na serwer produkcji
# Użycie: ./deploy.sh <user@host> <remote_dir>
set -e # Exit on error
# Kolory dla output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Parametry
REMOTE_HOST="${1:-ms@10.1.1.3}"
REMOTE_DIR="${2:-/var/www/ksef}"
echo -e "${YELLOW}🚀 KSEF Deployment Script${NC}"
echo "Remote host: $REMOTE_HOST"
echo "Remote dir: $REMOTE_DIR"
echo ""
# Krok 1: Build aplikacji
echo -e "${YELLOW}1⃣ Building application...${NC}"
if [ ! -d "src/app-public" ]; then
echo -e "${RED}❌ Error: src/app-public not found. Run from project root!${NC}"
exit 1
fi
npm run build:app
if [ ! -d "dist-app" ]; then
echo -e "${RED}❌ Error: dist-app not created!${NC}"
exit 1
fi
echo -e "${GREEN}✓ Build complete${NC}"
echo ""
# Krok 2: Sprawdzenie SSH dostępu
echo -e "${YELLOW}2⃣ Checking SSH access...${NC}"
if ! ssh -q "$REMOTE_HOST" "test -d /var/www"; then
echo -e "${RED}❌ SSH connection failed or /var/www not found${NC}"
exit 1
fi
echo -e "${GREEN}✓ SSH OK${NC}"
echo ""
# Krok 3: Stworzenie folderu
echo -e "${YELLOW}3⃣ Creating remote directory...${NC}"
ssh "$REMOTE_HOST" "mkdir -p $REMOTE_DIR"
echo -e "${GREEN}✓ Directory ready${NC}"
echo ""
# Krok 4: Upload artefaktów
echo -e "${YELLOW}4⃣ Uploading files...${NC}"
scp -r dist-app/* "$REMOTE_HOST:$REMOTE_DIR/"
echo -e "${GREEN}✓ Files uploaded${NC}"
echo ""
# Krok 5: Ustaw uprawnienia
echo -e "${YELLOW}5⃣ Setting permissions...${NC}"
ssh "$REMOTE_HOST" "sudo chown -R www-data:www-data $REMOTE_DIR && sudo chmod -R 755 $REMOTE_DIR"
echo -e "${GREEN}✓ Permissions set${NC}"
echo ""
# Krok 6: Reload nginx
echo -e "${YELLOW}6⃣ Reloading nginx...${NC}"
ssh "$REMOTE_HOST" "sudo nginx -t && sudo systemctl reload nginx"
echo -e "${GREEN}✓ Nginx reloaded${NC}"
echo ""
echo -e "${GREEN}✅ Deployment complete!${NC}"
echo -e "Application running at: ${YELLOW}http://www.sic.pl/ksef/${NC}"
echo ""
echo "Logs:"
echo " Errors: ssh $REMOTE_HOST 'sudo tail -f /var/log/nginx/error.log'"
echo " Access: ssh $REMOTE_HOST 'sudo tail -f /var/log/nginx/access.log | grep ksef'"