Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Autoupdate" feature. Update S6. Shellcheck. #81

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ FROM ubuntu:22.04 as base-amd64
ARG S6_OVERLAY_VERSION=v3.1.5.0
ARG S6_OVERLAY_ARCH=x86_64
ARG PLEX_BUILD=linux-x86_64
ARG PLEX_DISTRO=debian
ARG INTEL_NEO_VERSION=20.48.18558
ARG INTEL_IGC_VERSION=1.0.5699
ARG INTEL_GMMLIB_VERSION=20.3.2
Expand Down Expand Up @@ -71,17 +70,18 @@ RUN \
EXPOSE 32400/tcp 8324/tcp 32469/tcp 1900/udp 32410/udp 32412/udp 32413/udp 32414/udp
VOLUME /config /transcode

ARG AUTOUPDATE=false
ARG TAG=beta
# TAG can be "autoupdate" or an explicit version, like 1.32.4.7195-7c8f9d3b6
ARG TAG="autoupdate"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not certain about making the auto update the default behavior. It is antithetical to docker but then so is the current default of beta so 🤷 .

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I made this comment, I didn't realize that your work is effectively supplanting the public and beta tags. So, assuming that I have that correct, then this change isn't really a change.

ARG URL=
ARG DEBUG=

ENV TAG=${TAG} \
CHANGE_CONFIG_DIR_OWNERSHIP="true" \
ENV CHANGE_CONFIG_DIR_OWNERSHIP="true" \
HOME="/config" \
TZ="UTC" \
# Note, only used for images built with TAG=autoupdate
AUTO_UPDATE_CHANNEL="beta" \
\
TERM="xterm" \
LANG="C.UTF-8" \
TERM="xterm" \
LANG="C.UTF-8" \
LC_ALL="C.UTF-8" \
\
S6_KEEP_ENV=1 \
Expand All @@ -94,8 +94,11 @@ COPY root/ /

RUN \
# Save version and install
/installBinary.sh
/installBinary.sh \
&& \
# Clean up installer
rm /installBinary.sh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this intended to cleanup a deb file instead of removing the script to install debs?


HEALTHCHECK --interval=5s --timeout=2s --retries=20 CMD /healthcheck.sh || exit 1

ENTRYPOINT ["/init"]
ENTRYPOINT ["/init"]
29 changes: 21 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ The provided `docker-compose` templates use the `plexinc/pms-docker` image which
To use `docker-compose` with ARM devices, you must first build one of the ARM images locally.

```sh
docker build -t plexinc/pms-docker:latest -f Dockerfile.armv7 . # or arm64
# arm 32 bit
docker build --platform linux/arm/v7 -t plexinc/pms-docker:latest .
# arm 64 bit
docker build --platform linux/arm64 -t plexinc/pms-docker:latest .
```

Then you can `docker-compose up`.
Expand Down Expand Up @@ -138,9 +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, two other tags exist: `beta` and `public`. These two images behave differently than your typical containers. These two images do **not** have any Plex Media Server binary installed. Instead, when these containers are run, they will perform an update check and fetch the latest version, install it, and then continue execution. They also run the update check whenever the container is restarted. To update the version in the container, simply stop the container and start container again when you have a network connection. The startup script will automatically fetch the appropriate version and install it before starting the Plex Media Server.
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.

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`).

- **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.

The `public` restricts this check to public versions only where as `beta` 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.

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/)

Expand All @@ -158,11 +166,16 @@ If you wish to migrate an existing directory to the docker config directory:
- Note: by default Plex will claim ownership of the entire contents of the `config` dir (see CHANGE_CONFIG_DIR_OWNERSHIP for more information). As such, there should be nothing in that dir that you do not wish for Plex to own.

## Useful information
- Start the container: `docker start plex`
- Stop the container: `docker stop plex`
- Shell access to the container while it is running: `docker exec -it plex /bin/bash`
- See the logs given by the startup script in real time: `docker logs -f plex`
- Restart the application and upgrade to the latest version: `docker restart plex`
- Start the container:
- `docker start plex`
- Stop the container:
- `docker stop plex`
- Shell access to the container while it is running:
- `docker exec -it plex /bin/bash`
- See the logs given by the startup script in real time:
- `docker logs -f plex`
- Restart the application:
- `docker restart plex`

## Fedora, CentOS, Red Hat

Expand Down
44 changes: 43 additions & 1 deletion dev/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,45 @@
# Dev Helper Scripts

Unless you are making changes to the Dockerfile themselves, please ignore all the files here. In fact, your environment may be very different and these scripts may not work at all. They are provided only as a reference/starting point so you don't have to start from scratch. Heavy customizations are likely.
Hey homelab enthusiast!

Unless you are enhancing these Dockerfile themselves, please ignore all the files here. In fact, your environment may be very different and these scripts may not work at all. These are just provided only as a reference/starting point so you don't have to start from scratch.

You might just consider extending the images here. i.e.

```
FROM plexinc/pms-docker:latest

