diff --git a/Dockerfile b/Dockerfile index 01fe443c..6430e3e1 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 @@ -32,13 +32,24 @@ FROM alpine:latest # hadolint ignore=DL3018 RUN apk --no-cache add tzdata \ ca-certificates \ - && update-ca-certificates + su-exec \ + && 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", "/m3u-proxy/m3u-proxy"] 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..26c9cd78 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +# 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()