Update Docker utility scripts and readmes.

This commit is contained in:
Buster "Silver Eagle" Neece 2018-04-23 22:37:15 -05:00
parent 65b30ce58f
commit cd004383fa
6 changed files with 194 additions and 126 deletions

View File

@ -66,39 +66,12 @@ If you want a more "bare-metal" experience and greater customization, you can al
We strongly recommend installing and using AzuraCast via Docker. All of the necessary software packages are built by our automated tools, so installation is as easy as just pulling down the pre-compiled images. There's no need to worry about compatibility with your host operating system, so any host (including Windows and MacOS) will work great out of the box.
#### Step 1: Install Docker and Docker Compose
Your computer or server should be running the newest version of Docker and Docker Compose. You can use the easy scripts below to install both if you're starting from scratch:
You can use the AzuraCast Docker installer to check for (and install, if necessary) the latest version of Docker and Docker Compose, then pull the necessary files and get your instance running.
```bash
wget -qO- https://get.docker.com/ | sh
COMPOSE_VERSION=`git ls-remote https://github.com/docker/compose | grep refs/tags | grep -oP "[0-9]+\.[0-9][0-9]+\.[0-9]+$" | tail -n 1`
sudo sh -c "curl -L https://github.com/docker/compose/releases/download/${COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose"
sudo chmod +x /usr/local/bin/docker-compose
sudo sh -c "curl -L https://raw.githubusercontent.com/docker/compose/${COMPOSE_VERSION}/contrib/completion/bash/docker-compose > /etc/bash_completion.d/docker-compose"
```
If you're not installing as root, you may be given instructions to add your current user to the Docker group (i.e. `usermod -aG docker $user`). You should log out or reboot after doing this before continuing below.
#### Step 2: Pull the AzuraCast Docker Compose File
Choose where on the host computer you would like AzuraCast's configuration file to exist on your server.
Inside that directory, run this command to pull the Docker Compose configuration file.
```bash
curl -L https://raw.githubusercontent.com/AzuraCast/AzuraCast/master/docker-compose.sample.yml > docker-compose.yml
```
#### Step 3: Run the AzuraCast Docker Installer
From the directory that contains your YML configuration file, run these commands:
```bash
docker-compose pull
docker-compose run --rm cli azuracast_install
docker-compose up -d
curl -L https://raw.githubusercontent.com/AzuraCast/AzuraCast/master/docker.sh > docker.sh
chmod a+x docker.sh
./docker.sh install
```
#### Setting up HTTPS with LetsEncrypt
@ -131,7 +104,9 @@ docker-compose run --rm letsencrypt renew --webroot -w /var/www/letsencrypt
#### Updating with Docker
From inside the base directory where AzuraCast is copied, run the following commands:
If you have the `docker.sh` script from the installation steps above, you can run `./docker.sh update` to automatically update your installation.
To manually update, from inside the base directory where AzuraCast is copied, run the following commands:
```bash
docker-compose down

View File

@ -1,24 +0,0 @@
#!/usr/bin/env bash
#
# Usage:
# ./docker-backup.sh [/custom/backup/dir/custombackupname.tar.gz]
#
APP_BASE_DIR=$(pwd)
BACKUP_PATH=${1:-"./backup.tar.gz"}
BACKUP_DIR=$(cd `dirname "$BACKUP_PATH"` && pwd)
BACKUP_FILENAME=`basename "$BACKUP_PATH"`
cd $APP_BASE_DIR
docker-compose down
docker run --rm -v $BACKUP_DIR:/backup \
-v azuracast_db_data:/azuracast/db \
-v azuracast_influx_data:/azuracast/influx \
-v azuracast_station_data:/azuracast/stations \
busybox tar zcvf /backup/$BACKUP_FILENAME /azuracast
docker-compose up -d

View File

@ -1,34 +0,0 @@
#!/usr/bin/env bash
#
# Usage:
# ./docker-restore.sh [/custom/backup/dir/custombackupname.tar.gz]
#
APP_BASE_DIR=$(pwd)
BACKUP_PATH=${1:-"./backup.tar.gz"}
BACKUP_DIR=$(cd `dirname "$BACKUP_PATH"` && pwd)
BACKUP_FILENAME=`basename "$BACKUP_PATH"`
cd $APP_BASE_DIR
if [ -f $BACKUP_PATH ]; then
docker-compose down
docker volume rm azuracast_db_data azuracast_influx_data azuracast_station_data
docker volume create azuracast_db_data
docker volume create azuracast_influx_data
docker volume create azuracast_station_data
docker run --rm -v $BACKUP_DIR:/backup \
-v azuracast_db_data:/azuracast/db \
-v azuracast_influx_data:/azuracast/influx \
-v azuracast_station_data:/azuracast/stations \
busybox tar zxvf /backup/$BACKUP_FILENAME
docker-compose up -d
else
echo "File $BACKUP_PATH does not exist in this directory. Nothing to restore."
exit 1
fi

View File

@ -1,13 +0,0 @@
#!/usr/bin/env bash
read -p "This operation is destructive and will wipe your existing Docker containers. Continue? [y/N] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
docker-compose down -v
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
docker volume prune -f
fi

View File

@ -1,23 +0,0 @@
#!/usr/bin/env bash
docker-compose down
docker-compose rm -f
read -p "Update docker-compose.yml file? This will overwrite any customizations you made to this file. [y/N] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
cp docker-compose.yml docker-compose.backup.yml
echo "Your existing docker-compose.yml file has been backed up to docker-compose.backup.yml."
curl -L https://raw.githubusercontent.com/AzuraCast/AzuraCast/master/docker-compose.sample.yml > docker-compose.yml
echo "New docker-compose.yml file loaded."
fi
docker-compose pull
docker-compose run --rm cli azuracast_update
docker-compose up -d
docker rmi $(docker images | grep "none" | awk '/ / { print $3 }')

