Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish to helm registry #91

Closed

Conversation

sherry-ummen
Copy link

@sherry-ummen sherry-ummen commented May 12, 2020

Support for publish to Helm Registry

Fixes #90

Its using method defined here : https://helm.sh/docs/topics/registries/

Basically following command:

  • export HELM_EXPERIMENTAL_OCI=1
  • helm registry login -u myuser localhost:5000
  • helm registry logout localhost:5000
  • helm chart save mychart/ localhost:5000/myrepo/mychart:2.7.0
  • helm chart push localhost:5000/myrepo/mychart:2.7.0

Tested it with Azure Container Registry

Copy link
Contributor

@ErinCall ErinCall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Despite all my quibbles, this looks great overall. Thanks for diving into it!

Comment on lines +73 to +80
| Param name | Type | Required | Alias | Purpose |
|------------------------|----------|----------|------------------------|---------|
| registry_url | string | yes | | Registry url to where the chart be published|
| registry_login_user_id | string | yes | | Login ID for the Helm registry |
| registry_login_password| string | yes | | Login Password for the Helm registry |
| registry_repo_name | string | yes | | Repository name in the Helm registry |
| chart_version | string | yes | | Version of the chart |
| chart | string | | | Local path of the chart |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind aligning the whitespace here? It doesn't matter for the rendered markdown, but it makes the file easier to read while editing :)

Suggested change
| Param name | Type | Required | Alias | Purpose |
|------------------------|----------|----------|------------------------|---------|
| registry_url | string | yes | | Registry url to where the chart be published|
| registry_login_user_id | string | yes | | Login ID for the Helm registry |
| registry_login_password| string | yes | | Login Password for the Helm registry |
| registry_repo_name | string | yes | | Repository name in the Helm registry |
| chart_version | string | yes | | Version of the chart |
| chart | string | | | Local path of the chart |
| Param name | Type | Required | Alias | Purpose |
| ------------------------ | ---------- | ---------- | ------------------------ | --------- |
| registry_url | string | yes | | Registry url to where the chart be published |
| registry_login_user_id | string | yes | | Login ID for the Helm registry |
| registry_login_password | string | yes | | Login Password for the Helm registry |
| registry_repo_name | string | yes | | Repository name in the Helm registry |
| chart_version | string | yes | | Version of the chart |
| chart | string | | | Local path of the chart |


if reg.subCommand == "save" {
args = append(args, "save")
args = append(args, reg.chartPath)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to check for an empty chartPath? I haven't checked how helm save "" [ref] behaves, but I wouldn't expect it to be the same as helm save [ref].

Suggested change
args = append(args, reg.chartPath)
if reg.chartPath != "" {
args = append(args, reg.chartPath)
}

Comment on lines +50 to +51
cmd := fmt.Sprintf("%s/%s:%s", reg.registryURL, reg.registryRepoName, reg.chartVersion)
args = append(args, cmd)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two lines are the same as their counterparts in reg.subCommand == "save", right? If so they should go after the if clause, so they're less likely to accidentally diverge in the future.

RegistryURL string `envconfig:"registry_url"`
RegistryLoginUserID string `envconfig:"registry_login_user_id"`
RegistryLoginPassword string `envconfig:"registry_login_password"`
RegistryRepoName string `envconfig:"registry_repo_name"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Newly-added settings don't need entries in settingAliases—the aliases are for backwards compatibility if a setting gets renamed.

@@ -136,3 +139,16 @@ var lint = func(cfg env.Config) []Step {
var help = func(cfg env.Config) []Step {
return []Step{run.NewHelp(cfg)}
}

var publish = func(cfg env.Config) []Step {
fmt.Println("inside publish")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's some leftover debug logging here

Suggested change
fmt.Println("inside publish")

Comment on lines +33 to +34
func (reg *Chart) Execute() error {
return reg.cmd.Run()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: there's a bit of copy-paste left over here (and the same thing in Prepare)

Suggested change
func (reg *Chart) Execute() error {
return reg.cmd.Run()
func (chart *Chart) Execute() error {
return chart.cmd.Run()

}

// Prepare gets the Registry ready to execute.
func (reg *Registry) Prepare() error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above—this should check for missing config, and a test for these cases would be nice if you have the time.

Suggested change
func (reg *Registry) Prepare() error {
func (reg *Registry) Prepare() error {
if reg.userID == "" {
return fmt.Errorf("registry_login_user_id is required")
}
if reg.password == "" {
return fmt.Errorf("registry_login_password is required")
}
if reg.registryURL == "" {
return fmt.Errorf("registry_url is required")
}

fmt.Println("inside publish")
var steps []Step

os.Setenv("HELM_EXPERIMENTAL_OCI", "1")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than a bare os.Setenv, please set this in the environment for the cmd in Chart and Registry:

	environ := os.Environ()
	environ = append(environ, "HELM_EXPERIMENTAL_OCI=1")
	reg.cmd.Env(environ)

Changing the environment mid-execution doesn't always cause problems, but when problems do arise it's a headache trying to track them down.

RegistryURL: "registry_url",
}

u := NewRegistry("login", cfg)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: some leftover copy-paste here (and in TestPrepareAndExecuteLogout).

Suggested change
u := NewRegistry("login", cfg)
reg := NewRegistry("login", cfg)

Comment on lines +70 to +79
chart: ./
environment:
REGISTRY_URL:
from_secret: registry_url
REGISTRY_LOGIN_USER_ID:
from_secret: registry_login_user_id
REGISTRY_LOGIN_PASSWORD:
from_secret: registry_login_password
REGISTRY_REPO_NAME: <helm_repository_name>
CHART_VERSION: <version>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of nitpicks here:

  1. Since registry_repo_name and chart_version don't need to come from secrets, the settings block is a more appropriate spot for them.
  2. The README examples should only contain the required params, to minimize the amount of scrolling people have to do.
Suggested change
chart: ./
environment:
REGISTRY_URL:
from_secret: registry_url
REGISTRY_LOGIN_USER_ID:
from_secret: registry_login_user_id
REGISTRY_LOGIN_PASSWORD:
from_secret: registry_login_password
REGISTRY_REPO_NAME: <helm_repository_name>
CHART_VERSION: <version>
registry_repo_name: <helm_repository_name>
chart_version: <version>
environment:
REGISTRY_URL:
from_secret: registry_url
REGISTRY_LOGIN_USER_ID:
from_secret: registry_login_user_id
REGISTRY_LOGIN_PASSWORD:
from_secret: registry_login_password

@sherry-ummen
Copy link
Author

Hey thanks for the review, I will fix these soon. sorry for the delay

@josmo
Copy link
Member

josmo commented Aug 23, 2022

This is pushing a couple years so I'm going to close this out - if issues get address we can reopen :)

@josmo josmo closed this Aug 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for publish to Helm Registry
3 participants