LasTres/start_docker.sh

39 lines
1.3 KiB
Bash
Raw Normal View History

2023-07-01 03:43:54 +02:00
#!/bin/bash
CURRENT_DIR=$(dirname $0)
NEEDS_SUDO=0
SUDO=""
DOCKER_TAG="lastres:latest"
DOCKER_BUILD_PARAMS="$CURRENT_DIR -t $DOCKER_TAG"
DOCKER_RUN_PARAMS="run -it -v /var/run/postgresql/:/var/run/postgresql/ -v $CURRENT_DIR:/var/lib/las_tres/LasTres -v /var/run/redis/:/var/run/redis --name LasTresDocker -p 3000:3000 $DOCKER_TAG"
CHECKSUM_DOCKER_FILE="$CURRENT_DIR/.dockerfile_checksum"
perl -pe 's/\{\{UID\}\}/'"$UID/" Dockerfile.template > Dockerfile
OLD_CHECKSUM_DOCKER="$(cat $CHECKSUM_DOCKER_FILE 2> /dev/null)"
CURRENT_CHECKSUM_DOCKER="$(sha512sum Dockerfile | awk '{ print $1 }')"
if ! docker image ls 2>/dev/null; then
NEEDS_SUDO=1
fi
if [[ $NEEDS_SUDO -gt 0 ]]; then
SUDO="sudo"
fi
if [[ $OLD_CHECKSUM_DOCKER != $CURRENT_CHECKSUM_DOCKER ]]; then
echo "$OLD_CHECKSUM_DOCKER != $CURRENT_CHECKSUM_DOCKER rebuilding docker";
echo $SUDO docker build $DOCKER_BUILD_PARAMS
$SUDO docker build $DOCKER_BUILD_PARAMS
echo $CURRENT_CHECKSUM_DOCKER > $CHECKSUM_DOCKER_FILE
echo $SUDO docker $DOCKER_RUN_PARAMS
$SUDO docker $DOCKER_RUN_PARAMS
exit
fi
echo $SUDO docker container start LasTresDocker -ai
if ! $SUDO docker container start LasTresDocker -ai; then
echo $SUDO docker $DOCKER_RUN_PARAMS
$SUDO docker $DOCKER_RUN_PARAMS
fi