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

wf: set DIGDAG_CONFIG_HOME env var #174

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
34 changes: 24 additions & 10 deletions lib/td/command/workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ def workflow(op, capture_output=false, check_prereqs=true)
cmd << '-Dio.digdag.standards.td.client-configurator.enabled=true'
end

# Provide the digdag cli with a directory that can be used to e.g. store local secrets
FileUtils.mkdir_p digdag_config_dir
env['DIGDAG_CONFIG_HOME'] = digdag_config_dir

cmd << '-jar' << digdag_cli_path
unless op.argv.empty?
cmd << '--config' << digdag_config_path
Expand All @@ -53,16 +57,7 @@ def workflow(op, capture_output=false, check_prereqs=true)
$stderr.puts cmd.to_s
end

if capture_output
# TODO: use popen3 instead?
stdout_str, stderr_str, status = Open3.capture3(env, *cmd)
$stdout.write(stdout_str)
$stderr.write(stderr_str)
return status.exitstatus
else
Kernel::system(env, *cmd)
return $?.exitstatus
end
execute(capture_output, env, cmd)
}
end

Expand Down Expand Up @@ -96,6 +91,20 @@ def workflow_version(op)
workflow(version_op, capture_output=true, check_prereqs=false)
end

private
def execute(capture_output, env, cmd)
if capture_output
# TODO: use popen3 instead?
stdout_str, stderr_str, status = Open3.capture3(env, *cmd)
$stdout.write(stdout_str)
$stderr.write(stderr_str)
return status.exitstatus
else
Kernel::system(env, *cmd)
return $?.exitstatus
end
end

private
def system_java_cmd
if td_wf_java.nil? or td_wf_java.empty?
Expand Down Expand Up @@ -139,6 +148,11 @@ def digdag_dir
File.join(home_directory, '.td', 'digdag')
end

private
def digdag_config_dir
File.join(home_directory, '.td', 'digdag', 'config')
end

private
def digdag_tmp_dir
File.join(home_directory, '.td', 'digdag', 'tmp')
Expand Down
8 changes: 8 additions & 0 deletions spec/td/command/workflow_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,14 @@ def with_env(name, var)
}
end

it 'provides a config directory' do
allow(TreasureData::Config).to receive(:cl_apikey) { true }
expect(command).to receive(:execute).with(true, hash_including('DIGDAG_CONFIG_HOME'), anything()) { |_, env, _|
expect(File.directory?(env['DIGDAG_CONFIG_HOME'])).to be true
}
command.workflow(init_option, capture_output=true, check_prereqs=false)
end

it 'complains if there is no apikey' do
allow(TreasureData::Config).to receive(:apikey) { nil}
expect{command.workflow(version_option)}.to raise_error(TreasureData::ConfigError)
Expand Down