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 14 commits
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
73 changes: 57 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,32 +1,54 @@
FROM ubuntu:20.04

ARG S6_OVERLAY_VERSION=v2.2.0.3
ARG S6_OVERLAY_ARCH=amd64
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 DEBIAN_FRONTEND="noninteractive"
ARG INTEL_NEO_VERSION=20.48.18558
ARG INTEL_IGC_VERSION=1.0.5699
ARG INTEL_GMMLIB_VERSION=20.3.2
ENV TERM="xterm" LANG="C.UTF-8" LC_ALL="C.UTF-8"

ENTRYPOINT ["/init"]
FROM arm64v8/ubuntu:22.04 as base-arm64
ARG S6_OVERLAY_VERSION=v3.1.5.0
ARG S6_OVERLAY_ARCH=aarch64
ARG PLEX_BUILD=linux-aarch64

FROM arm32v7/ubuntu:22.04 as base-arm
ARG S6_OVERLAY_VERSION=v3.1.5.0
ARG S6_OVERLAY_ARCH=arm
ARG PLEX_BUILD=linux-armv7hf_neon

FROM i386/ubuntu:18.04 as base-386
Copy link

Choose a reason for hiding this comment

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

I'd call this i386 to not change how this arch is spelled in this context.

Copy link
Author

Choose a reason for hiding this comment

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

Unfortunately, I can't really change this. The way this multi-arch Dockerfile works is that it pulls from various arch-specific ubuntu images and then names them using the pattern base-TARGETARCH where arch comes from the env var TARGETARCH that is automatically set bydocker build[x]. The actual selected image is selected on line 24 below.

Looks like everyone has opinions, and they are not standardized, on what platforms mean what.

In the case of i386/ubuntu, this is meant to be used when TARGETARCH=386

S6-overlays' has its own opinions, and it maps TARGETARCH=386 to i686. See https://github.com/just-containers/s6-overlay#which-architecture-to-use-depending-on-your-targetarch

More details can be found here: https://github.com/BretFisher/multi-platform-docker-build/blob/main/README.md#the-problem-with-downloading-binaries-in-dockerfiles

Copy link
Author

Choose a reason for hiding this comment

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

Technically, the 32bit Ubuntu image is stuck at v18.04, which is way past EOL. Maybe this build should just be removed?

Copy link
Contributor

Choose a reason for hiding this comment

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

18.04 only left support a month ago + a few days but that it still out of support and likely should still be removed.

Copy link

Choose a reason for hiding this comment

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

I think it should stay until the team formally decides to stop supporting it.

ARG S6_OVERLAY_VERSION=v3.1.5.0
ARG S6_OVERLAY_ARCH=i686
ARG PLEX_BUILD=linux-x86

FROM base-${TARGETARCH} AS plex
ARG TARGETARCH
RUN echo Building pms-docker for ${TARGETARCH}

ARG DEBIAN_FRONTEND="noninteractive"
ARG PLEX_DISTRO=debian

RUN \
# Update and get dependencies
apt-get update && \
apt-get install -y \
tzdata \
curl \
xz-utils \
xmlstarlet \
uuid-runtime \
unrar \
cron \
multitail \
&& \
\
# Fetch and extract S6 overlay
curl -J -L -o /tmp/s6-overlay-${S6_OVERLAY_ARCH}.tar.gz https://github.com/just-containers/s6-overlay/releases/download/${S6_OVERLAY_VERSION}/s6-overlay-${S6_OVERLAY_ARCH}.tar.gz && \
tar xzf /tmp/s6-overlay-${S6_OVERLAY_ARCH}.tar.gz -C / --exclude='./bin' && \
tar xzf /tmp/s6-overlay-${S6_OVERLAY_ARCH}.tar.gz -C /usr ./bin && \
curl -L -s \
"https://github.com/just-containers/s6-overlay/releases/download/${S6_OVERLAY_VERSION}/s6-overlay-noarch.tar.xz" | tar Jxpf - -C / \
&& \
curl -L -s \
"https://github.com/just-containers/s6-overlay/releases/download/${S6_OVERLAY_VERSION}/s6-overlay-${S6_OVERLAY_ARCH}.tar.xz" | tar Jxpf - -C / \
&& \
\
# Add user
useradd -U -d /config -s /bin/false plex && \
Expand All @@ -49,16 +71,35 @@ RUN \
EXPOSE 32400/tcp 8324/tcp 32469/tcp 1900/udp 32410/udp 32412/udp 32413/udp 32414/udp
VOLUME /config /transcode

ENV CHANGE_CONFIG_DIR_OWNERSHIP="true" \
HOME="/config"

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 CHANGE_CONFIG_DIR_OWNERSHIP="true" \
HOME="/config" \
# Note, only used for images built with TAG=autoupdate
AUTO_UPDATE_CHANNEL="beta" \
\
TERM="xterm" \
LANG="C.UTF-8" \
LC_ALL="C.UTF-8" \
\
S6_KEEP_ENV=1 \
S6_SERVICES_GRACETIME=10000 \
S6_KILL_GRACETIME=5000 \
S6_CMD_WAIT_FOR_SERVICES_MAXTIME=0 \
S6_BEHAVIOUR_IF_STAGE2_FAILS=2

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"]
61 changes: 0 additions & 61 deletions Dockerfile.arm64

This file was deleted.

61 changes: 0 additions & 61 deletions Dockerfile.armv7

This file was deleted.

60 changes: 0 additions & 60 deletions Dockerfile.i386

This file was deleted.

31 changes: 23 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 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.

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

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

Expand All @@ -158,11 +166,18 @@ 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`
- Monitor all Plex Media Server logs:
- `docker exec -it plex /plex-logs.sh`
- Restart the application:
- `docker restart plex`

## Fedora, CentOS, Red Hat

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

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
```
Loading