diff --git a/caddy/config/caddyfile/Caddyfile b/caddy/config/caddyfile/Caddyfile index 9bd0b7a..37df71e 100644 --- a/caddy/config/caddyfile/Caddyfile +++ b/caddy/config/caddyfile/Caddyfile @@ -1,6 +1,6 @@ # See https://caddyserver.com/docs/caddyfile localhost { -root * /srv +root * /static file_server } diff --git a/caddy/config/service.env b/caddy/config/service.env index 92ef504..ffec6f9 100644 --- a/caddy/config/service.env +++ b/caddy/config/service.env @@ -1,7 +1,12 @@ -# Service settings specific to this server +# Service settings specific to this server # (can also override anything in the .template_info.env file in the template to make it specific to this server) CONTAINER_NAME=caddy IMAGE_TAG="latest" # Server Settings SSH_USER="root" + +# Static files directory (optional) +# If set, maps this host directory to /static in the container +# If empty, uses the default config/static directory +HOST_STATIC_DIR="" diff --git a/caddy/start.sh b/caddy/start.sh index 944cc92..0c599be 100755 --- a/caddy/start.sh +++ b/caddy/start.sh @@ -10,6 +10,13 @@ if [ ! -f "${CONFIG_PATH}/caddyfile/Caddyfile" ]; then _die "Caddyfile not found in ${CONFIG_PATH}/caddyfile/Caddyfile" fi +# Determine static files directory +# Use HOST_STATIC_DIR if set, otherwise use config/static +if [ -n "${HOST_STATIC_DIR}" ]; then + STATIC_DIR="${HOST_STATIC_DIR}" +else + STATIC_DIR="${CONFIG_PATH}/static" +fi DOCKER_RUN_CMD="docker run -d \ --restart unless-stopped \ @@ -21,7 +28,7 @@ DOCKER_RUN_CMD="docker run -d \ -v ${CONFIG_PATH}/caddyfile:/etc/caddy \ -v ${DATA_VOLUME}:/data \ -v ${CONFIG_VOLUME}:/config \ - -v ${CONFIG_PATH}/static:/srv \ + -v ${STATIC_DIR}:/static \ ${IMAGE_REGISTRY}/${IMAGE_REPO}:${IMAGE_TAG}" diff --git a/gitea-server/README.txt b/gitea-server/README.txt new file mode 100644 index 0000000..73c21ac --- /dev/null +++ b/gitea-server/README.txt @@ -0,0 +1,70 @@ +Gitea Server Template +===================== + +A lightweight, self-hosted Git service. Gitea is a painless self-hosted Git +service similar to GitHub, GitLab, and Bitbucket. + +Features: +- Git repository hosting +- Issue tracking +- Pull requests / code review +- Wiki +- CI/CD integration (with Gitea Actions or external runners) +- User and organization management +- Web-based interface + +Configuration +------------- + +Edit config/service.env to customize: + + CONTAINER_NAME - Name of the Docker container (default: gitea) + IMAGE_TAG - Docker image tag (default: latest) + HTTP_PORT - Web interface port (default: 3000) + SSH_PORT - Git SSH port (default: 2222) + +Ports +----- + + HTTP_PORT (default 3000) - Web interface and HTTP Git operations + SSH_PORT (default 2222) - SSH Git operations + +First-Time Setup +---------------- + +After installation, access Gitea at http://your-server:HTTP_PORT to complete +the initial configuration wizard. You'll need to set: + + - Database type (SQLite3 is recommended for small installations) + - Site title and base URL + - Administrator account + +Data Storage +------------ + +All data is stored in a Docker volume named ${CONTAINER_NAME}_data which +includes: + - Git repositories + - Database (if using SQLite) + - User uploads and attachments + - Configuration files + +Backup +------ + +Use the backup.sh script to create backups of all Gitea data. The backup +includes repositories, database, and configuration. + +SSH Clone URLs +-------------- + +To clone via SSH, users should use: + git clone ssh://git@your-server:SSH_PORT/username/repo.git + +Or configure SSH config for easier access. + +More Information +---------------- + +Gitea documentation: https://docs.gitea.io/ +Docker image: https://hub.docker.com/r/gitea/gitea diff --git a/gitea-server/_volumes.sh b/gitea-server/_volumes.sh new file mode 100755 index 0000000..c7c586d --- /dev/null +++ b/gitea-server/_volumes.sh @@ -0,0 +1,7 @@ +#!/bin/bash +# Define volume items for gitea container +# These are used across backup, restore, create, and destroy operations + +get_gitea_volumes() { + echo "volume:datavolume:${DATA_VOLUME}" +} diff --git a/gitea-server/backup.sh b/gitea-server/backup.sh new file mode 100755 index 0000000..a2a0b21 --- /dev/null +++ b/gitea-server/backup.sh @@ -0,0 +1,18 @@ +#!/bin/bash +# shellcheck disable=SC1091 +source "${AGENT_PATH}/common.sh" +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${SCRIPT_DIR}/_volumes.sh" +_check_required_env_vars "CONTAINER_NAME" "DATA_VOLUME" + +# BACKUP SCRIPT +# Creates a backup of the Gitea data volume + +_stop_container "$CONTAINER_NAME" + +# shellcheck disable=SC2046 +backup_items $(get_gitea_volumes) || _die "Failed to create backup" + +_start_container "$CONTAINER_NAME" + +echo "Backup created successfully" diff --git a/gitea-server/config/.template_info.env b/gitea-server/config/.template_info.env new file mode 100644 index 0000000..93fc31e --- /dev/null +++ b/gitea-server/config/.template_info.env @@ -0,0 +1,16 @@ +# DO NOT EDIT THIS FILE FOR YOUR SERVICE! +# This file is replaced from the template whenever there is an update. +# Edit the service.env file to make changes. + +# Template to use - always required! +TEMPLATE=gitea-server +REQUIRES_HOST_ROOT=false +REQUIRES_DOCKER=true +REQUIRES_DOCKER_ROOT=false + +# Image settings +IMAGE_REGISTRY="docker.io" +IMAGE_REPO="gitea/gitea" + +# Volume settings +DATA_VOLUME="${CONTAINER_NAME}_data" diff --git a/gitea-server/config/service.env b/gitea-server/config/service.env new file mode 100644 index 0000000..d9c8122 --- /dev/null +++ b/gitea-server/config/service.env @@ -0,0 +1,11 @@ +# Service settings specific to this server +# (can also override anything in the .template_info.env file in the template to make it specific to this server) +CONTAINER_NAME=gitea +IMAGE_TAG="latest" + +# Server Settings +SSH_USER="root" + +# Gitea ports +HTTP_PORT=3000 +SSH_PORT=2222 diff --git a/gitea-server/destroy.sh b/gitea-server/destroy.sh new file mode 100755 index 0000000..1c695f8 --- /dev/null +++ b/gitea-server/destroy.sh @@ -0,0 +1,20 @@ +#!/bin/bash +# shellcheck disable=SC1091 +source "${AGENT_PATH}/common.sh" +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${SCRIPT_DIR}/_volumes.sh" +_check_required_env_vars "CONTAINER_NAME" "DATA_VOLUME" + +# DESTROY SCRIPT +# Completely removes the service AND all data +# WARNING: This is irreversible! + +echo "WARNING: This will PERMANENTLY DELETE all data for ${CONTAINER_NAME}" +echo "This includes all repositories, users, and configuration!" + +./uninstall.sh + +# shellcheck disable=SC2046 +destroy_items $(get_gitea_volumes) || _die "Failed to destroy docker volumes" + +echo "Destroyed ${CONTAINER_NAME} and all data." diff --git a/gitea-server/install.sh b/gitea-server/install.sh new file mode 100755 index 0000000..f56af68 --- /dev/null +++ b/gitea-server/install.sh @@ -0,0 +1,19 @@ +#!/bin/bash +# shellcheck disable=SC1091 +source "${AGENT_PATH}/common.sh" +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${SCRIPT_DIR}/_volumes.sh" +_check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" "DATA_VOLUME" + +# shellcheck disable=SC2046 +create_items $(get_gitea_volumes) || _die "Failed to create volume $DATA_VOLUME" + +_check_docker_installed || _die "Docker test failed, aborting installation..." + +docker pull "$IMAGE_REGISTRY/$IMAGE_REPO:$IMAGE_TAG" || _die "Failed to pull image $IMAGE_REGISTRY/$IMAGE_REPO:$IMAGE_TAG" + +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" diff --git a/gitea-server/logs.sh b/gitea-server/logs.sh new file mode 100755 index 0000000..e64541c --- /dev/null +++ b/gitea-server/logs.sh @@ -0,0 +1,11 @@ +#!/bin/bash +source "${AGENT_PATH}/common.sh" +_check_required_env_vars "CONTAINER_NAME" + +# LOGS SCRIPT +# Shows the container logs + +echo "Container ${CONTAINER_NAME} logs:" +_grey_start +docker logs "${CONTAINER_NAME}" "$@" +_grey_end diff --git a/gitea-server/ports.sh b/gitea-server/ports.sh new file mode 100755 index 0000000..4a4dc01 --- /dev/null +++ b/gitea-server/ports.sh @@ -0,0 +1,9 @@ +#!/bin/bash +source "${AGENT_PATH}/common.sh" +_check_required_env_vars "HTTP_PORT" "SSH_PORT" + +# PORTS SCRIPT +# Lists the exposed ports + +echo "$HTTP_PORT" +echo "$SSH_PORT" diff --git a/gitea-server/restore.sh b/gitea-server/restore.sh new file mode 100755 index 0000000..177ca7d --- /dev/null +++ b/gitea-server/restore.sh @@ -0,0 +1,21 @@ +#!/bin/bash +# shellcheck disable=SC1091 +source "${AGENT_PATH}/common.sh" +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +source "${SCRIPT_DIR}/_volumes.sh" +_check_required_env_vars "CONTAINER_NAME" "DATA_VOLUME" + +# RESTORE SCRIPT +# Restores Gitea data from a backup + +# Uninstall container before restore +./uninstall.sh || _die "Failed to uninstall service before restore" + +# Restore data from backup file +# shellcheck disable=SC2046 +restore_items $(get_gitea_volumes) || _die "Failed to restore data from backup file" + +# Reinstall service +./install.sh || _die "Failed to reinstall service after restore" + +echo "Restore complete! Service is running again." diff --git a/gitea-server/ssh.sh b/gitea-server/ssh.sh new file mode 100755 index 0000000..5cd6b11 --- /dev/null +++ b/gitea-server/ssh.sh @@ -0,0 +1,8 @@ +#!/bin/bash +source "${AGENT_PATH}/common.sh" +_check_required_env_vars "CONTAINER_NAME" + +# SSH SCRIPT +# Opens a shell inside the container + +docker exec -it "${CONTAINER_NAME}" /bin/bash diff --git a/gitea-server/start.sh b/gitea-server/start.sh new file mode 100755 index 0000000..655e43f --- /dev/null +++ b/gitea-server/start.sh @@ -0,0 +1,30 @@ +#!/bin/bash +source "${AGENT_PATH}/common.sh" +_check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" "DATA_VOLUME" "HTTP_PORT" "SSH_PORT" + +# START SCRIPT +# The start script is required for all templates. +# It is used to start the service on the server. + +DOCKER_RUN_CMD="docker run -d \ + --restart unless-stopped \ + --name ${CONTAINER_NAME} \ + -p ${HTTP_PORT}:3000 \ + -p ${SSH_PORT}:22 \ + -v ${DATA_VOLUME}:/data \ + -e USER_UID=1000 \ + -e USER_GID=1000 \ + ${IMAGE_REGISTRY}/${IMAGE_REPO}:${IMAGE_TAG}" + +if ! _create_and_start_container "$DOCKER_RUN_CMD" "$CONTAINER_NAME"; then + _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" +echo "Access Gitea at http://localhost:${HTTP_PORT}" +echo "SSH clone available on port ${SSH_PORT}" diff --git a/gitea-server/status.sh b/gitea-server/status.sh new file mode 100755 index 0000000..b1a13d5 --- /dev/null +++ b/gitea-server/status.sh @@ -0,0 +1,31 @@ +#!/bin/bash +source "${AGENT_PATH}/common.sh" +_check_required_env_vars "CONTAINER_NAME" + +# STATUS SCRIPT +# The status script is REQUIRED. +# It is used to return the status of the service. +# Must output exactly one of: Running, Stopped, Error, Unknown + +# Check if container exists +if ! docker ps -a --format "{{.Names}}" | grep -q "^${CONTAINER_NAME}$"; then + echo "Unknown" + exit 0 +fi + +# Check container state +STATE=$(docker inspect -f '{{.State.Status}}' "$CONTAINER_NAME" 2>/dev/null) +case "$STATE" in + running) + echo "Running" + ;; + exited|stopped) + echo "Stopped" + ;; + restarting|paused) + echo "Error" + ;; + *) + echo "Unknown" + ;; +esac diff --git a/gitea-server/stop.sh b/gitea-server/stop.sh new file mode 100755 index 0000000..fe3d4df --- /dev/null +++ b/gitea-server/stop.sh @@ -0,0 +1,11 @@ +#!/bin/bash +source "${AGENT_PATH}/common.sh" +_check_required_env_vars "CONTAINER_NAME" + +# STOP SCRIPT +# The stop script is required for all templates. +# It is used to stop the service on the server. + +_stop_container $CONTAINER_NAME || _die "Failed to stop container ${CONTAINER_NAME}" + +echo "Container ${CONTAINER_NAME} stopped" diff --git a/gitea-server/uninstall.sh b/gitea-server/uninstall.sh new file mode 100755 index 0000000..d948214 --- /dev/null +++ b/gitea-server/uninstall.sh @@ -0,0 +1,18 @@ +#!/bin/bash +source "${AGENT_PATH}/common.sh" +_check_required_env_vars "CONTAINER_NAME" "IMAGE_REGISTRY" "IMAGE_REPO" "IMAGE_TAG" + +# UNINSTALL SCRIPT +# The uninstall script is required for all templates. +# It is used to uninstall the service from the server. +# IMPORTANT: This script MUST preserve data volumes! + +_remove_container "$CONTAINER_NAME" || _die "Failed to remove container ${CONTAINER_NAME}" +_is_container_running "$CONTAINER_NAME" && _die "Couldn't stop existing container" +_is_container_exists "$CONTAINER_NAME" && _die "Couldn't remove existing container" + +# Remove the image +docker rmi "$IMAGE_REGISTRY/$IMAGE_REPO:$IMAGE_TAG" || echo "Failed to remove image $IMAGE_REGISTRY/$IMAGE_REPO:$IMAGE_TAG" + +echo "Uninstallation of ${CONTAINER_NAME} complete." +echo "Data volume preserved. To remove all data, use destroy.sh"