From 22a6ba51d44084d0ba4ec4b77544f58adba6f0cc Mon Sep 17 00:00:00 2001 From: Frederik Beimgraben Date: Fri, 31 Oct 2025 00:46:26 +0100 Subject: [PATCH] feat: Correct UID in container (same as folder) --- .env.example | 15 +++++++++++++++ .gitignore | 1 + Makefile | 4 ++-- docker-compose.yml | 39 ++++++++++++++++++++++++++++++++++++--- 4 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 .env.example diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..5bf4b90 --- /dev/null +++ b/.env.example @@ -0,0 +1,15 @@ +# Docker Environment Configuration Example +# ========================================= +# Copy this file to .env and adjust values as needed + +# User ID and Group ID for the Docker container user +# These should match your local user to avoid permission issues +# You can get your current values by running: +# echo "HOST_UID=$(id -u)" +# echo "HOST_GID=$(id -g)" +HOST_UID=1000 +HOST_GID=1000 + +# Note: When using 'make docker-build', these values are automatically +# detected and passed to docker-compose, so you don't need a .env file. +# This file is only needed if you run docker-compose directly. diff --git a/.gitignore b/.gitignore index f441e37..28725df 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,4 @@ Output/ # Ignore chapter backups and Temporary PDF files from Inkscape .chapter-backups/ svg-inkscape/ +.config/ diff --git a/Makefile b/Makefile index c95d228..0f78cd6 100644 --- a/Makefile +++ b/Makefile @@ -135,8 +135,8 @@ check-docker: .PHONY: docker-build docker-build: check-docker @echo -e "$(BLUE)=== Building LaTeX Document with Docker ===$(NC)" - @echo -e "$(YELLOW)→ Starting Docker container...$(NC)" - @$(DOCKER_COMPOSE_CMD) up --build || { \ + @echo -e "$(YELLOW)→ Starting Docker container with UID=$$(id -u) GID=$$(id -g)...$(NC)" + @HOST_UID=$$(id -u) HOST_GID=$$(id -g) $(DOCKER_COMPOSE_CMD) up --build || { \ echo -e "$(RED)✗ Docker build failed$(NC)"; \ echo -e "$(YELLOW) Try 'make docker-clean' and rebuild$(NC)"; \ exit 1; \ diff --git a/docker-compose.yml b/docker-compose.yml index bf024ba..b6d845e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -21,11 +21,21 @@ services: build: # Build context is the current directory context: . + # Pass the current directory's UID and GID as build arguments + # These are automatically set by the Makefile, or can be manually provided: + # HOST_UID=$(id -u) HOST_GID=$(id -g) docker-compose up --build + args: + HOST_UID: ${HOST_UID:-1000} + HOST_GID: ${HOST_GID:-1000} # Inline Dockerfile definition for additional packages dockerfile_inline: | # Start from the full TeXLive image (includes XeLaTeX, Biber, etc.) FROM texlive/texlive:latest + # Accept build arguments for the host directory's UID and GID + ARG HOST_UID=1000 + ARG HOST_GID=1000 + # Update package lists to ensure we get the latest versions RUN apt update -y @@ -33,6 +43,32 @@ services: # Required for processing SVG graphics in the document RUN apt install inkscape -y + # Create a group with the host directory's GID + # The '|| true' ensures the command succeeds even if the group already exists + RUN groupadd -g ${HOST_GID} texuser 2>/dev/null || true + + # Create a user with the host directory's UID and GID + # - Same UID/GID as the host directory to avoid permission issues + # - Home directory at /home/texuser + # - Default shell /bin/bash + # If UID is taken in container, rename the user with the ID ${HOST_UID} to texuser + RUN useradd -m -u ${HOST_UID} -g ${HOST_GID} -s /bin/bash texuser || \ + usermod --login texuser "$(id -nu ${HOST_UID})" + + # Make /data and chown it to the user + RUN mkdir /data && \ + chown -R ${HOST_UID}:${HOST_GID} /data + + # Set /data as the user home + RUN usermod -d /data texuser + + # Set /data as the working directory + WORKDIR /data + + # Set the default user for running commands + # All subsequent commands will run as this user + USER texuser + # Volume mappings volumes: # Mount the entire project directory to /data in the container @@ -40,9 +76,6 @@ services: - ./:/data # Working directory configuration - # Previous project-specific path (kept for reference): - # working_dir: /data/Projektbeschreibung-MKI-METI-Projekt - # Current: Set to /data root for general use working_dir: /data # Default command when container starts