-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathbuild-deploy.sh
More file actions
executable file
·97 lines (83 loc) · 3 KB
/
Copy pathbuild-deploy.sh
File metadata and controls
executable file
·97 lines (83 loc) · 3 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
89
90
91
92
93
94
95
96
97
#!/bin/bash
# build-deploy.sh - Wrapper script that runs build.sh and deploy.sh in sequence
# This script maintains backward compatibility with the original build-deploy.sh
set -e # Exit immediately if a command exits with a non-zero status
# Function to print section headers
print_header() {
echo "======================================================"
echo "🚀 $1"
echo "======================================================"
}
print_header "BUILD AND DEPLOY WRAPPER"
echo "This script will run build.sh and deploy.sh in sequence."
echo "You can also run them separately:"
echo " ./build.sh [prod|staging] [version_tag]"
echo " ./deploy.sh [prod|staging] [machine_name] [version_tag] [subdomain]"
echo ""
# Check command line arguments
if [ $# -lt 3 ] || [ $# -gt 5 ]; then
echo "Error: Please specify environment, host, and subdomain"
echo "Usage: $0 [prod|staging] [machine_name] [subdomain]"
exit 1
fi
# Validate first argument (environment)
if [ "$1" != "prod" ] && [ "$1" != "staging" ]; then
echo "Error: First argument must be either 'prod' or 'staging'"
echo "Usage: $0 [prod|staging] [machine_name] [subdomain]"
exit 1
fi
# Validate second argument (machine). deploy.sh resolves any label-shaped
# name through SERVER_HOSTS_JSON, so adding a machine must not mean editing
# a list here.
case "$2" in
"" | *[!a-zA-Z0-9-]*)
echo "Error: machine name must be letters, digits and hyphens, got: '$2'"
echo "Usage: $0 [prod|staging] [machine_name] [subdomain]"
exit 1
;;
esac
# Validate third argument (subdomain). It becomes a DNS label and a Docker
# container name downstream, so hold it to the RFC 1123 label rules here rather
# than after the build has already run.
case "$3" in
"")
echo "Error: Subdomain is required"
echo "Usage: $0 [prod|staging] [machine_name] [subdomain]"
exit 1
;;
*[!a-zA-Z0-9-]* | -* | *-)
echo "Error: Subdomain must be a valid hostname label - letters, digits and interior hyphens only - got: '$3'"
echo "Usage: $0 [prod|staging] [machine_name] [subdomain]"
exit 1
;;
esac
if [ "${#3}" -gt 63 ]; then
echo "Error: Subdomain must be at most 63 characters, got ${#3}: '$3'"
echo "Usage: $0 [prod|staging] [machine_name] [subdomain]"
exit 1
fi
# Generate version tag
VERSION_TAG=$(date +"%Y%m%d-%H%M%S")
echo "Generated version tag: $VERSION_TAG"
# Extract arguments
ENV="$1"
HOST="$2"
SUBDOMAIN="$3"
# Step 1: Run build.sh
echo "Step 1: Running build.sh..."
./build.sh "$ENV" "$VERSION_TAG"
if [ $? -ne 0 ]; then
echo "❌ Build failed. Stopping deployment."
exit 1
fi
echo ""
echo "Step 2: Running deploy.sh"
./deploy.sh "$ENV" "$HOST" "$VERSION_TAG" "$SUBDOMAIN"
if [ $? -ne 0 ]; then
echo "❌ Deploy failed."
exit 1
fi
print_header "BUILD AND DEPLOY COMPLETED SUCCESSFULLY"
echo "✅ Both build and deploy operations completed successfully!"
echo "Version tag used: $VERSION_TAG"
echo "======================================================="