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

Update run image metadata when --run-image is provided #2022

Merged
merged 6 commits into from
Apr 9, 2024

Conversation

Pratham1812
Copy link
Contributor

Summary

Output

Before

image

After

image

Documentation

  • Should this change be documented?
    • Yes, see #___
    • No

Related

Resolves #1964

@Pratham1812 Pratham1812 requested review from a team as code owners January 11, 2024 08:56
@github-actions github-actions bot added this to the 0.33.0 milestone Jan 11, 2024
@github-actions github-actions bot added the type/enhancement Issue that requests a new feature or improvement. label Jan 11, 2024
@Pratham1812
Copy link
Contributor Author

@jjbustamante @natalieparellano could you please review and suggest improvements.

@jjbustamante
Copy link
Member

@Pratham1812 could you run make format in your branch and push it to the repo?

@Pratham1812
Copy link
Contributor Author

Pratham1812 commented Jan 16, 2024

@jjbustamante I have run make prepare-for-pr and committed. Could you please check.

Copy link
Member

@natalieparellano natalieparellano left a comment

Choose a reason for hiding this comment

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

@Pratham1812 thanks a lot for this! I left a few comments

pkg/client/build.go Outdated Show resolved Hide resolved
internal/builder/builder.go Outdated Show resolved Hide resolved
internal/builder/builder.go Outdated Show resolved Hide resolved
internal/builder/builder.go Outdated Show resolved Hide resolved
internal/builder/builder.go Outdated Show resolved Hide resolved
pkg/client/build.go Outdated Show resolved Hide resolved
@@ -1045,7 +1045,7 @@ api = "0.2"
h.AssertNil(t, err)
h.AssertEq(t, fakeLifecycle.Opts.Builder.Name(), defaultBuilderImage.Name())

bldr, err := builder.FromImage(defaultBuilderImage)
bldr, err := builder.FromImage(defaultBuilderImage, "", "")
Copy link
Member

Choose a reason for hiding this comment

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

It would be awesome to see a test that passes in some-value for the run image, and then verifies that some-value is present in the image metadata.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey! I did the changes as per the above comments, I am not sure how to write tests for this, if you could guide me further, it would be great.

pkg/client/build.go Outdated Show resolved Hide resolved
pkg/client/build.go Outdated Show resolved Hide resolved
pkg/client/build.go Outdated Show resolved Hide resolved
@github-actions github-actions bot added the type/chore Issue that requests non-user facing changes. label Jan 18, 2024
@@ -332,7 +332,7 @@ func (c *Client) Build(ctx context.Context, opts BuildOptions) error {
return errors.Wrapf(err, "getting builder architecture")
}

bldr, err := c.getBuilder(rawBuilderImage)
bldr, err := c.getBuilder(rawBuilderImage, opts.RunImage)
Copy link
Member

Choose a reason for hiding this comment

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

Do we really need this one? is it not enough with the createEphemeralBuilder change?

Copy link
Member

Choose a reason for hiding this comment

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

I pulled your branch, built the binary and tested out removing this, and it is still working so I think we don't need it.

@jjbustamante
Copy link
Member

jjbustamante commented Jan 18, 2024

@natalieparellano could you give me your thoughts here.

Testing the binary, I can see the following output

pack build -B paketobuildpacks/builder-jammy-base -p ./java-maven  --run-image paketobuildpacks/run-jammy-base:0.0.2  java-app-3

