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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: clone images on specified services #4270

Merged
merged 18 commits into from
Jun 14, 2024
Merged

fix: clone images on specified services #4270

merged 18 commits into from
Jun 14, 2024

Conversation

jLopezbarb
Copy link
Contributor

@jLopezbarb jLopezbarb commented Apr 29, 2024

Proposed changes

Fixes DEV-232

  • Fix multi tags with okteto registries.
    • When we run a command like okteto build -t okteto.dev/myapp:1.0.0,okteto.dev/myapp:latest
    • It was preventing us to create a clone
  • Create a new clone function that clones one image into another without calculating anything
    • Reuse that new function in the cloneFromGlobalToDev
  • Fix: Smartbuild was not getting the correct interface
    • The interface was the same but the methods were named different. In this PR we use the same naming
  • Created getGlobalTagFromDevIfNeccesary in order to get the global tag from dev if we need to build into the global registry too

It has created a side effect where we show that the image has been successfully pushed into the two registries. I think it's better for the user so he knows what's happening. Are we ok with that
Screenshot 2024-05-22 at 12 49 15

How to validate

  1. Copy the following okteto.ylm
build:
  my-service:
    image: okteto.dev/my-service:my-tag
    context: my-service
  1. Create my-service folder with a simple Dockerfile (FROM alpine)
  2. Run okteto build
  3. Check that we are pushing to the dev registry to the image in the field and the global registry with the hash as the tag

CLI Quality Reminders 馃敡

For both authors and reviewers:

  • Scrutinize for potential regressions
  • Ensure key automated tests are in place
  • Build the CLI and test using the validation steps
  • Assess Developer Experience impact (log messages, performances, etc)
  • If too broad, consider breaking into smaller PRs
  • Adhere to our code style and code review guidelines

@@ -92,6 +94,19 @@ func (it imageTagger) getServiceImageReference(manifestName, svcName string, b *
return useReferenceTemplate(targetRegistry, sanitizedName, svcName, model.OktetoDefaultImageTag)
}

