Add app nextcloud

This commit is contained in:
Nicolas Meienberger 2022-03-29 20:40:04 +00:00
parent b8004870dc
commit 631038f76b
9 changed files with 253 additions and 13 deletions

7
.gitignore vendored
View File

@ -2,6 +2,11 @@
nginx/*
letsencrypt/*
app-data/*
# Commit empty directories
!nignx/.gitkeep
!letsencrypt/.gitkeep
!letsencrypt/.gitkeep
!app-data/nextcloud/.gitkeep
!app-data/wg-easy/.gitkeep

View File

@ -0,0 +1,7 @@
version: "3.7"
networks:
default:
external:
name: tipi_main_network

View File

@ -0,0 +1,62 @@
version: "3.7"
services:
db:
image: mariadb:10.5.12
command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
restart: on-failure
volumes:
- ${APP_DATA_DIR}/data/db:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=moneyprintergobrrr
- MYSQL_PASSWORD=moneyprintergobrrr
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
networks:
default:
ipv4_address: $APP_NEXTCLOUD_DB_IP
redis:
image: redis:6.2.2-buster
restart: on-failure
volumes:
- "${APP_DATA_DIR}/data/redis:/data"
networks:
default:
ipv4_address: $APP_NEXTCLOUD_REDIS_IP
web:
image: nextcloud:22.1.1-apache
restart: unless-stopped
ports:
- ${APP_NEXTCLOUD_PORT}:80
volumes:
- ${APP_DATA_DIR}/data/nextcloud:/var/www/html
environment:
- MYSQL_HOST=${APP_NEXTCLOUD_DB_IP}
- REDIS_HOST=${APP_NEXTCLOUD_REDIS_IP}
- MYSQL_PASSWORD=moneyprintergobrrr
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
- NEXTCLOUD_ADMIN_USER=tipi
- NEXTCLOUD_ADMIN_PASSWORD=moneyprintergobrrr
- NEXTCLOUD_TRUSTED_DOMAINS=${APP_NEXTCLOUD_PORT}
depends_on:
- db
- redis
networks:
default:
ipv4_address: $APP_NEXTCLOUD_IP
cron:
image: nextcloud:22.0.0-apache
restart: on-failure
volumes:
- ${APP_DATA_DIR}/data/nextcloud:/var/www/html
entrypoint: /cron.sh
depends_on:
- db
- redis
networks:
default:
ipv4_address: $APP_NEXTCLOUD_CRON_IP

View File

@ -1,11 +1,10 @@
version: '3.7'
services:
wg-easy:
container_name: wg-easy
image: 'weejewel/wg-easy'
restart: unless-stopped
volumes:
- ${DATA_FOLDER}/wg-easy:/etc/wireguard
- ${APP_DATA_DIR}:/etc/wireguard
environment:
WG_HOST: 'wireguard.meienberger.dev'
PASSWORD: 'moneyprintergobrrr'

View File

@ -2,10 +2,8 @@ version: '3.7'
services:
nginx-proxy:
container_name: nginx-proxy
image: 'jc21/nginx-proxy-manager:latest'
restart: unless-stopped
# user: "1000:1000"
ports:
- '80:80'
- '81:81'

136
scripts/app.sh Executable file
View File

@ -0,0 +1,136 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT_FOLDER="$(readlink -f $(dirname "${BASH_SOURCE[0]}")/..)"
STATE_FOLDER="${ROOT_FOLDER}/state"
show_help() {
cat << EOF
app 0.0.1
CLI for managing Tipi apps
Usage: app <command> <app> [<arguments>]
Commands:
install Pulls down images for an app and starts it
uninstall Removes images and destroys all data for an app
stop Stops an installed app
start Starts an installed app
compose Passes all arguments to docker-compose
ls-installed Lists installed apps
EOF
}
# Get field from json file
function get_json_field() {
local json_file="$1"
local field="$2"
echo $(jq -r ".${field}" "${json_file}")
}
list_installed_apps() {
str=$(get_json_field ${STATE_FOLDER}/apps.json installed)
echo $str
}
if [ -z ${1+x} ]; then
command=""
else
command="$1"
fi
# Lists installed apps
if [[ "$command" = "ls-installed" ]]; then
list_installed_apps
exit
fi
if [ -z ${2+x} ]; then
show_help
exit 1
else
app="$2"
app_dir="${ROOT_FOLDER}/apps/${app}"
app_data_dir="${ROOT_FOLDER}/app-data/${app}"
if [[ -z "${app}" ]] || [[ ! -d "${app_dir}" ]]; then
echo "Error: \"${app}\" is not a valid app"
exit 1
fi
fi
if [ -z ${3+x} ]; then
args=""
else
args="${@:3}"
fi
compose() {
local app="${1}"
shift
# App data folder
local env_file="${ROOT_FOLDER}/.env"
local app_base_compose_file="${ROOT_FOLDER}/apps/docker-compose.common.yml"
local app_compose_file="${app_dir}/docker-compose.yml"
# Vars to use in compose file
export APP_DATA_DIR="${app_data_dir}"
docker-compose \
--env-file "${env_file}" \
--project-name "${app}" \
--file "${app_base_compose_file}" \
--file "${app_compose_file}" \
"${@}"
}
# Removes images and destroys all data for an app
if [[ "$command" = "uninstall" ]]; then
echo "Removing images for app ${app}..."
compose "${app}" down --rmi all --remove-orphans
echo "Deleting app data for app ${app}..."
if [[ -d "${app_data_dir}" ]]; then
rm -rf "${app_data_dir}"
fi
echo "Removing app ${app} from DB..."
update_installed_apps remove "${app}"
echo "Successfully uninstalled app ${app}"
exit
fi
# Stops an installed app
if [[ "$command" = "stop" ]]; then
echo "Stopping app ${app}..."
compose "${app}" rm --force --stop
exit
fi
# Starts an installed app
if [[ "$command" = "start" ]]; then
echo "Starting app ${app}..."
compose "${app}" up --detach
exit
fi
# Passes all arguments to docker-compose
if [[ "$command" = "compose" ]]; then
compose "${app}" ${args}
exit
fi
# If we get here it means no valid command was supplied
# Show help and exit
show_help
exit 1

View File

@ -1,3 +1,5 @@
#!/usr/bin/env bash
ROOT_FOLDER="$(readlink -f $(dirname "${BASH_SOURCE[0]}")/..)"
STATE_FOLDER="${ROOT_FOLDER}/state"
@ -9,7 +11,7 @@ if [[ $UID != 0 ]]; then
fi
# Run docker-compose
# docker-compose up -d
docker-compose up -d
# Get field from json file
function get_json_field() {
@ -23,10 +25,6 @@ str=$(get_json_field ${STATE_FOLDER}/apps.json installed)
apps_to_start=($str)
for app in "${apps_to_start[@]}"; do
echo "Starting app: $app"
"${ROOT_FOLDER}/scripts/app.sh" start $app
done
# App data folder
app_data_folder="${UMBREL_ROOT}/app-data/${app}"
docker-compose -f ${ROOT_FOLDER}/apps/${app}/docker-compose.yml --env-file ${ROOT_FOLDER}/.env -e DATA_FOLDER=${app_data_folder} up -d
done

35
scripts/stop.sh Executable file
View File

@ -0,0 +1,35 @@
#!/usr/bin/env bash
set -euo pipefail
if [[ $UID != 0 ]]; then
echo "Tipi must be stopped as root"
echo "Please re-run this script as"
echo " sudo ./scripts/stop"
exit 1
fi
ROOT_FOLDER="$(readlink -f $(dirname "${BASH_SOURCE[0]}")/..)"
STATE_FOLDER="${ROOT_FOLDER}/state"
cd "$ROOT_FOLDER"
export DOCKER_CLIENT_TIMEOUT=240
export COMPOSE_HTTP_TIMEOUT=240
function get_json_field() {
local json_file="$1"
local field="$2"
echo $(jq -r ".${field}" "${json_file}")
}
str=$(get_json_field ${STATE_FOLDER}/apps.json installed)
apps_to_start=($str)
for app in "${apps_to_start[@]}"; do
"${ROOT_FOLDER}/scripts/app.sh" stop $app
done
echo "Stopping Docker services..."
echo
docker-compose down

View File

@ -1,3 +1,3 @@
{
"installed": "wg-easy"
"installed": "wg-easy nextcloud"
}