RUN echo "Add your modifications here"
```

Otherwise, `dev.sh` will build all of the multi-platform docker images, for each platform it will build one that uses a specific version, and `autoupdate` version that doesn't bake the binary into the image, but rather downloads when container boots. Look inside the script for more info.

`docker-bake.hcl` is a buildx bake file that will build all platforms, using pre-installed binaries and `update` versions. This bake file will push to dockerhub. You can override the destination using the `dockerhub_image` variable in `dev.sh`.


### Examples

#### Prereqs:
- [docker](https://docs.docker.com/engine/install/)
- [buildx](https://github.com/docker/buildx)
- x86 based linux host

```sh
# sets up buildx for multi-arch builds
./dev.sh setup

# bake - build all and push to dockerhub
./dev.sh bake

# build version-specific and autoupdate image for amd64
./dev.sh build amd64

# build everything
./dev.sh buildall

# launches version-specific container
./dev.sh debug amd64

# launches auto-update container
./dev.sh debug amd64 autoupdate
```
7 changes: 0 additions & 7 deletions dev/build.386.sh

This file was deleted.

8 changes: 0 additions & 8 deletions dev/build.amd64.sh

This file was deleted.

8 changes: 0 additions & 8 deletions dev/build.arm32v7.sh

This file was deleted.

8 changes: 0 additions & 8 deletions dev/build.arm64v8.sh

This file was deleted.

7 changes: 0 additions & 7 deletions dev/debug.386.sh

This file was deleted.

7 changes: 0 additions & 7 deletions dev/debug.amd64.sh

This file was deleted.

14 changes: 0 additions & 14 deletions dev/debug.arm32v7.sh

This file was deleted.

14 changes: 0 additions & 14 deletions dev/debug.arm64v8.sh

This file was deleted.

87 changes: 87 additions & 0 deletions dev/dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'

# This is just a helper script to quickly test local Dockerfile builds, please run setup() once
# 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
VERSION_TO_BUILD=${VERSION_TO_BUILD:-"1.32.4.7195-7c8f9d3b6"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure it should default to a particular version as this script is likely not to be updated often as the server advances in version.

DOCKERHUB_IMAGE=${DOCKERHUB_IMAGE:-"plexinc/pms-docker"}

setup() {
# Create a multi-arch buildx builder named PlexBuilder (if it doesn't exist)
if ! docker buildx inspect PlexBuilder 1> /dev/null 2>& 1; then
echo Creating PlexBuilder
# --use will make it automatically use this builder
docker buildx create --name PlexBuilder --platform linux/arm64,linux/arm/v7,linux/386 --use
# this is needed to register the arch-specific images with QEMU to be able to test
# these without native hardware
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
fi
}
build() {
platform=$1
name=$2
docker buildx build \
--progress=plain \
-o type=docker \
--load \
--platform "$platform" \
--build-arg \
"TAG=$VERSION_TO_BUILD" \
-t "$name:$VERSION_TO_BUILD" \
-t "$name:latest" \
-f ../Dockerfile ..
docker buildx build \
--progress=plain \
-o type=docker \
--load \
--platform "$platform" \
--build-arg \
"TAG=autoupdate" \
-t "$name:autoupdate" \
-f ../Dockerfile ..
}

debug() {
platform=$1
name=$2
autoupdate=$3
if [ "$autoupdate" = "autoupdate" ]; then
name=$name:autoupdate
else
name=$name:latest
fi
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" &
sleep 5
docker exec -it debug-plex bash
else
docker run --rm --name debug-plex --platform "$platform" -e DEBUG=true -it "$name" bash
fi
}

cmd=${1:-}
kind=${2:-}
[ "$cmd" = 'setup' ] && setup
[ "$cmd" = 'build' ] && [ "$kind" = '386' ] && build linux/386 pms-386
[ "$cmd" = 'build' ] && [ "$kind" = 'amd64' ] && build linux/amd64 pms-amd64
[ "$cmd" = 'build' ] && [ "$kind" = 'arm32v7' ] && build linux/arm/v7 pms-arm32v7
[ "$cmd" = 'build' ] && [ "$kind" = 'arm64v8' ] && build linux/arm64 pms-arm64v8
[ "$cmd" = 'buildall' ] && \
build linux/386 pms-386 && \
build linux/amd64 pms-amd64 && \
build linux/arm/v7 pms-arm32v7 && \
build linux/arm64 pms-arm64v8

[ "$cmd" = 'bake' ] && TAG=$VERSION_TO_BUILD IMAGE=$DOCKERHUB_IMAGE docker buildx bake

autoupdate=${3:-}
[ "$cmd" = 'debug' ] && [ "$kind" = '386' ] && debug linux/386 pms-386 "$autoupdate"
[ "$cmd" = 'debug' ] && [ "$kind" = 'amd64' ] && debug linux/amd64 pms-amd64 "$autoupdate"
[ "$cmd" = 'debug' ] && [ "$kind" = 'arm32v7' ] && debug linux/arm/v7 pms-arm32v7 "$autoupdate"
[ "$cmd" = 'debug' ] && [ "$kind" = 'arm64v8' ] && debug linux/arm64 pms-arm64v8 "$autoupdate"
40 changes: 40 additions & 0 deletions dev/docker-bake.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# run this file using "docker buildx bake"

variable "TAG" {
# This should be overridden on command line to be the
# specific plex media server binary to download into the image
default = "1.32.4.7195-7c8f9d3b6"
}
variable "IMAGE" {
default = "plexinc/pms-docker"
}

group "default" {
targets = ["plexmediaserver-versioned", "plexmediaserver-autoupdate"]
}

target "plexmediaserver-versioned" {
# This target builds targets that downloald and pre-install the
# the plex media server binary in the container. This image
# has two tags, the version itself, and assuming this is that latest
# also tags it with :latest.
output = ["type=registry"]
context = ".."
platforms = ["linux/386", "linux/amd64", "linux/arm64", "linux/arm/v7"]
tags = ["${IMAGE}:${TAG}", "${IMAGE}:latest"]
args = {
TAG = "${TAG}"
}
}
target "plexmediaserver-autoupdate" {
# This target build a download and pre-install a configuration of the
# container automatically downloads and installs the server at runtime
# and automatically checks for updates once a day.
output = ["type=registry"]
context = ".."
platforms = ["linux/386", "linux/amd64", "linux/arm64", "linux/arm/v7"]
tags = ["${IMAGE}:autoupdate"]
args = {
TAG = "autoupdate"
}
}
1 change: 0 additions & 1 deletion dev/push.all.sh

This file was deleted.

16 changes: 0 additions & 16 deletions dev/setup-build-env.sh

This file was deleted.

Loading