-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_docker.sh
executable file
·86 lines (72 loc) · 3.03 KB
/
run_docker.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
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
#!/bin/bash
echo "$0"
# Check if the correct number of arguments are provided
if [ "$#" -lt 1 ] || [ "$#" -gt 3 ]; then
echo "Usage: $0 CITYNAME [copy] [container_name]"
echo "CITYNAME: name of the city to build the guide for"
echo "copy: optional argument to copy also guide/categories files"
exit 1
fi
# Assign arguments to variables with default values
CITYNAME=${1}
COPY=${2:-false}
CONTAINER_NAME=${3:-tfimage}
CONTAINER_PATH_IMAGE_DB=/app/models/src/main/assets/databases
LOCAL_PATH_CONTAINER_PATH_IMAGE_DB=./models/src/main/assets/
CONTAINER_PATH_CATEGORIES=/Python/categories/${CITYNAME}/
LOCAL_PATH_CATEGORIES=./models/src/main/assets/currentCategories/
CONTAINER_PATH_GUIDES=/Python/guides/${CITYNAME}/
LOCAL_PATH_GUIDES=./models/src/main/assets/currentGuide/
echo "Creating guide for: $CITYNAME"
if test -d "Python/categories/${CITYNAME}"; then
echo "Categories directory: " Python/categories/${CITYNAME} " exists."
else
echo "[ERROR] Categories directory " Python/categories/${CITYNAME} " does not exist."
echo "[ERROR] Exiting..."
exit 1
fi
if test -d "Python/guides/${CITYNAME}"; then
echo "Guides directory: " Python/guides/${CITYNAME} " exists."
else
echo "[ERROR] Categories directory: " Python/guides/${CITYNAME} " does not exist."
echo "[ERROR] Exiting..."
exit 1
fi
if [ "$(echo "$COPY" | tr '[:upper:]' '[:lower:]')" = "copy" ]; then # Convert to lowercase and compare
echo "[INFO] Copying also guide/categories files..."
./copy_guides.sh "$CITYNAME"
else
echo "[INFO] Not copying guide/categories files... Use ./copy_guides.sh to copy them manually or add 'copy' as second argument to this script."
fi
# Build Docker image
echo "[INFO] Building Docker image: $CONTAINER_NAME"
docker build -t "$CONTAINER_NAME" .
# Check if the build was successful
if [ $? -ne 0 ]; then
echo "Failed to build Docker image."
exit 1
fi
# Run Docker container in the background
echo "[INFO] Starting Docker container: $CONTAINER_NAME"
CONTAINER_ID=$(docker run -itd "$CONTAINER_NAME" "$CITYNAME")
echo "Docker container started with ID: $CONTAINER_ID"
docker logs -f "$CONTAINER_ID"
# Check if the log message is found using grep
if docker logs "$CONTAINER_ID" | grep -q 'Build DB script terminated correctly'; then
echo "[INFO]: Docker terminated correctly."
# Use docker cp to copy files
docker cp "$CONTAINER_ID":"$CONTAINER_PATH_IMAGE_DB" "$LOCAL_PATH_CONTAINER_PATH_IMAGE_DB"
# Check if the copy operation was successful
if [ $? -eq 0 ]; then
echo "[INFO] Image database files copied successfully from $CONTAINER_NAME:$CONTAINER_PATH_IMAGE_DB to $LOCAL_PATH_CONTAINER_PATH_IMAGE_DB"
else
echo "[ERROR] Failed to copy image database files from $CONTAINER_NAME:$CONTAINER_PATH_IMAGE_DB to $LOCAL_PATH_CONTAINER_PATH_IMAGE_DB"
echo "[ERROR] Exiting..."
exit 1
fi
else
echo "[ERROR]: Docker container did not run correctly. Check logs."
exit 1
fi
echo "[INFO] Process terminated correctly."
echo "[INFO] Now build the project with Android Studio."