usse/react_usse/use_docker.sh

68 lines
1.6 KiB
Bash
Raw Normal View History

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"
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
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-27 22:43:29 +00:00
docker run --name ${CONTAINER_NAME} -p ${PORT_MAPPING} -v /home/eljakim/Source/usse/source/scrape/out.json:/usr/src/app/src/locations.json ${IMAGE_NAME}