From db0232793c437d907eb129dc905a173377e922c3 Mon Sep 17 00:00:00 2001 From: Son Roy Almerol Date: Sat, 14 Sep 2024 15:11:11 -0400 Subject: [PATCH 1/4] add PUID/PGID with entrypoint --- Dockerfile | 20 +++++++++++++++----- README.md | 4 ++++ entrypoint.sh | 18 ++++++++++++++++++ m3u/generate.go | 2 +- 4 files changed, 38 insertions(+), 6 deletions(-) create mode 100644 entrypoint.sh diff --git a/Dockerfile b/Dockerfile index 01fe443c..a403cfc6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,7 +22,7 @@ RUN \ redis-server --daemonize yes && \ go test ./...; \ fi && \ - go build -ldflags='-s -w' -o main . + go build -ldflags='-s -w' -o m3u-proxy . # End from the latest alpine image # hadolint ignore=DL3007 @@ -35,10 +35,20 @@ RUN apk --no-cache add tzdata \ && update-ca-certificates # set the current workdir -WORKDIR /app +WORKDIR /m3u-proxy # copy in our compiled GO app -COPY --from=build /app/main /app/ +COPY --from=build /app/m3u-proxy /m3u-proxy/ + +# Copy the entrypoint script +COPY entrypoint.sh /m3u-proxy/entrypoint.sh + +# Make the entrypoint script executable +RUN chmod +x /m3u-proxy/entrypoint.sh + +# Set PUID and PGID as environment variables +ENV PUID=1000 +ENV PGID=1000 -# the containers entrypoint -ENTRYPOINT [ "/app/main" ] +# The container entrypoint +ENTRYPOINT ["/m3u-proxy/entrypoint.sh"] diff --git a/README.md b/README.md index 6b15ba39..e2ac5d00 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,8 @@ services: ports: - "8080:8080" environment: + - PUID=1000 + - PGID=1000 - TZ=America/Toronto - REDIS_ADDR=redis:6379 - SYNC_ON_BOOT=true @@ -92,6 +94,8 @@ Access the generated M3U playlist at `http://:8080/playlist.m3u`. | ENV VAR | Description | Default Value | Possible Values | |-----------------------------|----------------------------------------------------------|---------------|------------------------------------------------| +| PUID | Set UID of user running the container. | 1000 | Any valid UID | +| PGID | Set GID of user running the container. | 1000 | Any valid GID | | M3U_URL_1, M3U_URL_2, M3U_URL_X | Set M3U URLs as environment variables. | N/A | Any valid M3U URLs | | M3U_MAX_CONCURRENCY_1, M3U_MAX_CONCURRENCY_2, M3U_MAX_CONCURRENCY_X | Set max concurrency. | 1 | Any integer | | MAX_RETRIES | Set max number of retries (loop) across all M3Us while streaming. 0 to never stop retrying (beware of throttling from provider). | 5 | Any integer greater than or equal 0 | diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 00000000..ad59dfc4 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# Add a group with the specified PGID if it doesn't already exist +if ! getent group appgroup > /dev/null 2>&1; then + addgroup -g "${PGID}" appgroup +fi + +# Add a user with the specified PUID if it doesn't already exist +if ! id -u appuser > /dev/null 2>&1; then + adduser -D -u "${PUID}" -G appgroup appuser +fi + +# Change ownership of the app directory +chown -R appuser:appgroup /m3u-proxy + +# Switch to the new user and execute the main application +exec su-exec appuser "$@" + diff --git a/m3u/generate.go b/m3u/generate.go index f19efa0a..d008ebb9 100644 --- a/m3u/generate.go +++ b/m3u/generate.go @@ -20,7 +20,7 @@ type Cache struct { var M3uCache = &Cache{} -const cacheFilePath = "/cache.m3u" +const cacheFilePath = "/m3u-proxy/cache.m3u" func InitCache(db *database.Instance) { debug := isDebugMode() From 1386781258bd1868f38769882b872b8b79f17ea5 Mon Sep 17 00:00:00 2001 From: Son Roy Almerol Date: Sat, 14 Sep 2024 15:14:51 -0400 Subject: [PATCH 2/4] add su-exec --- Dockerfile | 3 ++- entrypoint.sh | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index a403cfc6..c873f321 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,7 +32,8 @@ FROM alpine:latest # hadolint ignore=DL3018 RUN apk --no-cache add tzdata \ ca-certificates \ - && update-ca-certificates + && update-ca-certificates \ + && su-exec # set the current workdir WORKDIR /m3u-proxy diff --git a/entrypoint.sh b/entrypoint.sh index ad59dfc4..26c9cd78 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh # Add a group with the specified PGID if it doesn't already exist if ! getent group appgroup > /dev/null 2>&1; then From 342ec5f17a2c964e584c6e935529ab8cda45dd95 Mon Sep 17 00:00:00 2001 From: Son Roy Almerol Date: Sat, 14 Sep 2024 15:17:51 -0400 Subject: [PATCH 3/4] fix su-exec apk add --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index c873f321..9346ecd6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,8 +32,8 @@ FROM alpine:latest # hadolint ignore=DL3018 RUN apk --no-cache add tzdata \ ca-certificates \ + su-exec \ && update-ca-certificates \ - && su-exec # set the current workdir WORKDIR /m3u-proxy From 9e59ba2da0c1b58f463d0d962741ee08173ea665 Mon Sep 17 00:00:00 2001 From: Son Roy Almerol Date: Sat, 14 Sep 2024 15:26:10 -0400 Subject: [PATCH 4/4] add binary to entrypoint --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 9346ecd6..6430e3e1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -52,4 +52,4 @@ ENV PUID=1000 ENV PGID=1000 # The container entrypoint -ENTRYPOINT ["/m3u-proxy/entrypoint.sh"] +ENTRYPOINT ["/m3u-proxy/entrypoint.sh", "/m3u-proxy/m3u-proxy"]