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

Add PUID/PGID setting on container runtime #157

Merged
merged 5 commits into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
23 changes: 17 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"]
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ services:
ports:
- "8080:8080"
environment:
- PUID=1000
- PGID=1000
- TZ=America/Toronto
- REDIS_ADDR=redis:6379
- SYNC_ON_BOOT=true
Expand Down Expand Up @@ -92,6 +94,8 @@ Access the generated M3U playlist at `http://<server ip>: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 |
Expand Down
18 changes: 18 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"

2 changes: 1 addition & 1 deletion m3u/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down