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

feat: Implement kitchen login for docker transport #422

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
43 changes: 43 additions & 0 deletions lib/kitchen/transport/docker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,49 @@ def container
end
@container
end

def login_command
config = container.instance_variable_get(:@config)
login_config = config.dup
login_config[:interactive] = true
login_config[:tty] = true
login_config[:detach] = false
login_config[:username] = nil
login_cmd = build_login_command(login_config)
LoginCommand.new(login_cmd[0], login_cmd[1..-1])
end

def build_login_command(config)
# This function duplicates a lot of CliHelper functionality, but I think I'd need to refactor
# things to override some aspects of Configurable in order to reuse that code.
docker = [config[:binary].dup]
docker << "-H #{config[:socket]}" if config[:socket]
docker << "--tls" if config[:tls]
docker << "--tlsverify" if config[:tls_verify]
docker << "--tlscacert=#{config[:tls_cacert]}" if config[:tls_cacert]
docker << "--tlscert=#{config[:tls_cert]}" if config[:tls_cert]
docker << "--tlskey=#{config[:tls_key]}" if config[:tls_key]
logger.debug("docker_command: #{docker.join(" ")}")

cmd = ["exec"]
cmd << "-d" if config[:detach]
if config[:env_variables]
config[:env_variables].each do |var|
cmd << "-e #{var}"
end
end
cmd << "--privileged" if config[:privileged]
cmd << "-t" if config[:tty]
cmd << "-i" if config[:interactive]
cmd << "-u #{config[:username]}" if config[:username]
cmd << "-w #{config[:working_dir]}" if config[:working_dir]
cmd << "#{config[:container_id]}"
cmd << "/bin/bash"
cmd << "-login"
cmd << "-i"
logger.debug("build_exec_command: #{cmd.join(" ")}")
docker + cmd
end
end
end
end
Expand Down
Loading