diff --git a/README.md b/README.md index 6a0434c..5041190 100644 --- a/README.md +++ b/README.md @@ -222,6 +222,27 @@ dip run bash -c pwd returned is `/app/sub-project-dir`. +#### $DIP_CURRENT_USER + +Exposes the current user ID (UID). It is useful when you need to run a container with the same user as the host machine. For example: + +```yml +# dip.yml (1) +environment: + UID: ${DIP_CURRENT_USER} +``` + +```yml +# docker-compose.yml (2) +services: + app: + image: ruby + user: ${UID:-1000} +``` + +The container will run using the same user ID as your host machine. + + ### dip run Run commands defined within the `interaction` section of dip.yml diff --git a/lib/dip/environment.rb b/lib/dip/environment.rb index c7031c1..e642a9e 100644 --- a/lib/dip/environment.rb +++ b/lib/dip/environment.rb @@ -5,7 +5,7 @@ module Dip class Environment VAR_REGEX = /\$\{?(?[a-zA-Z_][a-zA-Z0-9_]*)\}?/.freeze - SPECIAL_VARS = %i[os work_dir_rel_path].freeze + SPECIAL_VARS = %i[os work_dir_rel_path current_user].freeze attr_reader :vars @@ -63,5 +63,9 @@ def find_os def find_work_dir_rel_path @find_work_dir_rel_path ||= Pathname.getwd.relative_path_from(Dip.config.file_path.parent).to_s end + + def find_current_user + @find_current_user ||= Process.uid + end end end