In this case we are replacing the run-image with paketobuildpacks/run-jammy-base:0.0.2, checking the docker config file:

 docker inspect java-app-3  | jq '.[] | .Config.Labels | ."io.buildpacks.lifecycle.metadata" | fromjson' | jq .
{
  "runImage": {
    "topLayer": "sha256:be9eb0a7d50b0438c62376a29b5557f85496a55ae83d41a49f934160ffa09421",
    "reference": "945a5e4052d9b9b024f69bf89f8cf8bd72bc727882ab0b78df9592b37119a31c",
    "image": "paketobuildpacks/run-jammy-base:0.0.2"
  },
  "stack": {
    "runImage": {
      "image": "paketobuildpacks/run-jammy-base:0.0.2"
    }
}
  • Is it ok to change the stack.runImage.image? I think we shouldn't, we should only change the runImage.image metadada

@github-actions github-actions bot removed the type/chore Issue that requests non-user facing changes. label Jan 18, 2024
@natalieparellano
Copy link
Member

Is it ok to change the stack.runImage.image? I think we shouldn't, we should only change the runImage.image metadada

It should be okay, actually preferred - runImage.image and stack.runImage.image refer to the same thing, and are written twice for backwards compatibility.

@jjbustamante jjbustamante modified the milestones: 0.33.0, 0.34.0 Jan 24, 2024
@jjbustamante
Copy link
Member

Hi @Pratham1812 could try to solve the merge conflicts and the DCO check ?

@jjbustamante
Copy link
Member

I tried to fix the acceptance test failures. I focused in one of them and here are my findings.

The test case is trying to rebase an application image saved in the docker daemon with mirrors metadata saved with the application image.

Behavior before this PR

  • First we created a builder, and the builder has a pack-test/run as run image
  • Then we built the application image with a command similar to pack build localhost:32801/some-org/xeyagowjzc --run-image localhost:32801/run-before/vgdpkyhhne
  • The output from the previous command is an application image localhost:32801/some-org/xeyagowjzc with the following io.buildpacks.lifecycle.metadata
"runImage": {
    "topLayer": "sha256:47746006a138ccf6c120beaf5ec55a5589fc6a9b93777082ee9e3b722f3ddf73",
    "reference": "92761540a511123b9c76b9e4fe8c4826c3d19ef1dbfd67ed6b825d6b43546bb6",
    "image": "pack-test/run",
    "mirrors": [
      "localhost:32801/pack-test/run"
    ]
  },
  "stack": {
    "runImage": {
      "image": "pack-test/run",
      "mirrors": [
        "localhost:32801/pack-test/run"
      ]
    }
  }
  • Finally we run pack rebase localhost:32801/some-org/xeyagowjzcand and the Test expects the run image to be selected from the mirror.

If we take a look at the previous metadata, the runImage.Image is using the value from the Builder and the --run-image used during pack build is not being saved (which is actually the issue this PR is trying to solve)

Behavior with this PR

The current PR is updating the metadata when pack build is invoked, as I mentioned above, we are running pack build --run-image to setup the test fixture. The io.buildpacks.lifecycle.metadata looks like this with the new code.

"runImage": {
    "topLayer": "sha256:74275d5fce8e3c3343321b75529e7751bd5966664f6af3aec1bb50890c7b6e39",
    "reference": "5d17ab3bdb1b4764f429b059f7a8a1a7f820c4553d2a3f3dfeff69668a5c881a",
    "image": "localhost:32804/run-before/byxrrrztji",
    "mirrors": [
      "localhost:32804/pack-test/run"
    ]
  },
  "stack": {
    "runImage": {
      "image": "localhost:32804/run-before/byxrrrztji",
      "mirrors": [
        "localhost:32804/pack-test/run"
      ]
    }
  }
  • When running the rebase, the run image selected is localhost:32804/run-before/byxrrrztji and not the expected localhost:32804/pack-test/run.
    I think the metadata is correct, and the problem is with the test case and how to set up the fixture to use the mirrors. I think we need to do something to make the access_checker to return false when run-before image is used, I tried removing the image in the Before but it didn't work

@@ -140,6 +148,11 @@ func constructBuilder(img imgutil.Image, newName string, errOnMissingLabel bool,
return nil, err
}

if opts.runImage != "" {
metadata.RunImages = []RunImageMetadata{{Image: opts.runImage}}
metadata.Stack.RunImage.Image = opts.runImage
Copy link
Member

@natalieparellano natalieparellano Mar 5, 2024

Choose a reason for hiding this comment

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

Looking at this again, we need to be consistent in how we handle mirrors information. Right now it is being zeroed out for metadata.RunImages but preserved for metadata.Stack.RunImage (as metadata.Stack.RunImage.Mirrors could still have data).

I propose we look in the existing known run images (RunImageMetadata.Mirrors) and if the provided opts.runImage is found there then preserve the run image mirror information, otherwise zero it out.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I did that locally, trying to fix the issues with the acceptance but I didn't push it

@natalieparellano
Copy link
Member

natalieparellano commented Mar 5, 2024

@jjbustamante since the linked acceptance test is validating rebase behavior we should probably just update the test setup to produce a test image (repoName) with the correct metadata. I think if we update these lines in the test setup to remove --run-image it might just work, as this particular test doesn't have any expectations around runBefore. We might have to duplicate the setup for this test to avoid breaking others in this block.

Update: I think my suggestion of updating the setup will work. But, you have to also remove these lines from the setup, otherwise the test will fail with an inscrutable error.

@github-actions github-actions bot added the type/chore Issue that requests non-user facing changes. label Mar 5, 2024
Copy link

codecov bot commented Mar 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.72%. Comparing base (6a9e3d1) to head (dfe0e73).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2022      +/-   ##
==========================================
+ Coverage   79.70%   79.72%   +0.02%     
==========================================
  Files         176      176              
  Lines       13250    13261      +11     
==========================================
+ Hits        10560    10571      +11     
  Misses       2021     2021              
  Partials      669      669              
Flag Coverage Δ
os_linux 78.63% <100.00%> (+0.01%) ⬆️
os_macos 76.36% <100.00%> (+0.02%) ⬆️
os_windows 79.11% <100.00%> (+0.02%) ⬆️
unit 79.72% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

@jjbustamante
Copy link
Member

Hi @Pratham1812!

We made some changes to your code to get it into the last mile! but we need you to fix the DCO issues to get this PR merged. Is it possible for you to do that?

@jjbustamante
Copy link
Member

@Pratham1812

The steps required to sign-off your commits are describe here, the most important are:

To add your Signed-off-by line to every commit in this branch:

  1. Ensure you have a local copy of your branch by checking out the pull request locally via command line.
  2. In your local branch, run: git rebase HEAD~16 --signoff
  3. Force push your changes to overwrite the branch: git push --force-with-lease origin alpha/patch

It is very important that you sign-off your commits in order for us to merge the PR! Otherwise we can't do it

@jjbustamante
Copy link
Member

Oh man! I think you didn't update your main fork before running the rebase right? and we still have some commits without signing.

Signed-off-by: Pratham Agarwal <agarwalpratham1812@gmail.com>
Signed-off-by: Pratham Agarwal <agarwalpratham1812@gmail.com>
Signed-off-by: Pratham Agarwal <agarwalpratham1812@gmail.com>
Signed-off-by: Pratham Agarwal <agarwalpratham1812@gmail.com>
- Adding acceptance tests

Signed-off-by: Juan Bustamante <jbustamante@vmware.com>
@natalieparellano
Copy link
Member

Looks good to me :) I suggested a few cosmetic changes

@natalieparellano natalieparellano changed the title resolve issue #1964 Update run image metadata when --run-image is provided Apr 5, 2024
…ck from Natalie

Signed-off-by: Juan Bustamante <jbustamante@vmware.com>
@jjbustamante jjbustamante enabled auto-merge April 9, 2024 14:31
@jjbustamante jjbustamante disabled auto-merge April 9, 2024 14:31
@jjbustamante jjbustamante merged commit 969ff6c into buildpacks:main Apr 9, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/chore Issue that requests non-user facing changes. type/enhancement Issue that requests a new feature or improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pack build command not picking the run image
3 participants