Refactor readme, implement variable defaults

This commit is contained in:
Jafner 2021-09-30 11:16:46 -07:00
parent 75382caeff
commit 3d564d7492
3 changed files with 48 additions and 62 deletions

View File

@ -1,67 +1,41 @@
# Note: The 5e.tools domain upon which this image relies is offline indefinitely. This image will not work until this situation is resolved.
This is a simple image for hosting your own 5eTools instance. It is based on the Apache `httpd` image and uses a heavily-modified version of the auto-updater script from the [5eTools wiki](https://wiki.5e.tools/index.php/5eTools_Install_Guide). This image is built from [this GitHub repository](https://github.com/Jafner/5etools-docker). This is a simple image for hosting your own 5eTools instance. It is based on the Apache `httpd` image and uses a heavily-modified version of the auto-updater script from the [5eTools wiki](https://wiki.5e.tools/index.php/5eTools_Install_Guide). This image is built from [this GitHub repository](https://github.com/Jafner/5etools-docker).
# Usage with Docker Run # Usage
## Quickstart ## Default Configuration
You can quick-start this image by running: You can quick-start this image by running:
`docker run -d -p 80:80 --rm --name 5etools-docker -v 5etools:/usr/local/apache2/htdocs jafner/5etools-docker` `curl -o docker-compose.yml https://raw.githubusercontent.com/Jafner/5etools-docker/main/docker-compose.yml`
`docker-compose up -d && docker logs -f 5etools-docker`
Then give the container a minute or two to come online and it will be accessible at `localhost`. Then give the container a few minutes to come online and it will be accessible at `localhost:8080`.
When you stop the container, it will automatically delete itself. The downloaded files will remain in the 5etools volume, so you can always start the container back up by re-running the command. When you stop the container, it will automatically delete itself. The downloaded files will remain in the `~/5etools-docker/htdocs` directory, so you can always start the container back up by running `docker-compose up -d`.
### Getting token images ## Configuring the Setup
You can configure the container's initialization script to download image files by setting the `IMG` environment variable: The image uses a handful of environment variables to figure out how you want it to run.
`docker run -d -p 80:80 --rm --name 5etools-docker -v 5etools:/usr/local/apache2/htdocs -e IMG=true jafner/5etools-docker` By default, I assume you want to automatically download the latest files from the temporary github mirror. You can configure exactly how you want the script to run with environment variables within the docker-compose file.
This will add a significant amount of time to the container's initialization.
The `-e` flag specifies a Docker environment variable, which is passed into the container's shell environment and allows for customization of the container during the run command. Here, the environment variable is named `IMG` and this command sets the value to `true`.
### Using a persistent volume ### IMG (defaults to true)
By default, this container uses a Docker-managed persistent volume for the server files. This allows the downloaded 5eTools files to persist, even if the container is destroyed. Alternatively, you can use a host directory mapping to share files between your host file system and the container. When downloading from the `get.5e.tools` structure, grab both the base site files and the image files for the bestiary, items, adventures, etc.. This increases time and bandwidth needed to bring the server up.
#### Using a host directory mapping ### AUTOUPDATE (defaults to true)
You can persist your container's data by mapping a directory in the host's file system into the container. Assuming you want to use the directory `~/5etools-docker` on the host: Setting this to false bypasses all downloading logic and falls back to the local files if available, or exits if there is no local version.
1. Create the directories with `mkdir -p ~/5etools-docker/htdocs/download`. This will create the three nested directories necessary to run the container. ### DL_TYPE (defaults to github)
2. Run the container with `docker run -d -p 80:80 --rm --name 5etools-docker -v ~/5etools-docker/htdocs:/usr/local/apache2/htdocs jafner/5etools-docker` This can be set to "get", "github", or "mega". It is used to decide which logic to use to download the source files.
Note: host directory mappings must be absolute (cannot use `.` to refer to working directory). However, you can still refer to your working directory with `${PWD}`.
### Updating the container ### DL_LINK (defaults to temporary mirror)
Because this image is built on the auto-updater script, updating the container is very simple. Restart the container with `docker restart 5etools-docker`. When it restarts, the container will automatically check for an update and download it before starting. This can be set to the URL of the source files you want to use. For a github repository, use the HTTPS link ending with `.git`. For mega, use the full link to the file. For get, use the base domain (e.g. `https://get.5e.tools`), rather than a specific file.
Note: there is no way to disable this auto-updating behavior except to never restart the container. If you want a specific version of the container, it is recommended that you look into using the `httpd` image instead.
### Using a different port
Change the value on the left side of the `-p 80:80` flag to the desired port. Leave the value on the right alone.
### Integrating a reverse proxy ## Integrating a reverse proxy
Supporting integration of a reverse proxy is beyond the scope of this guide. Supporting integration of a reverse proxy is beyond the scope of this guide.
However, any instructions which work for the base `httpd` (Apache) image, should also work for this, as it is minimally different. However, any instructions which work for the base `httpd` (Apache) image, should also work for this, as it is minimally different.
# Usage with Docker Compose
Create the `~/5etools-docker/docker-compose.yml` file with your preferred text editor. Then add the following contents:
```yml
version: "3"
services:
5etools-docker:
container_name: 5etools-docker
image: jafner/5etools-docker:latest
volumes:
- ~/5etools-docker/htdocs:/usr/local/apache2/htdocs
environment:
- IMG=false # set to true to download images
- PUID=1000
- PGID=1000
```
If you would like to auto-load homebrew, you will need to follow the instructions in the Compose file.
# Auto-loading homebrew # Auto-loading homebrew
To use auto-loading homebrew, you will need to use a host directory mapping as described above. To use auto-loading homebrew, you will need to use a host directory mapping as described above.
1. Start the container (using either `docker run` or `docker-compose`) and wait for the container to finish starting. You can monitor its progress with `docker logs -f 5etools-docker`. 1. Online the container and wait for the container to finish starting. You can monitor its progress with `docker logs -f 5etools-docker`.
2. Assuming you are using the mapping `~/5etools-docker/htdocs:/usr/local/apache2/htdocs` place your homebrew json files into the `~/5etools-docker/htdocs/homebrew/` folder, then add their filenames to the `~/5etools-docker/htdocs/homebrew/index.json` file. 2. Assuming you are using the mapping `~/5etools-docker/htdocs:/usr/local/apache2/htdocs` place your homebrew json files into the `~/5etools-docker/htdocs/homebrew/` folder, then add their filenames to the `~/5etools-docker/htdocs/homebrew/index.json` file.
For example, if your homebrew folder contains: For example, if your homebrew folder contains:
``` ```

View File

@ -5,21 +5,25 @@ services:
image: jafner/5etools-docker:latest image: jafner/5etools-docker:latest
volumes: volumes:
- ~/5etools-docker/htdocs:/usr/local/apache2/htdocs - ~/5etools-docker/htdocs:/usr/local/apache2/htdocs
ports:
- 8080:80/tcp
environment: environment:
- IMG=true - IMG=
- PUID=1000 # defaults to "false"
- PGID=1000 # expects "true" or "false"
- AUTOUPDATE=
# defaults to "true"
# expects "true" or "false"
- AUTOUPDATE=true - DL_TYPE=
# must be set, expects "true" or "false" # defaults to "github"
# expects "get", "github", or "mega"
- DL_TYPE=get
# must be set, expects "get", "github", or "mega"
# where "get" refers to the old `get.5e.tools` structure, # where "get" refers to the old `get.5e.tools` structure,
# "github" refers to the root of a specific github repository, # "github" refers to the root of a specific github repository,
# and "mega" refers to a mega.nz download link # and "mega" refers to a mega.nz download link
- DL_LINK=https://get.5e.tools - DL_LINK=
# must be set # defaults to https://github.com/5etools-mirror-1/5etools-mirror-1.github.io.git
# expects a URL with the correct content for the DL_TYPE # expects a URL with the correct content for the DL_TYPE
# if you're using the github type, make sure the url ends with .git # if you're using the github type, make sure the url ends with .git

View File

@ -10,23 +10,31 @@ else
LOCAL_VERSION=0 LOCAL_VERSION=0
fi fi
# this variable must be passed into the environment via docker run or docker-compose # this variable can be passed into the environment via docker run or docker-compose
# since this variable is required, I declare it explicitly here # since this variable is required, I declare it explicitly here
# expects "get", "github", or "mega" # expects "get", "github", or "mega"
# where "get" refers to the old `get.5e.tools` structure, # where "get" refers to the old `get.5e.tools` structure,
# "github" refers to the root of a specific github repository, # "github" refers to the root of a specific github repository,
# and "mega" refers to a mega.nz download link # and "mega" refers to a mega.nz download link
DL_TYPE=$DL_TYPE # defaults to "github"
DL_TYPE=${DL_TYPE:-github}
# this variable must be passed into the environment via docker run or docker-compose # this variable can be passed into the environment via docker run or docker-compose
# since this variable is required, I declare it explicitly here # since this variable is required, I declare it explicitly here
# expects a URL with the correct content for the DL_TYPE # expects a URL with the correct content for the DL_TYPE
DL_LINK=$DL_LINK # defaults to the temporary github mirror
DL_LINK=${DL_LINK:-https://github.com/5etools-mirror-1/5etools-mirror-1.github.io.git}
# this variable must be passed into the environment via docker run or docker-compose # this variable can be passed into the environment via docker run or docker-compose
# since this variable is required, I declare it explicitly here # since this variable is required, I declare it explicitly here
# expects "true" or "false" # expects "true" or "false"
AUTOUPDATE=$AUTOUPDATE # defaults to "true"
AUTOUPDATE=${AUTOUPDATE:-true}
# this variable can be passed into the environment via
# expects "true" or "false"
# defaults to "false"
IMG=${IMG:-false}
if [ $AUTOUPDATE = false ]; then if [ $AUTOUPDATE = false ]; then
@ -107,7 +115,7 @@ else
git commit -m "Init" > /dev/null git commit -m "Init" > /dev/null
git remote add upstream $DL_LINK git remote add upstream $DL_LINK
fi fi
echo " === Pulling from $DL_LINK" echo " === Pulling from github... (This might take a while)"
git pull upstream master 2> /dev/null git pull upstream master 2> /dev/null
echo " === Using latest version on $DL_LINK" echo " === Using latest version on $DL_LINK"
echo " === Starting!" echo " === Starting!"