-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdeploy.sh
More file actions
executable file
·164 lines (144 loc) · 4.06 KB
/
deploy.sh
File metadata and controls
executable file
·164 lines (144 loc) · 4.06 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/bin/bash
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Print colored output
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Check if Docker is installed
check_docker() {
if ! command -v docker &> /dev/null; then
print_error "Docker is not installed. Please install Docker first."
exit 1
fi
if ! command -v docker-compose &> /dev/null; then
print_error "Docker Compose is not installed. Please install Docker Compose first."
exit 1
fi
print_success "Docker and Docker Compose are installed"
}
# Check if .env file exists
check_env() {
if [ ! -f "backend/.env" ]; then
print_warning "backend/.env file not found. Creating from example..."
cp backend/.env.example backend/.env
print_warning "Please edit backend/.env with your actual API keys before running the application"
print_warning "You can edit it with: nano backend/.env"
return 1
fi
return 0
}
# Build and deploy
deploy() {
print_status "Starting deployment process..."
# Stop existing containers
print_status "Stopping existing containers..."
docker-compose down
# Remove old images (optional)
if [ "$1" = "--clean" ]; then
print_status "Removing old images..."
docker-compose down --rmi all
docker system prune -f
fi
# Build and start containers
print_status "Building and starting containers..."
docker-compose up --build -d
if [ $? -eq 0 ]; then
print_success "Deployment completed successfully!"
print_status "Services are starting up..."
print_status "Frontend will be available at: http://localhost:3000"
print_status "Backend API will be available at: http://localhost:3001"
print_status ""
print_status "To view logs:"
print_status " Frontend: docker-compose logs -f frontend"
print_status " Backend: docker-compose logs -f backend"
print_status " All: docker-compose logs -f"
print_status ""
print_status "To stop services: docker-compose down"
else
print_error "Deployment failed!"
exit 1
fi
}
# Show help
show_help() {
echo "Usage: $0 [OPTIONS]"
echo ""
echo "Options:"
echo " --clean Remove old images before building"
echo " --logs Show container logs"
echo " --stop Stop all containers"
echo " --status Show container status"
echo " --help Show this help message"
echo ""
echo "Examples:"
echo " $0 # Deploy normally"
echo " $0 --clean # Clean deploy (remove old images)"
echo " $0 --logs # Show logs"
echo " $0 --stop # Stop containers"
}
# Show logs
show_logs() {
docker-compose logs -f
}
# Stop containers
stop_containers() {
print_status "Stopping containers..."
docker-compose down
print_success "Containers stopped"
}
# Show status
show_status() {
print_status "Container status:"
docker-compose ps
}
# Main script
main() {
case "$1" in
--help)
show_help
;;
--logs)
show_logs
;;
--stop)
stop_containers
;;
--status)
show_status
;;
--clean)
check_docker
check_env
deploy --clean
;;
"")
check_docker
env_check_result=$?
deploy
if [ $env_check_result -eq 1 ]; then
print_warning "Remember to configure your exchange API keys in backend/.env"
print_warning "Then restart with: docker-compose restart backend"
fi
;;
*)
print_error "Unknown option: $1"
show_help
exit 1
;;
esac
}
main "$@"