Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DIP_CURRENT_USER added #168

Merged
merged 4 commits into from
Feb 28, 2024
Merged
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
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion lib/dip/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
module Dip
class Environment
VAR_REGEX = /\$\{?(?<var_name>[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

Expand Down Expand Up @@ -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
Loading