-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy_with_diagnostics.sh
58 lines (45 loc) · 1.55 KB
/
deploy_with_diagnostics.sh
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
#!/bin/bash
# Stop and remove existing containers
docker-compose down
# Remove all Docker images related to the project
docker rmi -f $(docker images -q my_project_app)
# Ensure necessary directories and files are present
PROJECT_DIR=~/Pulpit/my_project
APP_DIR=$PROJECT_DIR/app
# Check if main.py exists
if [ ! -f "$APP_DIR/main.py" ]; then
echo "main.py not found in $APP_DIR"
exit 1
fi
# Check if Dockerfile exists
if [ ! -f "$PROJECT_DIR/Dockerfile" ]; then
echo "Dockerfile not found in $PROJECT_DIR"
exit 1
fi
# Check if docker-compose.yml exists
if [ ! -f "$PROJECT_DIR/docker-compose.yml" ]; then
echo "docker-compose.yml not found in $PROJECT_DIR"
exit 1
fi
# Build and start containers
docker-compose up --build -d
# Check status of containers
echo "Checking status of containers..."
docker ps -a
# Wait for a few seconds to ensure containers have started
sleep 5
# Get logs of the Flask app container
echo "Fetching logs of the Flask app container..."
docker logs my_project_app_1
# Check if the Flask container is running
FLASK_CONTAINER_STATUS=$(docker inspect -f '{{.State.Status}}' my_project_app_1)
if [ "$FLASK_CONTAINER_STATUS" != "running" ]; then
echo "Flask app container is not running. Checking detailed logs..."
docker logs my_project_app_1
echo "Attempting to start Flask app container manually..."
docker start my_project_app_1
docker exec -it my_project_app_1 /bin/bash -c "ls /app && python3 /app/main.py"
else
echo "Flask app container is running successfully."
fi
echo "Setup complete. Containers are running."