187
docker.sh Executable file
View File

@ -0,0 +1,187 @@
#!/usr/bin/env bash
# This is a general-purpose function to ask Yes/No questions in Bash, either
# with or without a default answer. It keeps repeating the question until it
# gets a valid answer.
ask() {
# https://djm.me/ask
local prompt default reply
while true; do
if [ "${2:-}" = "Y" ]; then
prompt="Y/n"
default=Y
elif [ "${2:-}" = "N" ]; then
prompt="y/N"
default=N
else
prompt="y/n"
default=
fi
# Ask the question (not using "read -p" as it uses stderr not stdout)
echo -n "$1 [$prompt] "
# Read the answer (use /dev/tty in case stdin is redirected from somewhere else)
read reply </dev/tty
# Default?
if [ -z "$reply" ]; then
reply=$default
fi
# Check if the reply is valid
case "$reply" in
Y*|y*) return 0 ;;
N*|n*) return 1 ;;
esac
done
}
#
# Usage: ./docker.sh install
#
install() {
if [[ $(which docker) && $(docker --version) ]]; then
echo "Docker is already installed! Continuing..."
else
if ask "Docker does not appear to be installed. Install Docker now?" Y; then
curl -fsSL get.docker.com -o get-docker.sh
sh get-docker.sh
rm get-docker.sh
if [[ $EUID -ne 0 ]]; then
sudo usermod -aG docker `whoami`
echo "You must log out or restart to apply necessary Docker permissions changes."
echo "Restart, then continue installing using this script."
exit
fi
fi
fi
if [[ $(which docker-compose) ]]; then
echo "Docker Compose is already installed! Continuing..."
else
if ask "Docker Compose does not appear to be installed. Install Docker Compose now?" Y; then
COMPOSE_VERSION=`git ls-remote https://github.com/docker/compose | grep refs/tags | grep -oP "[0-9]+\.[0-9][0-9]+\.[0-9]+$" | tail -n 1`
sudo sh -c "curl -L https://github.com/docker/compose/releases/download/${COMPOSE_VERSION}/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose"
sudo chmod +x /usr/local/bin/docker-compose
sudo sh -c "curl -L https://raw.githubusercontent.com/docker/compose/${COMPOSE_VERSION}/contrib/completion/bash/docker-compose > /etc/bash_completion.d/docker-compose"
fi
fi
if [ ! -f .env ]; then
echo "Writing default .env file..."
curl -L https://raw.githubusercontent.com/AzuraCast/AzuraCast/master/.env > .env
fi
if [ ! -f docker-compose.yml ]; then
echo "Retrieving default docker-compose.yml file..."
curl -L https://raw.githubusercontent.com/AzuraCast/AzuraCast/master/docker-compose.sample.yml > docker-compose.yml
fi
docker-compose pull
docker-compose run --rm cli azuracast_install
docker-compose up -d
}
#
# Usage: ./docker.sh update
#
update() {
docker-compose down
docker-compose rm -f
if ask "Update docker-compose.yml file? This will overwrite any customizations you made to this file?" N; then
cp docker-compose.yml docker-compose.backup.yml
echo "Your existing docker-compose.yml file has been backed up to docker-compose.backup.yml."
curl -L https://raw.githubusercontent.com/AzuraCast/AzuraCast/master/docker-compose.sample.yml > docker-compose.yml
echo "New docker-compose.yml file loaded."
fi
docker-compose pull
docker-compose run --rm cli azuracast_update
docker-compose up -d
docker rmi $(docker images | grep "none" | awk '/ / { print $3 }')
}
#
# Usage:
# ./docker.sh backup [/custom/backup/dir/custombackupname.tar.gz]
#
backup() {
APP_BASE_DIR=$(pwd)
BACKUP_PATH=${1:-"./backup.tar.gz"}
BACKUP_DIR=$(cd `dirname "$BACKUP_PATH"` && pwd)
BACKUP_FILENAME=`basename "$BACKUP_PATH"`
cd $APP_BASE_DIR
docker-compose down
docker run --rm -v $BACKUP_DIR:/backup \
-v azuracast_db_data:/azuracast/db \
-v azuracast_influx_data:/azuracast/influx \
-v azuracast_station_data:/azuracast/stations \
busybox tar zcvf /backup/$BACKUP_FILENAME /azuracast
docker-compose up -d
}
#
# Usage:
# ./docker.sh restore [/custom/backup/dir/custombackupname.tar.gz]
#
restore() {
APP_BASE_DIR=$(pwd)
BACKUP_PATH=${1:-"./backup.tar.gz"}
BACKUP_DIR=$(cd `dirname "$BACKUP_PATH"` && pwd)
BACKUP_FILENAME=`basename "$BACKUP_PATH"`
cd $APP_BASE_DIR
if [ -f $BACKUP_PATH ]; then
docker-compose down
docker volume rm azuracast_db_data azuracast_influx_data azuracast_station_data
docker volume create azuracast_db_data
docker volume create azuracast_influx_data
docker volume create azuracast_station_data
docker run --rm -v $BACKUP_DIR:/backup \
-v azuracast_db_data:/azuracast/db \
-v azuracast_influx_data:/azuracast/influx \
-v azuracast_station_data:/azuracast/stations \
busybox tar zxvf /backup/$BACKUP_FILENAME
docker-compose up -d
else
echo "File $BACKUP_PATH does not exist in this directory. Nothing to restore."
exit 1
fi
}
#
# Usage: ./docker.sh uninstall
#
uninstall() {
if ask "This operation is destructive and will wipe your existing Docker containers. Continue? [y/N] " N; then
docker-compose down -v
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
docker volume prune -f
fi
}
$*