diff --git a/Makefile b/Makefile index 731b6a7..c3226eb 100644 --- a/Makefile +++ b/Makefile @@ -8,10 +8,30 @@ endif include docker/.env -# Current user ID and group ID except MacOS where it conflicts with Docker abilities -ifeq ($(shell uname), Darwin) +# Current user ID and group ID with platform-specific handling +# Detect OS +UNAME_S := $(shell uname -s 2>/dev/null || echo Unknown) +IS_WSL := $(shell grep -qi microsoft /proc/version 2>/dev/null && echo 1 || echo 0) + +# MacOS: Use fixed UIDs to avoid conflicts with existing groups +ifeq ($(UNAME_S),Darwin) + export UID=1000 + export GID=1000 +# WSL (Windows Subsystem for Linux): Use fixed UIDs +else ifeq ($(IS_WSL),1) + export UID=1000 + export GID=1000 +# Windows (Git Bash/MSYS/MinGW/Cygwin): Use fixed UIDs +else ifneq (,$(findstring MINGW,$(UNAME_S))) + export UID=1000 + export GID=1000 +else ifneq (,$(findstring MSYS,$(UNAME_S))) + export UID=1000 + export GID=1000 +else ifneq (,$(findstring CYGWIN,$(UNAME_S))) export UID=1000 export GID=1000 +# Linux (native): Use current user's IDs else export UID=$(shell id -u) export GID=$(shell id -g) diff --git a/docker/Dockerfile b/docker/Dockerfile index 67445c3..f2c2bc8 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -38,12 +38,14 @@ COPY --from=composer /composer /usr/bin/composer # Based on https://frankenphp.dev/docs/docker/#running-as-a-non-root-user RUN \ - groupadd --gid ${GROUP_ID} ${GROUP_NAME}; \ - useradd --gid ${GROUP_ID} --uid ${USER_ID} ${GROUP_NAME}; \ + # Create group if it doesn't exist (handles Mac GID 20 conflict) \ + getent group ${GROUP_ID} || groupadd --gid ${GROUP_ID} ${GROUP_NAME}; \ + # Create user \ + useradd --gid ${GROUP_ID} --uid ${USER_ID} ${USER_NAME}; \ # Add additional capability to bind to port 80 and 443 \ setcap CAP_NET_BIND_SERVICE=+eip /usr/local/bin/frankenphp; \ - # Give write access to /data/caddy and /config/caddy \ - chown -R ${USER_NAME}:${GROUP_NAME} /data/caddy && chown -R ${USER_NAME}:${GROUP_NAME} /config/caddy + # Give write access to /data/caddy and /config/caddy (using GID for cross-platform compatibility) \ + chown -R ${USER_NAME}:${GROUP_ID} /data/caddy && chown -R ${USER_NAME}:${GROUP_ID} /config/caddy USER ${USER_NAME} #