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

support setting ImageFamily and BootMode when building image #140

Merged

Conversation

hwhuangzsly
Copy link
Contributor

support setting ImageFamily and BootMode when building image

@hwhuangzsly hwhuangzsly requested a review from a team as a code owner May 22, 2024 12:32
Copy link

hashicorp-cla-app bot commented May 22, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@lbajolet-hashicorp lbajolet-hashicorp left a comment

Choose a reason for hiding this comment

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

Hi @hwhuangzsly,

Thanks for the PR, I left a suggestion regarding validating the image family's contents before doing the build, may I also suggest adding unit tests for the config? It would be useful to make sure the invalid cases are caught during Prepare.

I'll let you address those, feel free to ping me when you're done (or if you have questions), and I'll do another pass then.

Thanks again!

builder/ecs/image_config.go Outdated Show resolved Hide resolved
builder/ecs/image_config.go Outdated Show resolved Hide resolved
builder/ecs/image_config.go Show resolved Hide resolved
@hwhuangzsly hwhuangzsly force-pushed the support_set_image_family branch 2 times, most recently from d7929aa to 4ee3aa7 Compare May 24, 2024 03:05
@hwhuangzsly
Copy link
Contributor Author

@lbajolet-hashicorp Thanks for your suggestions. I have added tests to the "target_image_family" and "boot_mode", and optimize the verification method and description of the "target_image_family". Please take a review again~

Copy link
Contributor

@lbajolet-hashicorp lbajolet-hashicorp left a comment

Choose a reason for hiding this comment

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

Hey @hwhuangzsly,

Thanks for the reroll! I've left only a couple of comments left on the regex and the tests, but overall this looks good to me, I'll let you address those and we can come back for another round of reviews then.

Pre-approving so it's not a problem later, the code is near-ready I think.

}

// success
c.AlicloudTargetImageFamily = "success"
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to be sure the \p{L} expression captures that, mind adding a test with chinese characters since they're explicitly documented as valid for the URIs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I add new tests to ensure the regex can match Chinese characters, -, _, : and .

strings.HasPrefix(c.AlicloudTargetImageFamily, "aliyun") {
errs = append(errs, fmt.Errorf("target_image_family can't start with 'aliyun', 'acs:', 'http://' or 'https://'"))
} else {
imageFamilyReg := regexp.MustCompile(`^[a-zA-Z\p{L}][a-zA-Z\p{L}_0-9\-\.\:]{1,127}$`)
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know all my unicode character classes by heart, but doesn't L also match the a-zA-Z ranges? We can probably simplify that expression if that's the case

Suggested change
imageFamilyReg := regexp.MustCompile(`^[a-zA-Z\p{L}][a-zA-Z\p{L}_0-9\-\.\:]{1,127}$`)
imageFamilyReg := regexp.MustCompile(`^\p{L}[\p{L}_0-9\-\.\:]{1,127}$`)

I believe also that both . and : don't need escaping in the context of a []? Not sure though, that probably depends on the regex engine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After testing, I find that p{L} can match a-zA-Z but can't match . or digit, so I simplify it as your suggestion. It's pleasure for me to learn more about the regex rule.

@hwhuangzsly hwhuangzsly force-pushed the support_set_image_family branch 2 times, most recently from 5332248 to 3c89f8c Compare May 25, 2024 09:45
@hwhuangzsly hwhuangzsly force-pushed the support_set_image_family branch from 3c89f8c to 6a8427f Compare May 25, 2024 09:54
@lbajolet-hashicorp
Copy link
Contributor

The last reroll looks good to me @hwhuangzsly, thanks for pushing this one forward!

I'll wait for tests to go green and merge this.

@lbajolet-hashicorp lbajolet-hashicorp merged commit e64189e into hashicorp:main May 27, 2024
12 checks passed
@hwhuangzsly
Copy link
Contributor Author

@lbajolet-hashicorp Excuse me, do you know when the next release version will be made?

@lbajolet-hashicorp
Copy link
Contributor

Hi @hwhuangzsly,

This can happen reasonably soon I would think, maybe today or tomorrow.

I'll let you know when this happens

@hwhuangzsly
Copy link
Contributor Author

@lbajolet-hashicorp Excuse me, as we previously mentioned, the next release version will be made soon. I think maybe you forget it, just a gentle reminder.

@lbajolet-hashicorp
Copy link
Contributor

Hi @hwhuangzsly,

Thanks for the reminder, I did forget indeed.
I've opened a PR for starting this release, provided this is accepted and merged quickly, the release will follow soon after.

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.

2 participants