func (it imageTagger) getGlobalTagFromDevIfNeccesary(tags, namespace, registryURL, buildHash, manifestName, svcName string, ic registry.ImageCtrl) string {
tagList := strings.Split(tags, ",")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to expand this to build all the global images from the parsed tags

E: fmt.Errorf("'%s' isn't a valid image tag", imageTag),
Hint: fmt.Sprintf("The Okteto Registry syntax is: '%s/image_name'", prefix),
tags := strings.Split(imageTags, ",")
for _, tag := range tags {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fix to pass several tags with okteto.dev

Signed-off-by: Javier Lopez <[email protected]>
Signed-off-by: Javier Lopez <[email protected]>
Signed-off-by: Javier Lopez <[email protected]>
Copy link

codecov bot commented May 21, 2024

Codecov Report

Attention: Patch coverage is 76.72414% with 27 lines in your changes missing coverage. Please review.

Project coverage is 43.25%. Comparing base (eb683fb) to head (634c93e).
Report is 5 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4270   +/-   ##
=======================================
  Coverage   43.25%   43.25%           
=======================================
  Files         375      375           
  Lines       30200    30222   +22     
=======================================
+ Hits        13064    13074   +10     
- Misses      15989    16007   +18     
+ Partials     1147     1141    -6     

Signed-off-by: Javier Lopez <[email protected]>
@jLopezbarb jLopezbarb marked this pull request as ready for review May 22, 2024 10:51
@jLopezbarb jLopezbarb requested a review from a team as a code owner May 22, 2024 10:51
Signed-off-by: Javier Lopez <[email protected]>
@ifbyol
Copy link
Member

ifbyol commented May 24, 2024

It has created a side effect where we show that the image has been successfully pushed into the two registries. I think it's better for the user so he knows what's happening. Are we ok with that

@jLopezbarb Why the double message? Before it was also happening but only on BuildKit logs, but not in the final success step

Copy link
Member

@ifbyol ifbyol left a comment

Choose a reason for hiding this comment

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

As we talked offline, we are mixing 2 ways of cloning images:

  • Old one: If the user didn't specify an image in the build info, we pass one tag in buildInfo.Tag and then, in buildkit.go, we fill buildOptions.DevTag with the dev tag to push
  • New one (added in this PR). If the user specify an image, and it is for dev registry, we pass 2 images in buildOptions.Tag and then, DevTag is not filled just because dev tag is the first in the list

We should unify both ways to just one to avoid problems in the future

Comment on lines 279 to 287
if ob.Registry.IsOktetoRegistry(firstTag) {
imageWithDigest, err = ob.smartBuildCtrl.Clone(imageWithDigest, firstTag)
if err != nil {
return err
}
}
} else {
imageWithDigest, err = ob.smartBuildCtrl.CloneGlobalImageToDev(imageWithDigest)
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Can't we unify this somehow instead of having to have 2 different functions (very similar)? At the end, CloneGlobalImageToDev wil have to clone always to okteto.dev/<image>:okteto. WDYT? Would it make sense?

pkg/cmd/build/build.go Outdated Show resolved Hide resolved
cmd/build/v2/build.go Outdated Show resolved Hide resolved
Signed-off-by: Javier Lopez <[email protected]>
@jLopezbarb
Copy link
Contributor Author

As we talked offline, we are mixing 2 ways of cloning images:

  • Old one: If the user didn't specify an image in the build info, we pass one tag in buildInfo.Tag and then, in buildkit.go, we fill buildOptions.DevTag with the dev tag to push
  • New one (added in this PR). If the user specify an image, and it is for dev registry, we pass 2 images in buildOptions.Tag and then, DevTag is not filled just because dev tag is the first in the list

We should unify both ways to just one to avoid problems in the future

On the old one we were only adding the dev tag if the image was a global image. I've removed the code so we are only using the new method

Signed-off-by: Javier Lopez <[email protected]>
cmd/build/v2/build.go Outdated Show resolved Hide resolved
cmd/build/v2/build.go Outdated Show resolved Hide resolved
@jLopezbarb jLopezbarb requested a review from ifbyol May 30, 2024 11:04
Signed-off-by: Javier Lopez <[email protected]>
Signed-off-by: Javier Lopez <[email protected]>
cmd/build/v2/smartbuild/smartbuild.go Outdated Show resolved Hide resolved
cmd/build/v2/tagger.go Outdated Show resolved Hide resolved
cmd/build/v2/tagger.go Outdated Show resolved Hide resolved
Signed-off-by: Javier Lopez <[email protected]>
Signed-off-by: Javier Lopez <[email protected]>
@@ -185,70 +188,6 @@ func TestGetBuildHash(t *testing.T) {
assert.Equal(t, "hash", out)
}

func TestCloneGlobalImageToDev(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

I think you need to change also the tests. It is no longer TestClone

@ifbyol
Copy link
Member

ifbyol commented Jun 10, 2024

Discussed offline, there is 1 case that doesn't work as expected. If I set my own image with a specific name, it is being cloned to global with other name instead of using the 1 I specified

Signed-off-by: Javier Lopez <[email protected]>
Copy link
Member

@teresaromero teresaromero left a comment

Choose a reason for hiding this comment

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

Tested couple scenarios, LGTM

Signed-off-by: Javier Lopez <[email protected]>
@ifbyol
Copy link
Member

ifbyol commented Jun 11, 2024

I found another issue while validating the changes. It is related to my previous message: #4270 (comment)

When I specify a custom image in the image field pointing to an Okteto dev registry image, e.g. okteto.dev/<image-name>:<my-custom-tag>, Smart Builds is not checking the right image. Instead of using the image name specified in image field, it is calculating the image name based on the service name. It should also check using the name specified in the image field

Signed-off-by: Javier Lopez <[email protected]>
@jLopezbarb jLopezbarb merged commit 7870e0e into master Jun 14, 2024
11 of 12 checks passed
@jLopezbarb jLopezbarb deleted the jlo/dev-232 branch June 14, 2024 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants