Skip to content

Commit

Permalink
Add missing autobuild-disable flag to publish command (#2733)
Browse files Browse the repository at this point in the history
* add addBundleDefinitionFlags to publish cmd

* add AutoBuildDisabled to publish cmd

* fix docs

Signed-off-by: Aleksey Barabanov <Alexey.Barabanov@kaspersky.com>

* 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 <me@carolynvanslyck.com>

* 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 <me@carolynvanslyck.com>

* 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 <me@carolynvanslyck.com>

---------

Signed-off-by: Aleksey Barabanov <Alexey.Barabanov@kaspersky.com>
Signed-off-by: Carolyn Van Slyck <me@carolynvanslyck.com>
Co-authored-by: Aleksey Barabanov <Alexey.Barabanov@kaspersky.com>
Co-authored-by: Carolyn Van Slyck <me@carolynvanslyck.com>
  • Loading branch information
3 people committed Apr 24, 2023
1 parent 7f119cb commit 0e739d8
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 2 additions & 0 deletions cmd/porter/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}
Expand Down
20 changes: 11 additions & 9 deletions docs/content/cli/publish.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 17 additions & 1 deletion tests/integration/publish_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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))
}

0 comments on commit 0e739d8

Please sign in to comment.