Skip to content

Commit

Permalink
Add documentation for custom env file + add local-persist install scr…
Browse files Browse the repository at this point in the history
…ipt (with a fix from official version)
  • Loading branch information
jfroment committed Nov 24, 2024
1 parent a9cce9c commit 0d81955
Show file tree
Hide file tree
Showing 5 changed files with 208 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Check the [Configuration Guide](doc/configuration.md).

- [Docker](https://github.com/docker/docker) >= 20.10
- [Docker Compose](https://github.com/docker/compose) >= 2.27.0
- [local-persist Docker plugin](https://github.com/MatchbookLab/local-persist): installed directly on host (not in container). This is a volume plugin that extends the default local driver’s functionality by allowing you specify a mountpoint anywhere on the host, which enables the files to always persist, even if the volume is removed via `docker volume rm`. Use *systemd* install for Ubuntu.
- [local-persist Docker plugin](https://github.com/MatchbookLab/local-persist): installed directly on host (not in container). This is a volume plugin that extends the default local driver’s functionality by allowing you specify a mountpoint anywhere on the host, which enables the files to always persist, even if the volume is removed via `docker volume rm`. Use *systemd* install for Ubuntu. **Since v2.2 the install script is bundled in seedbox's init script.**
- [jq](https://stedolan.github.io/jq/download/) >= 1.5
- [yq](https://github.com/mikefarah/yq/releases) >= 4

Expand All @@ -99,7 +99,7 @@ sudo su -c "mkdir /data && mkdir /data/config && mkdir /data/torrents"
./init.sh
```

Edit the `.env` file and change the variables as desired.
Edit the ``.env`` and ``.env.custom`` files and change the variables as desired.
The variables are all self-explanatory.

### Review the configuration
Expand Down
32 changes: 30 additions & 2 deletions doc/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,39 @@ Some general rules:
Also, do not forget to edit your ``.env`` file, which is where all the data which will be sent to containers (passwords, tokens, uid for disk permission...) lives.
> ⚠️ Since v2.2 release, environment variable live in two places: ``.env`` for common/global variables, common for the whole stack, and ``.env.custom`` where variables are specific for services **and prefixed with the service name**. Read below for forther explanations.
### Global variables
All variables releated to the stack itself live in the ``.env`` file. They concern:
* Traefik configuration (domain name, ACME mail, http-auth credentials...)
* Disk UUID/GUID
* Timezone
* Paths on your system/network and directories to organize your data and map docker volumes
### Services variables
This is a new feature in v2.2. For variables specific for a service, they are located in two places:
* directly in the docker-compose service file (for example the one for [ntfy](../services/ntfy.yaml)) under the ``environment:`` section. Mostly, they are generic here and do not contain sensitive information or customization.
* in the [.env.custom](../.env.custom.sample) file, where variables **must be prefixed with the service name in uppercase and a "_"**, they will be injected on the corresponding service.
*Example*: let's say you have a service called ``WONDERFULAPP``, and want it to use the environment variable ``MYKEY`` with the value ``ImAwesome``.
Simply add the following line in ``.env.custom``:
```yaml
#[...]
# Add this line to add the variable "MYKEY" with value "ImAwesome" to the service "WONDERFULAPP".
WONDERFULAPP_MYKEY: "ImAwesome"
#[...]
```

## Add your own service

Let's say you want to add a container nginx without interfering or creating conflicts in this git repository. That's possible.

Start by creating a file named nginx.yaml in the [services/custom/](services/custom/) directory:
Start by creating a file named nginx.yaml in the [services/custom/](../services/custom/) directory:

```yaml
services:
Expand Down Expand Up @@ -270,7 +298,7 @@ If your media is not on the same machine as your containers, do the following:
## Make the services communicate with each other
With docker-compose, all services are in the same Docker network (it is called ``traefik-network`` and is defined [here](../docker-compose.yaml)). Docker provides DNS resolution in the same network based on the name of the services, which act as hostnames.
With docker-compose, all services are in the same Docker network (it is called ``traefik-network`` and is defined [here](../docker-compose.sample.yaml)). Docker provides DNS resolution in the same network based on the name of the services, which act as hostnames.
So, for example, in order to setup Deluge in Sonarr, just add ``http://deluge:8112`` in the Download Clients settings section in Sonarr.
Expand Down
16 changes: 16 additions & 0 deletions init.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
#!/bin/bash

echo "[$0] Initializing..."

# Create docker network
docker network create traefik-network 2>&1 || true

echo "Installing local-persist docker driver... (will prompt for password for sudo access)"
sudo tools/local-persist.sh

# Copy env file
if [[ ! -f .env ]]; then
cp .env.sample .env
echo "[$0] Please edit .env file"
fi

# Copy custom env file
if [[ ! -f .env.custom ]]; then
cp .env.custom.sample .env.custom
echo "[$0] Please edit .env.custom file if you want more customization (see documentation)."
fi

# Copy sample docker compose file
if [[ ! -f docker-compose.yaml ]]; then
cp docker-compose.sample.yaml docker-compose.yaml
fi

echo "[$0] Done."
exit 0
2 changes: 1 addition & 1 deletion run-seedbox.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ if [[ ! -f .env ]]; then
fi

if [[ ! -f docker-compose.yaml ]]; then
echo "[$0] ERROR. \"docker-compose.yaml\" file not found. Please copy \"docker-compose.sample.yaml\" and edit its valuesif you need customization. Then, re-run this script."
echo "[$0] ERROR. \"docker-compose.yaml\" file not found. Please copy \"docker-compose.sample.yaml\" and edit its values if you need customization. Then, re-run this script."
exit 1
fi

Expand Down
159 changes: 159 additions & 0 deletions tools/local-persist.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
#!/usr/bin/env bash

set -e

VERSION="v1.3.0"

gitDir=$(realpath `dirname $BASH_SOURCE`/..)
echo $gitDir

# uname -s, uname -m
# Deb 32: Linux i686
# Ubuntu 64: Linux x86_64
# FreeBSD: FreeBSD amd64

if [[ "$UID" != 0 ]]; then
echo NOTE: sudo needed to set up and run start service
exit 1
fi


if [[ `git -C "${gitDir}" rev-parse --is-inside-work-tree 2> /dev/null` == "true" ]]; then
thisGit=`git -C "${gitDir}" config --get remote.origin.url`
thisGit=${thisGit::-4}
GITHUB_BINARY_BASE="${thisGit}/releases/download"
GITHUB_RAW_BASE="${thisGit/github.com/raw.githubusercontent.com}/releases/download"
fi

if [[ $thisGit == "" ]]; then
GITHUB_URL_PARTS="MatchbookLab/local-persist"
GITHUB_BINARY_BASE="https://github.com/${GITHUB_URL_PARTS}/releases/download"
GITHUB_RAW_BASE="https://raw.githubusercontent.com/${GITHUB_URL_PARTS}/"
GITHUB_URL_PARTS=
fi


function setenv {
OS=$(uname -s | tr "[:upper:]" "[:lower:]")
ARCH=$(uname -m)

SUPPORTED=false
if [[ $OS == "linux" ]]; then
case $ARCH in
"x86_64")
ARCH="amd64"
SUPPORTED=true
;;
"aarch64")
ARCH="arm64"
SUPPORTED=true
;;
"i686")
# ARCH="386"
SUPPORTED=false
;;
# untested
arm*)
# ARCH="arm"
SUPPORTED=false
;;
esac
elif [[ $OS == 'freebsd' ]]; then
ARCH=$(uname -m)
SUPPORTED=false
fi

if [[ $SUPPORTED == false ]]; then
echo $OS $ARCH is not supported
exit 2
fi
}

function install-binary {
echo Stopping docker-volume-local-persist service if running
echo ''
if [[ $* == *--upstart* ]]; then
(sudo service docker-volume-local-persist stop || true)
else
(sudo systemctl stop docker-volume-local-persist || true)
fi

BINARY_URL="${GITHUB_BINARY_BASE}/${VERSION}/local-persist-${OS}-${ARCH}"
BINARY_DEST="/usr/bin/docker-volume-local-persist"

echo Downloading binary:
echo " From: $BINARY_URL"
echo " To: $BINARY_DEST"

curl -fLsS "$BINARY_URL" > $BINARY_DEST
chmod +x $BINARY_DEST

echo Binary download
echo ''
}

# Systemd (default)
function setup-systemd {
SYSTEMD_CONFIG_URL="${GITHUB_RAW_BASE}/${VERSION}/init/systemd.service"
SYSTEMD_CONFIG_DEST="/etc/systemd/system/docker-volume-local-persist.service"

echo Downloading Systemd service conf:
echo " From: $SYSTEMD_CONFIG_URL"
echo " To: $SYSTEMD_CONFIG_DEST"

sudo curl -fLsS "$SYSTEMD_CONFIG_URL" > $SYSTEMD_CONFIG_DEST

echo Systemd conf downloaded
echo ''
}

function start-systemd {
echo Starting docker-volume-local-persist service...

sudo systemctl daemon-reload
sudo systemctl enable docker-volume-local-persist
sudo systemctl start docker-volume-local-persist
sudo systemctl status --full --no-pager docker-volume-local-persist

echo ''
echo Done! If you see this message, that should mean everything is installed and is running.
}

# Upstart
function setup-upstart {
UPSTART_CONFIG_URL="${GITHUB_RAW_BASE}/${VERSION}/init/upstart.conf"
UPSTART_CONFIG_DEST="/etc/init/docker-volume-local-persist.conf"

echo Downloading binary:
echo " From: $UPSTART_CONFIG_URL"
echo " To: $UPSTART_CONFIG_DEST"

sudo curl -fLsS "$UPSTART_CONFIG_URL" > $UPSTART_CONFIG_DEST

echo Upstart conf downloaded
echo ''
}

function start-upstart {
echo Reloading Upstart config and starting docker-volume-local-persist service...

sudo initctl reload-configuration
sudo service docker-volume-local-persist start
sudo service docker-volume-local-persist status

echo ''
echo Done! If you see this message, that should mean everything is installed and is running.
}


setenv

if [[ $* == *--upstart* ]]; then
install-binary --upstart
setup-upstart
start-upstart
else
install-binary
setup-systemd
start-systemd
fi

0 comments on commit 0d81955

Please sign in to comment.