-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·88 lines (70 loc) · 2.55 KB
/
deploy.sh
File metadata and controls
executable file
·88 lines (70 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash
###############################################################################
# Deployment Script for DocSignals
# Purpose: Deploy to web root with manual passphrase entry
###############################################################################
set -e
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE}DocSignals Deployment Script${NC}"
echo -e "${BLUE}========================================${NC}"
# Load host config (SSH_USER, SSH_HOST)
if [ ! -f ".deploy-credentials" ]; then
echo -e "${RED}Error: .deploy-credentials file not found!${NC}"
echo -e "${YELLOW}Please create .deploy-credentials with:${NC}"
echo -e "SSH_USER=\"your_username\""
echo -e "SSH_HOST=\"your_server_ip\""
exit 1
fi
source .deploy-credentials
if [ -z "$SSH_USER" ] || [ -z "$SSH_HOST" ]; then
echo -e "${RED}Error: Missing SSH_USER or SSH_HOST in .deploy-credentials!${NC}"
exit 1
fi
# Prompt for SSH key passphrase (hidden input)
read -rs -p "SSH key passphrase: " SSH_PASSPHRASE
echo
export SSH_PASSPHRASE
# Configuration
REMOTE_PATH="/var/www/docsignals"
# Build the project
echo -e "\n${YELLOW}Building project...${NC}"
npm run build
echo -e "${GREEN}Build successful${NC}"
if [ ! -d "dist" ]; then
echo -e "${RED}Error: dist/ directory not found after build.${NC}"
exit 1
fi
# Show deployment configuration
echo -e "\n${YELLOW}Deployment Configuration:${NC}"
echo -e "Source: ${GREEN}dist/${NC}"
echo -e "Destination: ${GREEN}${SSH_USER}@${SSH_HOST}:${REMOTE_PATH}${NC}"
echo -e ""
read -p "Continue with deployment? (y/n) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo -e "${RED}Deployment cancelled.${NC}"
exit 1
fi
# Deploy using SSH_ASKPASS to supply the passphrase non-interactively to rsync
echo -e "\n${YELLOW}Deploying files...${NC}"
ASKPASS=$(mktemp /tmp/ssh_askpass.XXXXXX)
printf '#!/bin/sh\nprintf "%%s" "$SSH_PASSPHRASE"\n' > "$ASKPASS"
chmod 700 "$ASKPASS"
SSH_ASKPASS="$ASKPASS" SSH_ASKPASS_REQUIRE=force \
rsync -rltvz --delete --no-perms --no-owner --no-group --omit-dir-times \
dist/ "${SSH_USER}@${SSH_HOST}:${REMOTE_PATH}/"
RC=$?
rm -f "$ASKPASS"
if [ $RC -ne 0 ]; then
echo -e "\n${RED}Deployment failed!${NC}"
exit 1
fi
echo -e "\n${BLUE}========================================${NC}"
echo -e "${GREEN}Deployment Successful!${NC}"
echo -e "${BLUE}========================================${NC}"
echo -e "Files deployed to: ${GREEN}${SSH_USER}@${SSH_HOST}:${REMOTE_PATH}${NC}\n"