From 30055bcb104277b3fcc013b1eb230101a734ce4b Mon Sep 17 00:00:00 2001 From: Carbrex <95964955+Carbrex@users.noreply.github.com> Date: Fri, 21 Jun 2024 17:13:15 +0530 Subject: [PATCH] Dont change user for docker desktop users --- docker-compose.yml | 9 +++++++++ docker/ui.Dockerfile | 8 ++++++++ lila-docker | 18 ++++++++++++++---- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 0de20174..90278704 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -118,6 +118,9 @@ services: chessground: build: context: docker + args: + USER_ID: ${USER_ID} + GROUP_ID: ${GROUP_ID} dockerfile: ui.Dockerfile entrypoint: ["/bin/sh", "-c", "pnpm install && pnpm run compile && pnpx http-server -p 8080"] restart: unless-stopped @@ -133,6 +136,9 @@ services: pgn_viewer: build: context: docker + args: + USER_ID: ${USER_ID} + GROUP_ID: ${GROUP_ID} dockerfile: ui.Dockerfile entrypoint: ["/bin/sh", "-c", "pnpm install && pnpm run demo"] restart: unless-stopped @@ -221,6 +227,9 @@ services: ui: build: context: docker + args: + USER_ID: ${USER_ID} + GROUP_ID: ${GROUP_ID} dockerfile: ui.Dockerfile restart: unless-stopped user: ${USER_ID}:${GROUP_ID} diff --git a/docker/ui.Dockerfile b/docker/ui.Dockerfile index d5824d51..093d49fb 100644 --- a/docker/ui.Dockerfile +++ b/docker/ui.Dockerfile @@ -11,4 +11,12 @@ RUN corepack enable RUN pnpm config set store-dir /.pnpm-store +ARG USER_ID +ARG GROUP_ID + +RUN if [ "$USER_ID" != "1000" ] && [ "$USER_ID" != "0" ]; then \ + adduser -D -u $USER_ID -G $(id -gn node) -h $(eval echo ~node) newuser; \ + chown -R $USER_ID:$(id -gn node) $(eval echo ~node); \ + fi + WORKDIR /app diff --git a/lila-docker b/lila-docker index 4ff7ce77..62fd320c 100755 --- a/lila-docker +++ b/lila-docker @@ -1,8 +1,7 @@ #!/bin/bash -e run_setup() { - echo "USER_ID=$(id -u)" > .env - echo "GROUP_ID=$(id -g)" >> .env + write_user_id_to_env rust_cmd setup @@ -52,8 +51,7 @@ all_profiles() { } build_all_profiles() { - echo "USER_ID=$(id -u)" > .env - echo "GROUP_ID=$(id -g)" >> .env + write_user_id_to_env COMPOSE_PROFILES=$(all_profiles) docker compose pull COMPOSE_PROFILES=$(all_profiles) docker compose build @@ -150,6 +148,18 @@ rust_cmd() { load_config_to_env } +write_user_id_to_env() { + if docker info 2>/dev/null | grep -q "Operating System: Docker Desktop"; then + echo "Running on Docker Desktop" + echo "USER_ID=0" > .env + echo "GROUP_ID=0" >> .env + else + echo "Running on Docker Engine" + echo "USER_ID=$(id -u)" > .env + echo "GROUP_ID=$(id -g)" >> .env + fi +} + load_config_to_env() { export $(cat settings.env | xargs) }