brew: improve Docker detection.

Needed for Ubuntu 22.04.
This commit is contained in:
Mike McQuaid 2022-09-06 16:32:35 +01:00
parent 0334658633
commit e58d7d3456
No known key found for this signature in database
GPG Key ID: 3338A31AFDB1D829
2 changed files with 4 additions and 2 deletions

View File

@ -120,8 +120,9 @@ begin
# Unset HOMEBREW_HELP to avoid confusing the tap # Unset HOMEBREW_HELP to avoid confusing the tap
with_env HOMEBREW_HELP: nil do with_env HOMEBREW_HELP: nil do
tap_commands = [] tap_commands = []
cgroup = Utils.popen_read("cat", "/proc/1/cgroup") if File.exist?("/.dockerenv") ||
if %w[azpl_job actions_job docker garden kubepods].none? { |container| cgroup.include?(container) } ((cgroup = Utils.popen_read("cat", "/proc/1/cgroup").presence) &&
%w[azpl_job actions_job docker garden kubepods].none? { |type| cgroup.include?(type) })
brew_uid = HOMEBREW_BREW_FILE.stat.uid brew_uid = HOMEBREW_BREW_FILE.stat.uid
tap_commands += %W[/usr/bin/sudo -u ##{brew_uid}] if Process.uid.zero? && !brew_uid.zero? tap_commands += %W[/usr/bin/sudo -u ##{brew_uid}] if Process.uid.zero? && !brew_uid.zero?
end end

View File

@ -197,6 +197,7 @@ check-run-command-as-root() {
[[ "$(id -u)" == 0 ]] || return [[ "$(id -u)" == 0 ]] || return
# Allow Azure Pipelines/GitHub Actions/Docker/Concourse/Kubernetes to do everything as root (as it's normal there) # Allow Azure Pipelines/GitHub Actions/Docker/Concourse/Kubernetes to do everything as root (as it's normal there)
[[ -f /.dockerenv ]] && return
[[ -f /proc/1/cgroup ]] && grep -E "azpl_job|actions_job|docker|garden|kubepods" -q /proc/1/cgroup && return [[ -f /proc/1/cgroup ]] && grep -E "azpl_job|actions_job|docker|garden|kubepods" -q /proc/1/cgroup && return
# Homebrew Services may need `sudo` for system-wide daemons. # Homebrew Services may need `sudo` for system-wide daemons.