-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpodman-deploy.sh
More file actions
executable file
·154 lines (137 loc) · 4.19 KB
/
podman-deploy.sh
File metadata and controls
executable file
·154 lines (137 loc) · 4.19 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
#!/usr/bin/env bash
# ClearURLs Bot - Podman Deployment Script
# This script replaces Docker commands with Podman equivalents
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Function to print colored output
print_status() {
echo -e "${GREEN}[INFO]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Check if Podman is installed
if ! command -v podman &> /dev/null; then
print_error "Podman is not installed. Please install Podman first."
exit 1
fi
# Check if podman-compose is installed (optional)
if ! command -v podman-compose &> /dev/null; then
print_warning "podman-compose is not installed. Using podman kube generate instead."
COMPOSE_AVAILABLE=false
else
COMPOSE_AVAILABLE=true
fi
# Function to build the container
build_container() {
print_status "Building ClearURLs Bot container..."
podman build -t clear_urls_bot -f Containerfile .
print_status "Container built successfully!"
}
# Function to run the container
run_container() {
print_status "Starting ClearURLs Bot container..."
# Create pod for networking
podman pod create --name clear_urls_bot_pod -p 3000:3000 2>/dev/null || true
# Run the container
podman run -d \
--name clear_urls_bot \
--pod clear_urls_bot_pod \
--env-file .env \
-e APP_ENV=production \
-e RUST_LOG=clear_urls_bot=info \
-v ./bot.db:/app/bot.db:Z \
--memory=512m \
--cpus=0.5 \
--restart=unless-stopped \
clear_urls_bot
print_status "Container started successfully!"
}
# Function to stop the container
stop_container() {
print_status "Stopping ClearURLs Bot container..."
podman stop clear_urls_bot 2>/dev/null || true
podman rm clear_urls_bot 2>/dev/null || true
podman pod rm clear_urls_bot_pod 2>/dev/null || true
print_status "Container stopped and removed!"
}
# Function to view logs
view_logs() {
podman logs -f clear_urls_bot
}
# Function to show status
show_status() {
podman ps -a --filter name=clear_urls_bot
}
# Main script logic
case "${1:-build}" in
"build")
build_container
;;
"run")
run_container
;;
"start")
build_container
run_container
;;
"stop")
stop_container
;;
"restart")
stop_container
run_container
;;
"logs")
view_logs
;;
"status")
show_status
;;
"compose")
if [ "$COMPOSE_AVAILABLE" = true ]; then
print_status "Using podman-compose..."
podman-compose -f podman-compose.yml "${2:-up}"
else
print_warning "podman-compose not available. Generate Kubernetes manifest..."
podman kube generate clear_urls_bot > clear_urls_bot.yaml
print_status "Kubernetes manifest generated: clear_urls_bot.yaml"
print_status "Use 'podman play kube clear_urls_bot.yaml' to deploy"
fi
;;
"help"|"-h"|"--help")
echo "ClearURLs Bot - Podman Deployment Script"
echo ""
echo "Usage: $0 [command]"
echo ""
echo "Commands:"
echo " build Build the container image"
echo " run Run the container (assumes image exists)"
echo " start Build and run the container"
echo " stop Stop and remove the container"
echo " restart Restart the container"
echo " logs View container logs"
echo " status Show container status"
echo " compose Use podman-compose (optional argument: up/down)"
echo " help Show this help message"
echo ""
echo "Examples:"
echo " $0 start # Build and run the bot"
echo " $0 logs # View logs"
echo " $0 restart # Restart the bot"
echo " $0 compose up # Use podman-compose to start"
echo " $0 compose down # Use podman-compose to stop"
;;
*)
print_error "Unknown command: $1"
print_status "Use '$0 help' to see available commands"
exit 1
;;
esac