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

Support Hako definitions written in Jsonnet #59

Merged
merged 2 commits into from
Dec 22, 2017
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
32 changes: 25 additions & 7 deletions lib/barbeque/executor/hako.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,20 @@ class HakoCommandError < StandardError

# @param [String] hako_dir
# @param [Hash] hako_env
# @param [String] yaml_dir
def initialize(hako_dir:, hako_env: {}, yaml_dir:, oneshot_notification_prefix:)
# @param [String] definition_dir
# @param [String] yaml_dir (deprecated: renamed to definition_dir)
def initialize(hako_dir:, hako_env: {}, yaml_dir: nil, definition_dir: nil, oneshot_notification_prefix:)
@hako_dir = hako_dir
@hako_env = hako_env
@yaml_dir = yaml_dir
@definition_dir =
if definition_dir
definition_dir
elsif yaml_dir
warn 'yaml_dir option is renamed to definition_dir. Please update config/barbeque.yml'
yaml_dir
else
raise ArgumentError.new('definition_dir is required')
end
@hako_s3_client = HakoS3Client.new(oneshot_notification_prefix)
end

Expand Down Expand Up @@ -104,10 +113,19 @@ def poll_retry(job_retry)
private

def build_hako_oneshot_command(docker_image, command, envs)
[
'bundle', 'exec', 'hako', 'oneshot', '--no-wait', '--tag', docker_image.tag,
*env_options(envs), File.join(@yaml_dir, "#{docker_image.repository}.yml"), '--', *command,
]
jsonnet_path = File.join(@definition_dir, "#{docker_image.repository}.jsonnet")
yaml_path = File.join(@definition_dir, "#{docker_image.repository}.yml")

cmd = ['bundle', 'exec', 'hako', 'oneshot', '--no-wait', '--tag', docker_image.tag, *env_options(envs)]
if File.readable?(jsonnet_path)
cmd << jsonnet_path
elsif File.readable?(yaml_path)
cmd << yaml_path
else
raise HakoCommandError.new("No definition found matching '#{docker_image.repository}' in #{@definition_dir}")
end
cmd << '--'
cmd.concat(command)
end

def env_options(envs)
Expand Down
6 changes: 5 additions & 1 deletion spec/barbeque/executor/hako_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
described_class.new(
hako_dir: hako_directory,
hako_env: hako_env,
yaml_dir: '/yamls',
definition_dir: '/yamls',
oneshot_notification_prefix: 's3://barbeque/task_statuses?region=ap-northeast-1',
)
end
Expand Down Expand Up @@ -52,6 +52,8 @@
let(:stderr) { '' }

before do
allow(File).to receive(:readable?).with("/yamls/#{app_name}.jsonnet").and_return(false)
allow(File).to receive(:readable?).with("/yamls/#{app_name}.yml").and_return(true)
expect(Open3).to receive(:capture3).with(
hako_env,
'bundle', 'exec', 'hako', 'oneshot', '--no-wait', '--tag', 'latest',
Expand Down Expand Up @@ -207,6 +209,8 @@

describe '#start_retry' do
before do
allow(File).to receive(:readable?).with("/yamls/#{app_name}.jsonnet").and_return(false)
allow(File).to receive(:readable?).with("/yamls/#{app_name}.yml").and_return(true)
expect(Open3).to receive(:capture3).with(
hako_env,
'bundle', 'exec', 'hako', 'oneshot', '--no-wait', '--tag', 'latest',
Expand Down