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 8 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
63 changes: 50 additions & 13 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 \
&& \
\
# 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,31 @@ 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 AUTOUPDATE=false
ARG TAG=beta
ARG URL=

ENV TAG=${TAG} \
CHANGE_CONFIG_DIR_OWNERSHIP="true" \
HOME="/config" \
TZ="UTC" \
midzelis marked this conversation as resolved.
Show resolved Hide resolved
\
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

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

ENTRYPOINT ["/init"]
midzelis marked this conversation as resolved.
Show resolved Hide resolved
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.

3 changes: 3 additions & 0 deletions dev/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 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.
7 changes: 7 additions & 0 deletions dev/build.386.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'

# This is just a helper script to quickly test local Dockerfile builds, please run setup-build-env.sh once

docker buildx build --progress=plain -o type=docker,name=pms-386 --load --platform linux/386 --build-arg AUTOUPDATE=TRUE -f ../Dockerfile ..
8 changes: 8 additions & 0 deletions dev/build.amd64.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'

# This is just a helper script to quickly test local Dockerfile builds, please run setup-build-env.sh once

# https://github.com/tianon/docker-brew-ubuntu-core/issues/183 explains why need to use --security-opt seccomp:unconfined
docker buildx build --progress=plain --security-opt seccomp:unconfined -o type=docker,name=pms-amd64 --platform linux/amd64 --build-arg AUTOUPDATE=TRUE -f ../Dockerfile ..
8 changes: 8 additions & 0 deletions dev/build.arm32v7.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'

# This is just a helper script to quickly test local Dockerfile builds, please run setup-build-env.sh once

# https://github.com/tianon/docker-brew-ubuntu-core/issues/183 explains why need to use --security-opt seccomp:unconfined
docker buildx build --progress=plain --security-opt seccomp:unconfined -o type=docker,name=pms-armv7 --load --platform linux/arm/v7 --build-arg AUTOUPDATE=TRUE -f ../Dockerfile ..
8 changes: 8 additions & 0 deletions dev/build.arm64v8.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'

# This is just a helper script to quickly test local Dockerfile builds, please run setup-build-env.sh once

# https://github.com/tianon/docker-brew-ubuntu-core/issues/183
docker buildx build --progress=plain --security-opt seccomp:unconfined -o type=docker,name=pms-arm64 --load --platform linux/arm64 --build-arg AUTOUPDATE=TRUE -f ../Dockerfile ..
7 changes: 7 additions & 0 deletions dev/debug.386.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'

# This is just a helper script to quickly test local Dockerfile builds, please run setup-build-env.sh once

docker run --rm --name pms-386 --platform linux/386 -e DEBUG=true -it pms-386:latest bash
midzelis marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 7 additions & 0 deletions dev/debug.amd64.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'

# This is just a helper script to quickly test local Dockerfile builds, please run setup-build-env.sh once

docker run --rm --name pms-amd64 -e DEBUG=true -it pms-amd64:latest bash
midzelis marked this conversation as resolved.
Show resolved Hide resolved
14 changes: 14 additions & 0 deletions dev/debug.arm32v7.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'

# This is just a helper script to quickly test local Dockerfile builds, please run setup-build-env.sh once

# Note - S6 overlay does NOT like it when you give it a tty under QEMU - do not run
# the container with "-it" rather, run it in background (so we get log output) then
# exec a bash process to enter the container.

trap "trap - SIGTERM && docker stop pms-armv7" SIGINT SIGTERM EXIT
docker run --rm --name pms-armv7 --platform linux/arm/v7 -e DEBUG=true pms-armv7:latest &
sleep 5
docker exec -it pms-armv7 bash
14 changes: 14 additions & 0 deletions dev/debug.arm64v8.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'

# This is just a helper script to quickly test local Dockerfile builds, please run setup-build-env.sh once

# Note - S6 overlay does NOT like it when you give it a tty under QEMU - do not run
# the container with "-it" rather, run it in background (so we get log output) then
# exec a bash process to enter the container.

trap "trap - SIGTERM && docker stop pms-arm64" SIGINT SIGTERM EXIT
docker run --rm --name pms-arm64 --platform linux/arm64 -e DEBUG=true pms-arm64:latest &
sleep 5
docker exec -it pms-arm64 bash
1 change: 1 addition & 0 deletions dev/push.all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker buildx build --progress=plain --push --security-opt seccomp:unconfined --platform linux/amd64,linux/386,linux/arm/v7,linux/arm64 --build-arg AUTOUPDATE=TRUE -f ../Dockerfile --tag INSERT_TAG_HERE:autoupdate ..
16 changes: 16 additions & 0 deletions dev/setup-build-env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'

# This is a one time setup script to setup the build env needed by the build and debug scripts.
# Assumes this is running on Linux (any distro) using (intel/amd).

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