Do not install on every container start.

This commit is contained in:
Min Idzelis 2023-06-29 03:34:12 +00:00 committed by Graham Booker
parent f247c8c414
commit 0086f00e43
5 changed files with 67 additions and 56 deletions

View File

@ -141,14 +141,14 @@ uid=1001(myuser) gid=1001(myuser) groups=1001(myuser)
In the above case, if you set the `PLEX_UID` and `PLEX_GID` to `1001`, then the permissions will match that of your own user.
## Tags
In addition to the standard version and `latest` tags, there is a special `autoupdate` tag. This container behave differently than your typical containers. The `autoupdate` container does **not** have any Plex Media Server binary installed. Instead, every time this container is run, it will fetch the latest version, install it and then start the Plex Media Server.
In addition to the standard version and `latest` tags, there is a special `autoupdate` tag. This container behaves differently than typical containers. The `autoupdate` container does **not** have any Plex Media Server binary installed. Instead, every time this container is run, it checks to see if the server is installed. If it is (because you've already started this container before) it starts the server. If it wasn't installed (because this is the first time the server is starting) it will install it, then start the server.
Since containers lose their state every time they are restarted, the binary is cached in `/config/install` so it won't need to be downloaded again, but it will need to be installed every time this container starts.
This container will automatically check for new updates every day between 4:00am - 4:30am (according to timezone in `TZ`).
The `autoupdate` container will automatically check for new updates every day between 4:00am - 4:30am (according to timezone set in `TZ`).
- **AUTO_UPDATE_CHANNEL** This variable can only be `public` or `beta` (default). The `public` value restricts this check to public versions only whereas `beta` value will fetch beta versions. If the server is not logged in or you do not have Plex Pass on your account, the `beta` tagged images will be restricted to publicly available versions only.
- **FORCE_UPDATE** Set this variable to `true` in order to ignore previously cached binaries in `/config/install` upon startup. This is generally not required, but provided just-in-case. You can also manually force an update by simply deleting the `/config/install` directory.
### Forcing an update/install on startup
- Create an empty file called `_force_` in the `/config` directory. (i.e. `touch /config/_force_`) You can also manually force an update by simply recreating the image. Just restarting the container (or stopping and starting) will not normally update the existing installation within the container.
To view the Docker images head over to [https://hub.docker.com/r/plexinc/pms-docker/tags/](https://hub.docker.com/r/plexinc/pms-docker/tags/)

View File

@ -6,9 +6,12 @@ IFS=$'\n\t'
# Assumes this is running on Linux (any distro) using (intel/amd).
# This bakes the specific binary into the image, you can override these vars on command line
# DOCKERHUB_IMAGE=myorg/mycontainer ./dev/sh bake
# prompt> DOCKERHUB_IMAGE=myorg/mycontainer ./dev/sh bake
VERSION_TO_BUILD=${VERSION_TO_BUILD:-"1.32.4.7195-7c8f9d3b6"}
DOCKERHUB_IMAGE=${DOCKERHUB_IMAGE:-"plexinc/pms-docker"}
# launch with KEEP=true to keep the container after starting/running it - manual cleanup required when done
# prompt> KEEP=true ./dev.sh debug arm64v8 autoupdate
KEEP=${KEEP:-}
setup() {
# Create a multi-arch buildx builder named PlexBuilder (if it doesn't exist)
@ -49,19 +52,33 @@ debug() {
platform=$1
name=$2
autoupdate=$3
if [ "$autoupdate" = "autoupdate" ]; then
name=$name:autoupdate
else
name=$name:latest
fi
[ "$autoupdate" = "autoupdate" ] && name=$name:autoupdate || name=$name:latest
if [[ $platform == linux/arm* ]]; then
# shellcheck disable=SC2064
trap "trap - SIGTERM && docker stop debug-plex" SIGINT SIGTERM EXIT
docker run --rm --name debug-plex --platform "$platform" -e DEBUG=true "$name" &
trap "trap - SIGTERM && docker stop debug-${name/:/_}" SIGINT SIGTERM EXIT
if [ "${KEEP,,}" = "true" ]; then
if docker start "debug-${name/:/_}"; then
docker attach "debug-${name/:/_}" &
else
docker run --name "debug-${name/:/_}" --platform "$platform" -e DEBUG=true "$name" &
fi
else
docker run -rm --name "debug-${name/:/_}" --platform "$platform" -e DEBUG=true "$name" &
fi
sleep 5
docker exec -it debug-plex bash
docker exec -it "debug-${name/:/_}" bash
else
docker run --rm --name debug-plex --platform "$platform" -e DEBUG=true -it "$name" bash
if [ "${KEEP,,}" = "true" ]; then
if docker start "debug-${name/:/_}"; then
# shellcheck disable=SC2064
trap "trap - SIGTERM && docker stop debug-${name/:/_}" SIGINT SIGTERM EXIT
docker attach "debug-${name/:/_}"
else
docker run --name "debug-${name/:/_}" --platform "$platform" -e DEBUG=true -it "$name" bash
fi
else
docker run -rm --name "debug-${name/:/_}" --platform "$platform" -e DEBUG=true -it "$name" bash
fi
fi
}

View File

@ -5,22 +5,14 @@ IFS=$'\n\t'
# This script is called by the autoupdate, beta, and public tags only
DEBUG=${DEBUG:-}
FORCE_UPDATE=${FORCE_UPDATE:-}
# If we are debugging, enable trace
if [ "${DEBUG,,}" = "true" ]; then
set -x
fi
# shellcheck source=../../plex-common.sh
. /plex-common.sh
CACHED_URL=
[[ -r /config/install/plexmediaserver.url ]] && CACHED_URL=$(< /config/install/plexmediaserver.url)
if [ ! "${FORCE_UPDATE,,}" = "true" ] && [ -n "$CACHED_URL" ] && [ -f /config/install/plexmediaserver.deb ]; then
echo "Installing previously downloaded plex version..."
installFromRawUrl "$CACHED_URL"
else
if [ -f /config/_force_ ] || ! dpkg --get-selections plexmediaserver 2> /dev/null | grep -wq "install"; then
echo "Downloading latest plex version..."
exec /etc/plex/plex-update
fi

View File

@ -38,7 +38,8 @@ else
# This pre-installs the specified version in TAG into this docker image.
remoteVersion=
remoteFile=
getVersionInfo "${TAG}" "" remoteVersion remoteFile
remoteFileHashSha256=
getVersionInfo "${TAG}" "" remoteVersion remoteFile remoteFileHashSha256
if [ -z "${remoteVersion}" ] || [ -z "${remoteFile}" ]; then
echo "Could not get install version"
@ -46,7 +47,5 @@ else
fi
echo "Attempting to install: ${remoteVersion}"
installFromUrl "${remoteFile}"
# delete unnecessary installer
rm -rf /config/install
installFromUrl "${remoteFile}" "${remoteFileHashSha256}"
fi

View File

@ -3,7 +3,6 @@ set -euo pipefail
IFS=$'\n\t'
PLEX_UPDATE_CHANNEL=${PLEX_UPDATE_CHANNEL:-}
FORCE_UPDATE=${FORCE_UPDATE:-}
CONT_CONF_FILE="/version.txt"
@ -31,6 +30,7 @@ function getVersionInfo {
local token="$2"
local -n getVersionInfo_remoteVersion=$3
local -n getVersionInfo_remoteFile=$4
local -n getVersionInfo_remoteFileHashSha256=$5
local channel=
local tokenNeeded=1
@ -77,37 +77,40 @@ function installFromRawUrl {
local remoteFile="$1"
local expectedSha256="${2:-}"
# if download url matches and download is cached, then install it without download
[[ -r /config/install/plexmediaserver.url ]] && oldurl=$(< /config/install/plexmediaserver.url)
if [ ! "${FORCE_UPDATE,,}" = "true" ] && [ "$remoteFile" = "${oldurl:-}" ] && [ -f /config/install/plexmediaserver.deb ]; then
rm -rf /tmp/plexmediaserver.deb
if curl --create-dirs -J -L -o /tmp/plexmediaserver.deb "${remoteFile}" ; then
if [ -n "$expectedSha256" ]; then
sha256=$(sha256sum /tmp/plexmediaserver.deb | awk '{ print $1 }')
# compare sha256, if provided
if [ ! "$expectedSha256" = "$sha256" ]; then
cleanup "Download failed: sha256sum does not match: expected=$expectedSha256 actual=$sha256"
fi
else
# no sha256, check if size appears ok
if [[ $(stat -c %s /tmp/plexmediaserver.deb) -lt 10000 ]]; then
# shellcheck disable=SC2119
cleanup "Download failed: size appears wrong"
fi
fi
# looks good, move tmp into position
install "$remoteFile"
return $?
else
# shellcheck disable=SC2119
cleanup
fi
}
curl --create-dirs -J -L -o /config/install/tmp/plexmediaserver.deb "${remoteFile}"
local last=$?
local sha256;
sha256=$(sha256sum /config/install/tmp/plexmediaserver.deb | awk '{ print $1 }')
echo "$sha256" > /config/install/tmp/plexmediaserver.sha256
echo "$remoteFile" > /config/install/tmp/plexmediaserver.url
# test if deb file size is ok, or if download failed
if [[ "$last" -gt "0" ]] || [[ $(stat -c %s /config/install/tmp/plexmediaserver.deb) -lt 10000 ]]; then
rm -rf /config/install/tmp
echo "Failed to fetch update: curl returned $last"
exit 1
fi
# compare sha256, if provided
if [ -n "$expectedSha256" ] && [ ! "$expectedSha256" = "$sha256" ]; then
rm -rf /config/install/tmp
echo "Failed to fetch update: sha256sum does not match: expected=$expectedSha256 actual=$sha256"
exit 1
fi
# looks good, move tmp into position
mv /config/install/tmp/* /config/install && rm -rf /config/install/tmp
install "$remoteFile"
function cleanup {
local msg="${1:-"Download failed"}"
rm -rf /tmp/plexmediaserver.deb
echo "$msg"
exit 1
}
function install {
dpkg -i --force-confold /config/install/plexmediaserver.deb
dpkg -i --force-confold /tmp/plexmediaserver.deb
rm -rf /tmp/plexmediaserver.deb
# clean up _force_ flag, if exists
rm -rf /config/_force_
}