diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c3e190e..9184004d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,11 +17,14 @@ _Please add entries here for your pull requests that have not yet been released. ### Fixed - Fixed issue where `run` command fails when runner workload has ENV but original workload does not. [PR 227](https://github.com/shakacode/control-plane-flow/pull/227) by [Rafael Gomes](https://github.com/rafaelgomesxyz). - - Fixed potential infinite loop that could occur for a command if one of the execution steps fails and gets stuck. [PR 217](https://github.com/shakacode/control-plane-flow/pull/217) by [Zakir Dzhamaliddinov](https://github.com/zzaakiirr). - - Fixed issue where app cannot be deleted because one of the workloads has a volumeset in-use. [PR 245](https://github.com/shakacode/control-plane-flow/pull/245) by [Zakir Dzhamaliddinov](https://github.com/zzaakiirr). +### Added + +- Added `--docker-context` option to `build-image` command. [PR 250](https://github.com/shakacode/control-plane-flow/pull/250) by [Sergey Tarasov](https://github.com/dzirtusss). + + ## [4.0.0] - 2024-08-21 ### Fixed diff --git a/lib/command/base.rb b/lib/command/base.rb index dd05997b..74c69909 100644 --- a/lib/command/base.rb +++ b/lib/command/base.rb @@ -442,6 +442,17 @@ def self.add_app_identity_option(required: false) } } end + + def self.docker_context_option + { + name: :docker_context, + params: { + desc: "Path to the docker build context directory", + type: :string, + required: false + } + } + end # rubocop:enable Metrics/MethodLength def self.all_options diff --git a/lib/command/build_image.rb b/lib/command/build_image.rb index 6a75c509..6d56402a 100644 --- a/lib/command/build_image.rb +++ b/lib/command/build_image.rb @@ -5,7 +5,8 @@ class BuildImage < Base NAME = "build-image" OPTIONS = [ app_option(required: true), - commit_option + commit_option, + docker_context_option ].freeze ACCEPTS_EXTRA_OPTIONS = true DESCRIPTION = "Builds and pushes the image to Control Plane" @@ -34,9 +35,12 @@ def call # rubocop:disable Metrics/MethodLength build_args = [] build_args.push("GIT_COMMIT=#{commit}") if commit + docker_context = config.options[:docker_context] || config.app_dir + cp.image_build(image_url, dockerfile: dockerfile, docker_args: config.args, - build_args: build_args) + build_args: build_args, + docker_context: docker_context) push_path = "/org/#{config.org}/image/#{image_name}" diff --git a/lib/core/controlplane.rb b/lib/core/controlplane.rb index 601bd032..e1665a03 100644 --- a/lib/core/controlplane.rb +++ b/lib/core/controlplane.rb @@ -90,7 +90,7 @@ def query_images(a_gvc = gvc, a_org = org, partial_gvc_match: nil) api.query_images(org: a_org, gvc: a_gvc, gvc_op_type: gvc_op) end - def image_build(image, dockerfile:, docker_args: [], build_args: []) + def image_build(image, dockerfile:, docker_context:, docker_args: [], build_args: []) # https://docs.controlplane.com/guides/push-image#step-2 # Might need to use `docker buildx build` if compatiblitity issues arise cmd = "docker build --platform=linux/amd64 -t #{image} -f #{dockerfile}" @@ -98,7 +98,7 @@ def image_build(image, dockerfile:, docker_args: [], build_args: []) cmd += " #{docker_args.join(' ')}" if docker_args.any? build_args.each { |build_arg| cmd += " --build-arg #{build_arg}" } - cmd += " #{config.app_dir}" + cmd += " #{docker_context}" perform!(cmd) end