Skip to content
Draft
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
24 changes: 22 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 6 additions & 4 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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}

#
Expand Down