diff options
| author | JP Dillingham <jp@dillingham.me> | 2026-04-24 09:44:44 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2026-04-24 09:44:44 -0500 |
| commit | 64fb4c12a013ed1b50ddcf57fb4bd16decb928f0 (patch) | |
| tree | 3d647cf4f912fa6437e0d0030e99f577e6f0a2c7 /Dockerfile | |
| parent | 19fba8293b472939d74ed23232577cbfdf523586 (diff) | |
| parent | fc722e4a78aa5369fcd5ca0d8e88bd98d874a1d8 (diff) | |
| download | slskd-64fb4c12a013ed1b50ddcf57fb4bd16decb928f0.tar.gz | |
Merge remote-tracking branch 'origin/master' into retries
Diffstat (limited to 'Dockerfile')
| -rw-r--r-- | Dockerfile | 109 |
1 files changed, 96 insertions, 13 deletions
@@ -1,6 +1,9 @@ +# syntax=docker/dockerfile:1 +# ^ enable heredoc for BuildKit + # build static web content # note: pin this to amd64 to speed it up, it is prohibitively slow under QEMU -FROM --platform=$BUILDPLATFORM node:18-alpine3.18 AS web +FROM --platform=$BUILDPLATFORM node:22-alpine AS web ARG VERSION=0.0.1.65534-local WORKDIR /slskd @@ -13,7 +16,7 @@ RUN sh ./bin/build --web-only --version $VERSION # build, test, and publish application binaries # note: this needs to be pinned to an amd64 image in order to publish armv7 binaries # https://github.com/dotnet/dotnet-docker/issues/1537#issuecomment-615269150 -FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-bookworm-slim AS publish +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:10.0-noble AS publish ARG TARGETPLATFORM ARG VERSION=0.0.1.65534-local @@ -32,7 +35,7 @@ RUN bash ./bin/build --dotnet-only --version $VERSION RUN bash ./bin/publish --no-prebuild --platform $TARGETPLATFORM --version $VERSION --output ../../dist/${TARGETPLATFORM} # application -FROM mcr.microsoft.com/dotnet/runtime-deps:8.0-bookworm-slim AS slskd +FROM mcr.microsoft.com/dotnet/runtime-deps:10.0-noble AS slskd ARG TARGETPLATFORM ARG TAG=0.0.1 ARG VERSION=0.0.1.65534-local @@ -43,6 +46,7 @@ RUN apt-get update && apt-get install --no-install-recommends -y \ jq \ wget \ tini \ + gosu \ && \ rm -rf \ /tmp/* \ @@ -50,8 +54,11 @@ RUN apt-get update && apt-get install --no-install-recommends -y \ /var/cache/apt/* \ /var/tmp/* -RUN bash -c 'mkdir -p /app/{incomplete,downloads} \ - && chmod -R 777 /app \ +RUN groupadd -o -g 1000 slskd && \ + useradd -o -u 1000 -g slskd slskd + +RUN bash -c 'mkdir -p /app \ + && chown -R slskd:slskd /app \ && mkdir -p /.net \ && chmod 777 /.net' @@ -64,7 +71,7 @@ ENV SHELL=/usr/bin/bash \ DOTNET_BUNDLE_EXTRACT_BASE_DIR=/.net \ DOTNET_gcServer=0 \ DOTNET_gcConcurrent=1 \ - DOTNET_GCHeapHardLimit=0x80000000 \ + DOTNET_GCHeapHardLimit=0x80000000 \ DOTNET_GCConserveMemory=9 \ SLSKD_UMASK=0022 \ SLSKD_HTTP_PORT=5030 \ @@ -73,13 +80,13 @@ ENV SHELL=/usr/bin/bash \ SLSKD_APP_DIR=/app \ SLSKD_DOCKER_TAG=$TAG \ SLSKD_DOCKER_VERSION=$VERSION \ - SLSKD_DOCKER_REVISON=$REVISION \ + SLSKD_DOCKER_REVISION=$REVISION \ SLSKD_DOCKER_BUILD_DATE=$BUILD_DATE LABEL org.opencontainers.image.title=slskd \ org.opencontainers.image.description="A modern client-server application for the Soulseek file sharing network" \ - org.opencontainers.image.authors="slskd Team" \ - org.opencontainers.image.vendor="slskd Team" \ + org.opencontainers.image.authors="JP Dillingham, slskd Contributors" \ + org.opencontainers.image.vendor="slskd Project" \ org.opencontainers.image.licenses=AGPL-3.0 \ org.opencontainers.image.url=https://slskd.org \ org.opencontainers.image.source=https://github.com/slskd/slskd \ @@ -91,7 +98,83 @@ LABEL org.opencontainers.image.title=slskd \ WORKDIR /slskd COPY --from=publish /slskd/dist/${TARGETPLATFORM} . -RUN echo "umask \$SLSKD_UMASK && ./slskd" > start.sh \ - && chmod +x start.sh - -ENTRYPOINT ["/usr/bin/tini", "--", "./start.sh"] +# supports three modes: +# 1. --user / user: (modern Docker) — container starts as non-root, skips all usermod/chown, execs the app directly. +# 2. PUID/PGID (legacy linuxserver style) — container starts as root, mutates user, chowns /app if needed, drops privileges via gosu. +# 3. neither --user nor at least one of PUID/PGID supplied - container and app run as root +COPY <<'SCRIPT' /entrypoint.sh +#!/bin/bash +set -e + +# --user mode; user has provided a user via the command line or docker compose file +#--------------------------------------------------------------------------------------- +if [ "$(id -u)" -ne 0 ]; then + # if the user has also supplied PUID or PGID, let them know they need to use one or the other + if [ -n "${PUID}" ] || [ -n "${PGID}" ]; then + echo "ERROR: PUID/PGID are set but the container is running as a non-root user (using --user or user:)." + echo "Use one or the other, not both. Either remove --user and set PUID/PGID, or remove PUID/PGID and use --user." + exit 1 + fi + + # exit if /app is not writable; we can't fix this because we lack permissions + if [ ! -r /app ] || [ ! -w /app ]; then + echo "ERROR: /app is not readable and/or writable by the current user ($(id -u):$(id -g)); currently owned by owned by $(stat -c '%U:%G (%u:%g)' /app)." + echo "To fix: chown -R $(id -u):$(id -g) /path/to/your/mounted/app/directory" + exit 1 + fi + + # should be good to go; set umask and launch + umask "$SLSKD_UMASK" + exec "$@" +fi + +# no --user supplied, neither PUID nor PGID supplied, run as root (same behavior as < 0.25.0) +#--------------------------------------------------------------------------------------- +if [ -z "${PUID}" ] && [ -z "${PGID}" ]; then + umask "$SLSKD_UMASK" + exec "$@" +fi + +# PUID/PGID mode; user has provided explicit user and group IDs to use +#--------------------------------------------------------------------------------------- +PUID="${PUID:-1000}" +PGID="${PGID:-1000}" + +if ! [[ "${PUID}" =~ ^[0-9]+$ ]]; then + echo "ERROR: PUID must be a non-negative integer, got '${PUID}'." + exit 1 +fi + +if ! [[ "${PGID}" =~ ^[0-9]+$ ]]; then + echo "ERROR: PGID must be a non-negative integer, got '${PGID}'." + exit 1 +fi + +# update group if needed +if [ "$(getent group slskd | cut -d: -f3)" != "$PGID" ]; then + groupmod -o -g "$PGID" slskd +fi + +# update user if needed +if [ "$(id -u slskd)" != "$PUID" ] || [ "$(id -g slskd)" != "$PGID" ]; then + usermod -o -u "$PUID" -g "$PGID" slskd +fi + +# change owner of the the /app directory if it isn't correct +# we're not checking anything other than the root, and we're not recursively +# applying the changes, which might be dangerous/unwanted and/or take forever +if [ "$(stat -c '%u:%g' /app)" != "${PUID}:${PGID}" ]; then + chown "${PUID}:${PGID}" /app +fi + +# set umask and launch +umask "$SLSKD_UMASK" +exec gosu "${PUID}:${PGID}" "$@" + +SCRIPT +# EOF + +RUN chmod +x /entrypoint.sh + +ENTRYPOINT ["/usr/bin/tini", "--", "/entrypoint.sh"] +CMD ["./slskd"] |
