usse/react_usse/use_docker.sh

69 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
CONTAINER_NAME="usse_react"
IMAGE_NAME="usse_react"
PORT_MAPPING="15015:3000"
COMMAND="bash"
OUT_JSON_PATH=`realpath ../scrape/out.json`
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..."
docker build -t ${IMAGE_NAME} --build-arg http_proxy=$http_proxy --build-arg https_proxy=$https_proxy .
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
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
# Run container
docker run --name ${CONTAINER_NAME} -p ${PORT_MAPPING} -v ${OUT_JSON_PATH}:/usr/src/app/src/locations.json ${IMAGE_NAME}