#!/usr/bin/env ruby
# SPDX-License-Identifier: MulanPSL-2.0+
# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved.
# frozen_string_literal: true

require 'set'
require_relative '../defconfig.rb'

names = Set.new %w[
  SCHED_PORT
  git_branch_cbs
  git_branch_lkp
]
defaults = relevant_defaults(names)

SCHED_PORT = (defaults['SCHED_PORT'] || '3000')
git_branch_cbs = defaults['git_branch_cbs']
git_branch_lkp = defaults['git_branch_lkp']

docker_skip_rebuild "sch-ruby-a:v0.00d-#{SCHED_PORT}"

download_repo("cbs", git_branch_cbs)
download_repo("lkp-tests", git_branch_lkp)

CCI_SRC = ENV['CCI_SRC']
system "bash #{CCI_SRC}/container/compile ."
system "cp #{CCI_SRC}/sbin/create-job-cpio.sh ."

system "docker build --no-cache -t sch-ruby-a:v0.00d-#{SCHED_PORT} ."

push_image_remote "sch-ruby-a:v0.00d-#{SCHED_PORT}"

system 'rm scheduler'
system 'rm create-job-cpio.sh'
