Dropshell basic templates (WIP)

This commit is contained in:
Your Name
2025-05-13 21:15:52 +12:00
parent e061feadc6
commit 4a74bbf551
71 changed files with 969 additions and 0 deletions

10
squashkiwi/_default.env Normal file
View File

@ -0,0 +1,10 @@
# Application settings
CONTAINER_PORT=8181
# Deployment settings
CONTAINER_NAME="squashkiwi"
# Image settings
IMAGE_REGISTRY="gitea.jde.nz"
IMAGE_REPO="squashkiwi/squashkiwi"
IMAGE_TAG="latest"

13
squashkiwi/backup.sh Executable file
View File

@ -0,0 +1,13 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
_check_required_env_vars "CONTAINER_NAME" "LOCAL_DATA_FOLDER" "BACKUP_FILE" "TEMP_DIR"
# Stop container before backup
_stop_container "$CONTAINER_NAME"
autobackup "path=${LOCAL_DATA_FOLDER}" || _die "Failed to create backup"
# Start container after backup
_start_container "$CONTAINER_NAME"
echo "Backup created successfully"

View File

@ -0,0 +1,2 @@
# Template to use - always required!
TEMPLATE=squashkiwi

View File

@ -0,0 +1,6 @@
# Service settings specific to this server
# (can also override anything in the _basic.env file in the template to make it specific to this server)
HOST_PORT=80
LOCAL_DATA_FOLDER="/home/dropshell/example-squashkiwi"
IMAGE_TAG="latest"

18
squashkiwi/install.sh Executable file
View File

@ -0,0 +1,18 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
_check_required_env_vars "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" "CONTAINER_NAME" "LOCAL_DATA_FOLDER"
autocreate path=$LOCAL_DATA_FOLDER || _die "Failed to create local data folder"
# Test Docker
_check_docker_installed || _die "Docker test failed, aborting installation..."
# check can pull image on remote host and exit if fails
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.
bash ./stop.sh || _die "Failed to stop container ${CONTAINER_NAME}"
_remove_container $CONTAINER_NAME || _die "Failed to remove container ${CONTAINER_NAME}"
bash ./start.sh || _die "Failed to start container ${CONTAINER_NAME}"
echo "Installation of ${CONTAINER_NAME} complete"

8
squashkiwi/logs.sh Executable file
View File

@ -0,0 +1,8 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
_check_required_env_vars "CONTAINER_NAME"
echo "Container ${CONTAINER_NAME} logs:"
_grey_start
docker logs "${CONTAINER_NAME}"
_grey_end

8
squashkiwi/nuke.sh Executable file
View File

@ -0,0 +1,8 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
_check_required_env_vars "LOCAL_DATA_FOLDER"
autonuke "path=${LOCAL_DATA_FOLDER}" || _die "Failed to nuke ${LOCAL_DATA_FOLDER}"
echo "Nuke of ${CONTAINER_NAME} complete"

5
squashkiwi/ports.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
_check_required_env_vars "HOST_PORT"
echo $HOST_PORT

18
squashkiwi/restore.sh Executable file
View File

@ -0,0 +1,18 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
_check_required_env_vars "CONTAINER_NAME" "LOCAL_DATA_FOLDER" "BACKUP_FILE" "TEMP_DIR"
# RESTORE SCRIPT
# The restore script is OPTIONAL.
# It is used to restore the service on the server from a backup file.
# It is called with one argument: the path to the backup file.
# # Stop container before backup
bash ./uninstall.sh || _die "Failed to uninstall service before restore"
autorestore "path=${LOCAL_DATA_FOLDER}" || _die "Failed to restore data folder from backup"
# reinstall service
bash ./install.sh || _die "Failed to reinstall service after restore"
echo "Restore complete! Service is running again on port $HOST_PORT with restored website."

13
squashkiwi/ssh.sh Executable file
View File

@ -0,0 +1,13 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
_check_required_env_vars "CONTAINER_NAME"
if ! _is_container_running "$CONTAINER_NAME"; then
_die "Container ${CONTAINER_NAME} is not running. Can't connect to it."
fi
echo "Connecting to ${CONTAINER_NAME}..."
docker exec -it ${CONTAINER_NAME} bash
echo "Disconnected from ${CONTAINER_NAME}"

24
squashkiwi/start.sh Executable file
View File

@ -0,0 +1,24 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
_check_required_env_vars "CONTAINER_NAME" "HOST_PORT" "CONTAINER_PORT" "LOCAL_DATA_FOLDER" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG"
DOCKER_RUN_CMD="docker run -d \
--restart unless-stopped \
--name ${CONTAINER_NAME} \
-p ${HOST_PORT}:${CONTAINER_PORT} \
-v ${LOCAL_DATA_FOLDER}:/skdata \
${IMAGE_REGISTRY}/${IMAGE_REPO}:${IMAGE_TAG}"
if ! _create_and_start_container "$DOCKER_RUN_CMD" "$CONTAINER_NAME"; then
echo "${DOCKER_RUN_CMD}"
_die "Failed to start container ${CONTAINER_NAME}"
fi
# Check if the container is running
if ! _is_container_running "$CONTAINER_NAME"; then
_die "Container ${CONTAINER_NAME} is not running"
fi
echo "Container ${CONTAINER_NAME} started, on port ${HOST_PORT}"

13
squashkiwi/status.sh Executable file
View File

@ -0,0 +1,13 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
_check_required_env_vars "CONTAINER_NAME" "HOST_PORT"
# check if the service is running
_is_container_running $CONTAINER_NAME || _die "Service is not running - did not find container $CONTAINER_NAME."
# check if the service is healthy
curl -s -X GET http://localhost:${HOST_PORT}/health | grep -q "OK" \
|| _die "Service is not healthy - did not get OK response from /health endpoint."
echo "Service is healthy"
exit 0

7
squashkiwi/stop.sh Executable file
View File

@ -0,0 +1,7 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
_check_required_env_vars "CONTAINER_NAME"
_stop_container $CONTAINER_NAME || _die "Failed to stop container ${CONTAINER_NAME}"
echo "Container ${CONTAINER_NAME} stopped"

16
squashkiwi/uninstall.sh Executable file
View File

@ -0,0 +1,16 @@
#!/bin/bash
source "${AGENT_PATH}/_common.sh"
_check_required_env_vars "CONTAINER_NAME" "LOCAL_DATA_FOLDER"
# UNINSTALL SCRIPT
# The uninstall script is required for all templates.
# It is used to uninstall the service from the server.
# It is called with the path to the server specific env file as an argument.
_remove_container $CONTAINER_NAME || _die "Failed to remove container ${CONTAINER_NAME}"
_is_container_running && _die "Couldn't stop existing container"
_is_container_exists && _die "Couldn't remove existing container"
echo "Uninstallation of ${CONTAINER_NAME} complete."
echo "Local data folder ${LOCAL_DATA_FOLDER} still in place."