diff --git a/templates/squashkiwi/_dockerhelper.sh b/templates/squashkiwi/_dockerhelper.sh deleted file mode 100644 index f1ecce3..0000000 --- a/templates/squashkiwi/_dockerhelper.sh +++ /dev/null @@ -1,81 +0,0 @@ -# Routines for interacting with docker - - -# Check if docker is installed -_check_docker_installed() { - if ! command -v docker &> /dev/null; then - echo "Docker is not installed" - return 1 - fi - - # check if docker daemon is running - if ! docker info &> /dev/null; then - echo "Docker daemon is not running" - return 1 - fi - - # check if user has permission to run docker - if ! docker run --rm hello-world &> /dev/null; then - echo "User does not have permission to run docker" - return 1 - fi - - return 0 -} - -# Check if a container exists -_is_container_exists() { - if ! docker ps -a --format "{{.Names}}" | grep -q "^$1$"; then - return 1 - fi - return 0 -} - -# Check if a container is running -_is_container_running() { - if ! docker ps --format "{{.Names}}" | grep -q "^$1$"; then - return 1 - fi - return 0 -} - -# get contianer ID -_get_container_id() { - docker ps --format "{{.ID}}" --filter "name=$1" -} - -# get container status -_get_container_status() { - docker ps --format "{{.Status}}" --filter "name=$1" -} - -# start container that exists -_start_container() { - _is_container_exists $1 || return 1 - _is_container_running $1 && return 0 - docker start $1 -} - -# stop container that exists -_stop_container() { - _is_container_running $1 || return 0; - docker stop $1 -} - -# remove container that exists -_remove_container() { - _stop_container $1 - _is_container_exists $1 || return 0; - docker rm $1 -} - -# get container logs -_get_container_logs() { - if ! _is_container_exists $1; then - echo "Container $1 does not exist" - return 1 - fi - - docker logs $1 -} - diff --git a/templates/squashkiwi/_install.sh b/templates/squashkiwi/_install.sh index e188dc7..1853db6 100755 --- a/templates/squashkiwi/_install.sh +++ b/templates/squashkiwi/_install.sh @@ -6,6 +6,7 @@ load_env "$1" || die "Failed to load environment variables" _check_docker_installed || die "Docker test failed, aborting installation..." # Create deploy and data folders +[ -z "$LOCAL_DATA_FOLDER" ] && die "LOCAL_DATA_FOLDER is not set" create_folder "$LOCAL_DATA_FOLDER/data" create_folder "$LOCAL_DATA_FOLDER/backups" @@ -13,8 +14,8 @@ create_folder "$LOCAL_DATA_FOLDER/backups" docker pull "$IMAGE_REGISTRY/$IMAGE_REPO:$IMAGE_TAG" || die "Failed to pull image $IMAGE_REGISTRY/$IMAGE_REPO:$IMAGE_TAG" # remove and restart, as the env may have changed. -./stop.sh || die "Failed to stop container ${CONTAINER_NAME}" +bash ./stop.sh $1 || die "Failed to stop container ${CONTAINER_NAME}" _remove_container $CONTAINER_NAME || die "Failed to remove container ${CONTAINER_NAME}" -./start.sh || die "Failed to start container ${CONTAINER_NAME}" +bash ./start.sh $1 || die "Failed to start container ${CONTAINER_NAME}" echo "Installation of ${CONTAINER_NAME} complete" diff --git a/templates/squashkiwi/start.sh b/templates/squashkiwi/start.sh index 2b59ddf..390fdb0 100755 --- a/templates/squashkiwi/start.sh +++ b/templates/squashkiwi/start.sh @@ -2,10 +2,14 @@ source "$(dirname "$0")/_common.sh" load_env "$1" || die "Failed to load environment variables" -create_and_start_container "docker run -d \ - --restart unless-stopped \ - --name ${CONTAINER_NAME} \ - -p ${HOST_PORT}:${CONTAINER_PORT} \ - -v ${LOCAL_DATA_FOLDER}/data:/skdata \ - ${IMAGE_REGISTRY}/${IMAGE_REPO}:${IMAGE_TAG}" - || die "Failed to start container ${CONTAINER_NAME}" +DOCKER_RUN_CMD="docker run -d \ + --restart unless-stopped \ + --name ${CONTAINER_NAME} \ + -p ${HOST_PORT}:${CONTAINER_PORT} \ + -v ${LOCAL_DATA_FOLDER}/data:/skdata \ + ${IMAGE_REGISTRY}/${IMAGE_REPO}:${IMAGE_TAG}" + + +if ! create_and_start_container "$DOCKER_RUN_CMD"; then + die "Failed to start container ${CONTAINER_NAME}" +fi