From ce3d2d00a6cf96949d7fef264593730da149a94a Mon Sep 17 00:00:00 2001 From: Rafael Gomes Date: Mon, 22 Jan 2024 01:22:44 -0300 Subject: [PATCH] Allow specifying upstream for `copy-image-from-upstream` command through `CPLN_UPSTREAM` env var (#138) * feat: allow specifying upstream through env var --- CHANGELOG.md | 1 + docs/commands.md | 2 +- lib/command/copy_image_from_upstream.rb | 4 ++-- spec/command/copy_image_from_upstream_spec.rb | 1 + 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index acca9486..d85a6161 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ _Please add entries here for your pull requests that are not yet released._ - Added `--domain` option to `maintenance`, `maintenance:on` and `maintenance:off` commands. [PR 131](https://github.com/shakacode/heroku-to-control-plane/pull/131) by [Rafael Gomes](https://github.com/rafaelgomesxyz). - Added `default_domain` config to specify domain for `maintenance`, `maintenance:on` and `maintenance:off` commands. [PR 131](https://github.com/shakacode/heroku-to-control-plane/pull/131) by [Rafael Gomes](https://github.com/rafaelgomesxyz). +- Added option to specify upstream for `copy-image-from-upstream` command through `CPLN_UPSTREAM` env var. [PR 138](https://github.com/shakacode/heroku-to-control-plane/pull/138) by [Rafael Gomes](https://github.com/rafaelgomesxyz). ### Changed diff --git a/docs/commands.md b/docs/commands.md index 9bb48a12..523617ba 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -87,7 +87,7 @@ cpl config -a $APP_NAME ### `copy-image-from-upstream` - Copies an image (by default the latest) from a source org to the current org -- The source org must be specified through `upstream` in the `.controlplane/controlplane.yml` file +- The source app must be specified either through the `CPLN_UPSTREAM` env var or `upstream` in the `.controlplane/controlplane.yml` file - Additionally, the token for the source org must be provided through `--upstream-token` or `-t` - A `cpln` profile will be temporarily created to pull the image from the source org diff --git a/lib/command/copy_image_from_upstream.rb b/lib/command/copy_image_from_upstream.rb index 9eb86325..f2d8d045 100644 --- a/lib/command/copy_image_from_upstream.rb +++ b/lib/command/copy_image_from_upstream.rb @@ -11,7 +11,7 @@ class CopyImageFromUpstream < Base DESCRIPTION = "Copies an image (by default the latest) from a source org to the current org" LONG_DESCRIPTION = <<~DESC - Copies an image (by default the latest) from a source org to the current org - - The source org must be specified through `upstream` in the `.controlplane/controlplane.yml` file + - The source app must be specified either through the `CPLN_UPSTREAM` env var or `upstream` in the `.controlplane/controlplane.yml` file - Additionally, the token for the source org must be provided through `--upstream-token` or `-t` - A `cpln` profile will be temporarily created to pull the image from the source org DESC @@ -28,7 +28,7 @@ class CopyImageFromUpstream < Base def call # rubocop:disable Metrics/MethodLength ensure_docker_running! - @upstream = config[:upstream] + @upstream = ENV.fetch("CPLN_UPSTREAM", nil) || config[:upstream] @upstream_org = ENV.fetch("CPLN_ORG_UPSTREAM", nil) || config.find_app_config(@upstream)&.dig(:cpln_org) ensure_upstream_org! diff --git a/spec/command/copy_image_from_upstream_spec.rb b/spec/command/copy_image_from_upstream_spec.rb index b5059c17..9ce39fb6 100644 --- a/spec/command/copy_image_from_upstream_spec.rb +++ b/spec/command/copy_image_from_upstream_spec.rb @@ -10,6 +10,7 @@ allow(ENV).to receive(:fetch).with("CPLN_ORG", nil).and_return(nil) allow(ENV).to receive(:fetch).with("CPLN_ORG_UPSTREAM", nil).and_return(nil) allow(ENV).to receive(:fetch).with("CPLN_APP", nil).and_return(nil) + allow(ENV).to receive(:fetch).with("CPLN_UPSTREAM", nil).and_return(nil) allow_any_instance_of(Config).to receive(:config_file_path).and_return("spec/fixtures/config.yml") allow_any_instance_of(described_class).to receive(:ensure_docker_running!) allow_any_instance_of(Controlplane).to receive(:profile_exists?).and_return(false)