2023-12-27 22:04:07 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
CONTAINER_NAME="usse_react"
|
|
|
|
IMAGE_NAME="usse_react"
|
2023-12-27 22:43:29 +00:00
|
|
|
PORT_MAPPING="15015:3000"
|
2023-12-27 22:04:07 +00:00
|
|
|
COMMAND="bash"
|
2023-12-27 22:50:18 +00:00
|
|
|
OUT_JSON_PATH=`realpath ../scrape/out.json`
|
2023-12-27 22:04:07 +00:00
|
|
|
|
|
|
|
ok () {
|
|
|
|
echo -e "[\033[32;1m+\033[0m] $@"
|
|
|
|
}
|
|
|
|
|
|
|
|
err () {
|
|
|
|
echo -e "[\033[31;1m!\033[0m] $@"
|
|
|
|
}
|
|
|
|
|
|
|
|
info () {
|
|
|
|
echo -e "[\033[34;1m-\033[0m] $@"
|
|
|
|
}
|
|
|
|
|
|
|
|
check_ret (){
|
|
|
|
if [ $? -ne 0 ]
|
|
|
|
then
|
|
|
|
err $1
|
|
|
|
exit -1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
if [[ "$1" == "remove" ]]; then
|
|
|
|
echo "Stopping the Docker container..."
|
|
|
|
docker stop ${CONTAINER_NAME} && docker rm ${CONTAINER_NAME}
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "$1" == "rebuild" ]]; then
|
|
|
|
echo "Stopping and removing the Docker container..."
|
|
|
|
docker stop ${CONTAINER_NAME} && docker rm ${CONTAINER_NAME}
|
|
|
|
|
|
|
|
echo "Removing the Docker image..."
|
|
|
|
docker rmi ${IMAGE_NAME} || true
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check if the container image exists
|
|
|
|
if [[ ! "$(docker images -q ${IMAGE_NAME})" ]]; then
|
|
|
|
echo "Building the Docker container..."
|
2023-12-28 15:43:53 +00:00
|
|
|
cp ${OUT_JSON_PATH} src/locations.json
|
2024-03-31 16:01:38 +00:00
|
|
|
docker build -t ${IMAGE_NAME} .
|
2023-12-27 22:04:07 +00:00
|
|
|
check_ret "Docker build failed!"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "$1" == "recreate" ]]; then
|
|
|
|
echo "Removing docker container for recreation..."
|
|
|
|
docker stop ${CONTAINER_NAME} && docker rm ${CONTAINER_NAME}
|
|
|
|
fi
|
|
|
|
|
2023-12-27 22:43:29 +00:00
|
|
|
if [[ "$1" == "shell" ]]; then
|
|
|
|
# Get a bash shell inside the container
|
|
|
|
docker exec -ti ${CONTAINER_NAME} ${COMMAND}
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "$1" == "logs" ]]; then
|
|
|
|
# Get a bash shell inside the container
|
|
|
|
docker logs ${CONTAINER_NAME}
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2023-12-27 22:04:07 +00:00
|
|
|
# Run container
|
2023-12-28 15:43:53 +00:00
|
|
|
docker run --name ${CONTAINER_NAME} -p ${PORT_MAPPING} ${IMAGE_NAME}
|