Skip to content

Commit

Permalink
Merge pull request #157 from sonroyaalmerol/docker-entrypoint
Browse files Browse the repository at this point in the history
Add PUID/PGID setting on container runtime
  • Loading branch information
sonroyaalmerol authored Sep 14, 2024
2 parents de66425 + 9e59ba2 commit 6b0ff4d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 7 deletions.
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

0 comments on commit 6b0ff4d

Please sign in to comment.