From 0e739d88fc73db6d21238ded6856cbba4f822989 Mon Sep 17 00:00:00 2001 From: Aleksey <61249402+alekseybb197@users.noreply.github.com> Date: Mon, 24 Apr 2023 23:58:49 +0300 Subject: [PATCH] Add missing autobuild-disable flag to publish command (#2733) * add addBundleDefinitionFlags to publish cmd * add AutoBuildDisabled to publish cmd * fix docs Signed-off-by: Aleksey Barabanov * Correct how --autobuild-disabled is defined on publish * The flag doesn't need to be manually configured with viper because the flag is defined on publish. * The flag doesn't need to be defined on Config.DataStore because the flag is defined on publish. * Update example to use --autobuild-disabled without =true, since that is the default when the flag is specified. Signed-off-by: Carolyn Van Slyck * Add test for publish --autobuild-disabled Add a test to validate that we can disable autobuild for the publish command. Signed-off-by: Carolyn Van Slyck * Add regression test for autobuild-disabled via config This adds a regression test for setting autobuild-disabled to true in a config file and having the CLI correctly pick up the setting. Signed-off-by: Carolyn Van Slyck --------- Signed-off-by: Aleksey Barabanov Signed-off-by: Carolyn Van Slyck Co-authored-by: Aleksey Barabanov Co-authored-by: Carolyn Van Slyck --- CONTRIBUTORS.md | 1 + cmd/porter/bundle.go | 2 ++ docs/content/cli/publish.md | 20 +++++++++++--------- tests/integration/publish_test.go | 18 +++++++++++++++++- 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index c70236f2e..8d283060e 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -80,3 +80,4 @@ and we will add you. **All** contributors belong here. 💯 * [James Blair](https://github.com/jmhbnz) * [Chengwei Guo](https://github.com/cw-Guo) * [Sarah Christoff](https://github.com/hypernovasunnix) +* [Aleksey Barabanov](https://github.com/alekseybb197) diff --git a/cmd/porter/bundle.go b/cmd/porter/bundle.go index 85906f4ac..faa12275d 100644 --- a/cmd/porter/bundle.go +++ b/cmd/porter/bundle.go @@ -146,6 +146,7 @@ Note: if overrides for registry/tag/reference are provided, this command only re porter bundle publish --archive /tmp/mybuns.tgz --reference myrepo/my-buns:0.1.0 porter bundle publish --tag latest porter bundle publish --registry myregistry.com/myorg + porter bundle publish --autobuild-disabled `, PreRunE: func(cmd *cobra.Command, args []string) error { return opts.Validate(p.Config) @@ -169,6 +170,7 @@ Note: if overrides for registry/tag/reference are provided, this command only re cmd.Flag("force").Annotations = map[string][]string{ "viper-key": {"force-overwrite"}, } + f.BoolVar(&opts.AutoBuildDisabled, "autobuild-disabled", false, "Do not automatically build the bundle from source when the last build is out-of-date.") return &cmd } diff --git a/docs/content/cli/publish.md b/docs/content/cli/publish.md index 4e7d2bfe8..27e0fa8a2 100644 --- a/docs/content/cli/publish.md +++ b/docs/content/cli/publish.md @@ -26,21 +26,23 @@ porter publish [flags] porter publish --archive /tmp/mybuns.tgz --reference myrepo/my-buns:0.1.0 porter publish --tag latest porter publish --registry myregistry.com/myorg + porter publish --autobuild-disabled ``` ### Options ``` - -a, --archive string Path to the bundle archive in .tgz format - -d, --dir string Path to the build context directory where all bundle assets are located. - -f, --file porter.yaml Path to the Porter manifest. Defaults to porter.yaml in the current directory. - --force Force push the bundle to overwrite the previously published bundle - -h, --help help for publish - --insecure-registry Don't require TLS for the registry - -r, --reference string Use a bundle in an OCI registry specified by the given reference. - --registry string Override the registry portion of the bundle reference, e.g. docker.io, myregistry.com/myorg - --tag string Override the Docker tag portion of the bundle reference, e.g. latest, v0.1.1 + -a, --archive string Path to the bundle archive in .tgz format + --autobuild-disabled Do not automatically build the bundle from source when the last build is out-of-date. + -d, --dir string Path to the build context directory where all bundle assets are located. + -f, --file porter.yaml Path to the Porter manifest. Defaults to porter.yaml in the current directory. + --force Force push the bundle to overwrite the previously published bundle + -h, --help help for publish + --insecure-registry Don't require TLS for the registry + -r, --reference string Use a bundle in an OCI registry specified by the given reference. + --registry string Override the registry portion of the bundle reference, e.g. docker.io, myregistry.com/myorg + --tag string Override the Docker tag portion of the bundle reference, e.g. latest, v0.1.1 ``` ### Options inherited from parent commands diff --git a/tests/integration/publish_test.go b/tests/integration/publish_test.go index bf1fc8d66..14c84400d 100644 --- a/tests/integration/publish_test.go +++ b/tests/integration/publish_test.go @@ -4,8 +4,10 @@ package integration import ( "fmt" + "path" "testing" + "get.porter.sh/porter/pkg/yaml" "get.porter.sh/porter/tests" "get.porter.sh/porter/tests/tester" "github.com/stretchr/testify/require" @@ -20,14 +22,28 @@ func TestPublish(t *testing.T) { test.Chdir(test.TestDir) test.RequirePorter("create") + // Try to publish with autobuild disabled, it should fail + _, _, err = test.RunPorter("publish", "--autobuild-disabled") + require.ErrorContains(t, err, "Skipping autobuild because --autobuild-disabled was specified") + + // Try again with autobuild disabled via a config setting instead of a flag + // This is a regression test for https://github.com/getporter/porter/issues/2735 + test.EditYaml(path.Join(test.PorterHomeDir, "config.yaml"), func(yq *yaml.Editor) error { + return yq.SetValue("autobuild-disabled", "true") + }) + _, output, err := test.RunPorter("publish") + fmt.Println(output) + require.ErrorContains(t, err, "Skipping autobuild because --autobuild-disabled was specified") + // Build with version override test.RequirePorter("build", "--version=0.0.0") // Start up an insecure registry with self-signed TLS certificates reg := test.StartTestRegistry(tester.TestRegistryOptions{UseTLS: true}) + defer reg.Close() // Confirm that publish picks up the version override // Use an insecure registry to validate that we can publish to one - _, output := test.RequirePorter("publish", "--registry", reg.String(), "--insecure-registry") + _, output = test.RequirePorter("publish", "--registry", reg.String(), "--insecure-registry") tests.RequireOutputContains(t, output, fmt.Sprintf("Bundle %s/porter-hello:v0.0.0 pushed successfully", reg)) }