-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeploy-podman.sh
More file actions
executable file
·279 lines (246 loc) · 7.23 KB
/
deploy-podman.sh
File metadata and controls
executable file
·279 lines (246 loc) · 7.23 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
#!/bin/bash
# Everything OpenCode Podman Deployment Script
# Quick start for deploying Everything OpenCode with Podman
set -e
# Configuration
IMAGE_NAME="everything-opencode"
CONTAINER_NAME="everything-opencode"
NETWORK_NAME="everything-opencode-net"
VOLUME_NAME="everything-opencode-data"
PORT_APP=3000
PORT_DEBUG=3005
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Functions
print_header() {
echo -e "${BLUE}"
echo "=========================================="
echo "Everything OpenCode Podman Deployment"
echo "=========================================="
echo -e "${NC}"
echo "For Quadlet (systemd) deployment, use: sudo ./deploy-quadlet.sh"
echo ""
}
print_step() {
echo -e "${YELLOW}[STEP] $1${NC}"
}
print_success() {
echo -e "${GREEN}✅ $1${NC}"
}
print_error() {
echo -e "${RED}❌ $1${NC}"
}
check_command() {
if ! command -v $1 &> /dev/null; then
print_error "$1 is not installed. Please install it first."
exit 1
fi
}
check_podman() {
print_step "Checking Podman installation..."
if ! podman --version &> /dev/null; then
print_error "Podman is not installed or not in PATH"
echo "Please install Podman:"
echo " Ubuntu/Debian: sudo apt install podman podman-docker"
echo " macOS: brew install podman"
echo " Windows (WSL2): sudo apt install podman"
exit 1
fi
PODMAN_VERSION=$(podman --version | awk '{print $3}')
print_success "Podman $PODMAN_VERSION is installed"
}
build_image() {
print_step "Building container image..."
if [ -f "Dockerfile" ]; then
podman build -t $IMAGE_NAME:latest .
print_success "Image built successfully"
else
print_error "Dockerfile not found in current directory"
exit 1
fi
}
create_network() {
print_step "Creating network..."
if ! podman network exists $NETWORK_NAME; then
podman network create $NETWORK_NAME
print_success "Network '$NETWORK_NAME' created"
else
print_success "Network '$NETWORK_NAME' already exists"
fi
}
create_volume() {
print_step "Creating volume..."
if ! podman volume exists $VOLUME_NAME; then
podman volume create $VOLUME_NAME
print_success "Volume '$VOLUME_NAME' created"
else
print_success "Volume '$VOLUME_NAME' already exists"
fi
}
stop_container() {
print_step "Stopping existing container..."
if podman ps -a --format "{{.Names}}" | grep -q $CONTAINER_NAME; then
podman stop $CONTAINER_NAME 2>/dev/null || true
podman rm $CONTAINER_NAME 2>/dev/null || true
print_success "Existing container stopped and removed"
else
print_success "No existing container found"
fi
}
run_container() {
print_step "Starting container..."
# Create environment file if it doesn't exist
if [ ! -f ".env" ]; then
cat > .env << EOF
NODE_ENV=production
DEBUG_ENABLED=true
PORT=$PORT_APP
DEBUG_PORT=$PORT_DEBUG
LOG_LEVEL=info
CORS_ORIGIN=*
MAX_FILE_SIZE=10MB
EOF
print_success "Created .env file with default settings"
fi
# Run container
podman run -d \
--name $CONTAINER_NAME \
--network $NETWORK_NAME \
--hostname $CONTAINER_NAME \
-p $PORT_APP:$PORT_APP \
-p $PORT_DEBUG:$PORT_DEBUG \
--volume $VOLUME_NAME:/app/data:Z \
--volume $(pwd)/config:/app/config:ro,Z \
--env-file .env \
--restart unless-stopped \
$IMAGE_NAME:latest
print_success "Container started"
}
check_health() {
print_step "Checking container health..."
# Wait for container to start
sleep 5
# Check if container is running
if podman ps --format "{{.Names}} {{.Status}}" | grep -q "$CONTAINER_NAME Up"; then
print_success "Container is running"
else
print_error "Container failed to start"
podman logs $CONTAINER_NAME
exit 1
fi
# Try health endpoint
local max_retries=10
local retry_count=0
while [ $retry_count -lt $max_retries ]; do
if curl -s -f http://localhost:$PORT_APP/health > /dev/null 2>&1; then
print_success "Health check passed"
return 0
fi
retry_count=$((retry_count + 1))
echo " Health check attempt $retry_count/$max_retries failed, retrying..."
sleep 3
done
print_error "Health check failed after $max_retries attempts"
podman logs $CONTAINER_NAME
exit 1
}
show_info() {
print_step "Deployment Information:"
echo ""
echo -e "${GREEN}✅ Deployment Successful!${NC}"
echo ""
echo "Container Information:"
echo " Name: $CONTAINER_NAME"
echo " Image: $IMAGE_NAME:latest"
echo " Network: $NETWORK_NAME"
echo " Volume: $VOLUME_NAME"
echo ""
echo "Access URLs:"
echo " Main Application: http://localhost:$PORT_APP"
echo " Debug Server: http://localhost:$PORT_DEBUG"
echo " Health Check: http://localhost:$PORT_APP/health"
echo ""
echo "Useful Commands:"
echo " View logs: podman logs -f $CONTAINER_NAME"
echo " Shell access: podman exec -it $CONTAINER_NAME /bin/sh"
echo " Stop container: podman stop $CONTAINER_NAME"
echo " Remove container: podman rm $CONTAINER_NAME"
echo " View stats: podman stats $CONTAINER_NAME"
echo ""
echo "Next Steps:"
echo " 1. Configure your application in the ./config directory"
echo " 2. Check logs for any initialization issues"
echo " 3. Access the web interface at http://localhost:$PORT_APP"
echo ""
}
cleanup() {
print_step "Cleaning up..."
podman system prune -f
print_success "Cleanup completed"
}
# Main execution
main() {
print_header
# Check prerequisites
check_podman
check_command curl
# Build and deploy
build_image
create_network
create_volume
stop_container
run_container
check_health
# Show deployment info
show_info
# Optional cleanup
# cleanup
echo -e "${GREEN}🎉 Everything OpenCode is now running with Podman!${NC}"
}
# Handle command line arguments
case "$1" in
"stop")
stop_container
print_success "Container stopped"
;;
"logs")
podman logs -f $CONTAINER_NAME
;;
"shell")
podman exec -it $CONTAINER_NAME /bin/sh
;;
"restart")
stop_container
run_container
check_health
print_success "Container restarted"
;;
"status")
podman ps -a --filter "name=$CONTAINER_NAME"
;;
"clean")
cleanup
;;
"help"|"-h"|"--help")
echo "Usage: $0 [command]"
echo ""
echo "Commands:"
echo " (no command) Deploy Everything OpenCode"
echo " stop Stop the container"
echo " logs View container logs"
echo " shell Access container shell"
echo " restart Restart the container"
echo " status Show container status"
echo " clean Clean up unused resources"
echo " help Show this help message"
echo ""
exit 0
;;
*)
main
;;
esac