forked from rybbit-io/rybbit
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsetup.sh
More file actions
139 lines (126 loc) · 3.97 KB
/
setup.sh
File metadata and controls
139 lines (126 loc) · 3.97 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/bin/bash
# Exit immediately if a command exits with a non-zero status.
set -e
# Default values
USE_WEBSERVER="true"
BACKEND_PORT="3001"
CLIENT_PORT="3002"
# Help function
show_help() {
echo "Usage: $0 <domain_name> [options]"
echo "Example: $0 myapp.example.com"
echo "Example with no webserver: $0 myapp.example.com --no-webserver"
echo ""
echo "Options:"
echo " --no-webserver Disable the built-in Caddy webserver"
echo " --backend-port <port> Set custom host port for backend (default: 3001)"
echo " --client-port <port> Set custom host port for client (default: 3002)"
echo " --help Show this help message"
}
# Parse arguments
while [[ "$#" -gt 0 ]]; do
case $1 in
--no-webserver)
USE_WEBSERVER="false"
shift
;;
--backend-port)
if [[ -z "$2" || "$2" =~ ^- ]]; then
echo "Error: --backend-port requires a port number"
show_help
exit 1
fi
BACKEND_PORT="$2"
shift 2
;;
--client-port)
if [[ -z "$2" || "$2" =~ ^- ]]; then
echo "Error: --client-port requires a port number"
show_help
exit 1
fi
CLIENT_PORT="$2"
shift 2
;;
--help)
show_help
exit 0
;;
-*)
echo "Unknown option: $1"
show_help
exit 1
;;
*)
if [ -z "$DOMAIN_NAME" ]; then
DOMAIN_NAME="$1"
else
echo "Error: Only one domain name can be specified"
show_help
exit 1
fi
shift
;;
esac
done
# Check if domain name argument is provided
if [ -z "$DOMAIN_NAME" ]; then
echo "Error: Domain name is required"
show_help
exit 1
fi
BASE_URL="https://${DOMAIN_NAME}"
# Generate a secure random secret for BETTER_AUTH_SECRET
# Uses OpenSSL if available, otherwise falls back to /dev/urandom
if command -v openssl &> /dev/null; then
BETTER_AUTH_SECRET=$(openssl rand -hex 32)
elif [ -e /dev/urandom ]; then
BETTER_AUTH_SECRET=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 32)
else
echo "Error: Could not generate secure secret. Please install openssl or ensure /dev/urandom is available." >&2
exit 1
fi
# Create or overwrite the .env file
echo "Creating .env file..."
# Update port mappings based on webserver choice
if [ "$USE_WEBSERVER" = "false" ]; then
# When not using the built-in webserver, expose ports to all interfaces
# Using quotes to ensure the string is passed as-is to Docker Compose
HOST_BACKEND_PORT="\"${BACKEND_PORT}:3001\""
HOST_CLIENT_PORT="\"${CLIENT_PORT}:3002\""
else
# Keep ports only accessible via localhost when using Caddy
HOST_BACKEND_PORT="\"127.0.0.1:${BACKEND_PORT}:3001\""
HOST_CLIENT_PORT="\"127.0.0.1:${CLIENT_PORT}:3002\""
fi
cat > .env << EOL
# Variables configured by setup.sh
DOMAIN_NAME=${DOMAIN_NAME}
BASE_URL=${BASE_URL}
BETTER_AUTH_SECRET=${BETTER_AUTH_SECRET}
USE_WEBSERVER=${USE_WEBSERVER}
HOST_BACKEND_PORT=${HOST_BACKEND_PORT}
HOST_CLIENT_PORT=${HOST_CLIENT_PORT}
DISABLE_SIGNUP=false
EOL
echo ".env file created successfully with domain ${DOMAIN_NAME}."
if [ "$USE_WEBSERVER" = "false" ]; then
echo "Caddy webserver is disabled. You'll need to set up your own webserver."
if [ "$BACKEND_PORT" = "3001" ] && [ "$CLIENT_PORT" = "3002" ]; then
echo "The backend service will be available on port 3001 and the client on port 3002."
else
echo "The backend service will be available on port ${BACKEND_PORT} (mapped to container port 3001)"
echo "The client service will be available on port ${CLIENT_PORT} (mapped to container port 3002)"
fi
fi
# Build and start the Docker Compose stack
echo "Building and starting Docker services..."
if [ "$USE_WEBSERVER" = "false" ]; then
# Start without the caddy service when using --no-webserver
docker compose up -d backend client clickhouse postgres
else
# Start all services including caddy
docker compose up -d
fi
echo "Setup complete. Services are starting in the background."
echo "You can monitor logs with: docker compose logs -f"