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

Fix cannot find a UUID when connect using train with local transport inside docker container #747

Merged
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
23 changes: 23 additions & 0 deletions lib/train/platforms/detect/helpers/os_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def unix_uuid
(unix_uuid_from_chef ||
unix_uuid_from_machine_file ||
uuid_from_command ||
uuid_from_containerized_system ||
raise(Train::TransportError, "Cannot find a UUID for your node."))
end

Expand Down Expand Up @@ -155,6 +156,28 @@ def uuid_from_command
uuid_from_string(result.stdout.chomp) if result.exit_status == 0 && !result.stdout.empty?
end

# This will run if anyone is running Train with local transport inside docker container
# This is fallback plan, if other ways of getting uuid fails for local transport running inside docker container
# TODO: This needs to be improved to support other container runtime
def uuid_from_containerized_system
uuid = nil

if File.exist?("/proc/self/cgroup")
cmd = @backend.run_command("head -1 /proc/self/cgroup|cut -d/ -f3")
unless cmd.stdout.strip.empty?
uuid = cmd.stdout.strip
end
end

if uuid.nil? && File.exist?("/proc/self/mountinfo")
cmd = @backend.run_command("cat /proc/self/mountinfo | grep -i /docker/containers/ | head -n 1 | awk '{print $4}' | awk NF=NF FS=/ | awk '{print $3}'")
unless cmd.stdout.strip.empty?
uuid = cmd.stdout.strip
end
end
uuid
end

# This hashes the passed string into SHA1.
# Then it downgrades the 160bit SHA1 to a 128bit
# then we format it as a valid UUIDv5.
Expand Down