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

Fixes for run image extension #1134

Merged
merged 10 commits into from
Jul 5, 2023
Merged

Fixes for run image extension #1134

merged 10 commits into from
Jul 5, 2023

Conversation

natalieparellano
Copy link
Member

@natalieparellano natalieparellano commented Jun 28, 2023

  • When pulling remote image data during restore, fail if the remote image is not found
  • When validating dockerfiles during generate, set extend to true if there are any instructions (vs more than one instruction)
  • Update matching logic when considering if two image names are equivalent to ignore the digest portion of the reference if present (for the purpose of selecting data from run.toml to add to the lifecycle metadata label during export i.e., “run image for rebase”)
  • During export, continue to use run image identifier (which could be a digest reference or daemon image ID) as the run image reference instead of falling back to image name when exporting to a daemon
  • When finding the run image info during export, use the run image "image" (name) in analyzed.toml as the search key, because the run image "reference" could be a daemon image ID or include the digest, which isn't helpful when retrieving image names that are supposed to float

@natalieparellano
Copy link
Member Author

Will undraft once tests are added

@natalieparellano natalieparellano force-pushed the fix/extensions branch 2 times, most recently from 9fd794a to fdf2f9f Compare June 30, 2023 14:26
@natalieparellano
Copy link
Member Author

First fix: pack v0.30.0-pre2 has a bug where registry credentials for the run image are not provided to the restorer, we can see the failure here with broken pack and fixed lifecycle (this branch):

     |         ===> RESTORING
     |         Running the 'restorer' on OS 'linux' with:
     |         Container Settings:
     |           Args: '/cnb/lifecycle/restorer -cache-dir /cache -log-level debug'
     |           System Envs: 'CNB_USER_ID=2222 CNB_GROUP_ID=3333 CNB_PLATFORM_API=0.12'
     |           Image: 'index.docker.io/library/lifecycle:fdf2f9f8'
     |           User: 'root'
     |           Labels: 'map[author:pack]'
     |         Host Settings:
     |           Binds: 'pack-cache-some-org_vvpmfybuie_latest-bff67ad6bc90.build:/cache pack-cache-some-org_vvpmfybuie_latest-bff67ad6bc90.kaniko:/kaniko pack-layers-wrvbsrdokl:/layers pack-app-luykxtohnj:/workspace'
     |           Network Mode: 'host'
     |         [restorer] Starting restorer...
     |         [restorer] Parsing inputs...
     |         [restorer] Ensuring privileges...
     |         [restorer] Executing command...
     |         [restorer] Pulling run image metadata for localhost:55012/pack-test/run...
     |         [restorer] ERROR: failed to pull run image: failed to get remote image
     |         ERROR: failed to build: executing lifecycle: failed with status code: 1

With fixed pack (buildpacks/pack#1815) and fixed lifecycle:

     |         ===> RESTORING
     |         Running the 'restorer' on OS 'linux' with:
     |         Container Settings:
     |           Args: '/cnb/lifecycle/restorer -cache-dir /cache -log-level debug'
     |           System Envs: 'CNB_USER_ID=2222 CNB_GROUP_ID=3333 CNB_REGISTRY_AUTH=<redacted> CNB_PLATFORM_API=0.12'
     |           Image: 'index.docker.io/library/lifecycle:fdf2f9f8'
     |           User: 'root'
     |           Labels: 'map[author:pack]'
     |         Host Settings:
     |           Binds: 'pack-cache-some-org_swikudtwom_latest-7835b39bb382.build:/cache pack-cache-some-org_swikudtwom_latest-7835b39bb382.kaniko:/kaniko pack-layers-vrugmvjkcd:/layers pack-app-sxgvmonswt:/workspace'
     |           Network Mode: 'host'
     |         [restorer] Starting restorer...
     |         [restorer] Parsing inputs...
     |         [restorer] Ensuring privileges...
     |         [restorer] Executing command...
     |         [restorer] Pulling run image metadata for localhost:55013/pack-test/run...
     |         [restorer] Saving image metadata to /kaniko/cache/base/sha256:9ea9f8ce440b399eecd28af397e493e52b96bf87c2d5b04b048c2ca3261789aa...
     |         [restorer] Updating run image info in analyzed metadata...
     |         [restorer] Run image info in analyzed metadata was: 
     |         [restorer] {"Reference":"10eab44d6000fc0cd8f6651c4665c509815eddfea8f12d4659be0d7e292e3131","Image":"localhost:55013/pack-test/run","Extend":true,"target":{"os":"linux","arch":"amd64"}}
     |         [restorer] Run image info in analyzed metadata is: 
     |         [restorer] {"Reference":"localhost:55013/pack-test/run@sha256:9ea9f8ce440b399eecd28af397e493e52b96bf87c2d5b04b048c2ca3261789aa","Image":"localhost:55013/pack-test/run","Extend":true,"target":{"os":"linux","arch":"amd64"}}

Signed-off-by: Natalie Arellano <narellano@vmware.com>
…ructions (vs more than one instruction)

Signed-off-by: Natalie Arellano <narellano@vmware.com>
…ent to ignore the digest portion of the reference if present (for the purpose of selecting data from run.toml to add to the lifecycle metadata label i.e., “run image for rebase”)

Signed-off-by: Natalie Arellano <narellano@vmware.com>
Don't print `%!s(<nil>)` if nil is provided to the "parse maybe" function

Signed-off-by: Natalie Arellano <narellano@vmware.com>
…a digest reference or daemon image ID)

instead of falling back to image name when exporting to a daemon.

Previously, the digest reference was incorrect which caused the daemon not to find the image.
But when provided a correct digest reference the daemon can still find it.

Signed-off-by: Natalie Arellano <narellano@vmware.com>
…port

When determining if a provided reference is found in existing metadata, remove its digest -
except when setting the new run image "image" in analyzed.toml,
because we should always respect what the extension author wrote.

Signed-off-by: Natalie Arellano <narellano@vmware.com>
… (name)

in analyzed.toml as the search key, because the run image "reference" could be a daemon image ID
or include the digest, which isn't helpful when retrieving image names that are supposed to float.

Signed-off-by: Natalie Arellano <narellano@vmware.com>
Signed-off-by: Natalie Arellano <narellano@vmware.com>
var (
remoteRunImage imgutil.Image
)
runImageName := analyzedMD.RunImageImage() // FIXME: if we have a digest reference available in `Reference` (e.g., in the non-daemon case) we should use it
Copy link
Contributor

Choose a reason for hiding this comment

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

just verifying you still want this FIXME

Copy link
Member Author

Choose a reason for hiding this comment

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

This seems to be an edge case and not super important to fix right now

{
condition: "has an implicit tag and has a digest",
provided: "some.registry/some-library/some-repo@sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
does: "adds an explicit tag and removes the digest",
Copy link
Contributor

Choose a reason for hiding this comment

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

it's surprising to me that this is the desired behavior?

platform/run_image.go Outdated Show resolved Hide resolved
if err = files.DecodeBuildMetadata(launch.GetMetadataFilePath(inputs.LayersDir), inputs.PlatformAPI, buildMD); err != nil {
return files.RunImageForExport{}, err
}
if len(buildMD.Extensions) > 0 { // FIXME: try to know for sure if extensions were used to switch the run image
Copy link
Contributor

Choose a reason for hiding this comment

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

how could you know for sure?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not for sure without some spec changes... but I would rather tackle this in tandem with buildpacks/rfcs#285

…not found

when we are only updating the reference and target data in analyzed.toml

Signed-off-by: Natalie Arellano <narellano@vmware.com>
Signed-off-by: Natalie Arellano <narellano@vmware.com>
@natalieparellano natalieparellano added this to the lifecycle 0.17.0 milestone Jul 5, 2023
@natalieparellano natalieparellano merged commit 84a94d5 into main Jul 5, 2023
7 checks passed
@natalieparellano natalieparellano deleted the fix/extensions branch July 5, 2023 20:23
dlion pushed a commit to dlion/lifecycle that referenced this pull request Jul 7, 2023
* When pulling remote image data, fail if the remote image is not found

Signed-off-by: Natalie Arellano <narellano@vmware.com>

* When validating dockerfiles, set extend to true if there are any instructions (vs more than one instruction)

Signed-off-by: Natalie Arellano <narellano@vmware.com>

* Update matching logic when considering if two image names are equivalent to ignore the digest portion of the reference if present (for the purpose of selecting data from run.toml to add to the lifecycle metadata label i.e., “run image for rebase”)

Signed-off-by: Natalie Arellano <narellano@vmware.com>

* Comments and cleanup

Don't print `%!s(<nil>)` if nil is provided to the "parse maybe" function

Signed-off-by: Natalie Arellano <narellano@vmware.com>

* When exporting, continue to use run image identifier (which could be a digest reference or daemon image ID)
instead of falling back to image name when exporting to a daemon.

Previously, the digest reference was incorrect which caused the daemon not to find the image.
But when provided a correct digest reference the daemon can still find it.

Signed-off-by: Natalie Arellano <narellano@vmware.com>

* Add Contains method to structs that hold run image information for export

When determining if a provided reference is found in existing metadata, remove its digest -
except when setting the new run image "image" in analyzed.toml,
because we should always respect what the extension author wrote.

Signed-off-by: Natalie Arellano <narellano@vmware.com>

* When finding the run image info for export, use the run image "image" (name)
in analyzed.toml as the search key, because the run image "reference" could be a daemon image ID
or include the digest, which isn't helpful when retrieving image names that are supposed to float.

Signed-off-by: Natalie Arellano <narellano@vmware.com>

* Fix detector acceptance and add more logging

Signed-off-by: Natalie Arellano <narellano@vmware.com>

* Fix: use "image" instead of "reference" and also guard against image not found
when we are only updating the reference and target data in analyzed.toml

Signed-off-by: Natalie Arellano <narellano@vmware.com>

* Add comment

Signed-off-by: Natalie Arellano <narellano@vmware.com>

---------

Signed-off-by: Natalie Arellano <narellano@vmware.com>
dlion pushed a commit to dlion/lifecycle that referenced this pull request Jul 20, 2023
* When pulling remote image data, fail if the remote image is not found

Signed-off-by: Natalie Arellano <narellano@vmware.com>

* When validating dockerfiles, set extend to true if there are any instructions (vs more than one instruction)

Signed-off-by: Natalie Arellano <narellano@vmware.com>

* Update matching logic when considering if two image names are equivalent to ignore the digest portion of the reference if present (for the purpose of selecting data from run.toml to add to the lifecycle metadata label i.e., “run image for rebase”)

Signed-off-by: Natalie Arellano <narellano@vmware.com>

* Comments and cleanup

Don't print `%!s(<nil>)` if nil is provided to the "parse maybe" function

Signed-off-by: Natalie Arellano <narellano@vmware.com>

* When exporting, continue to use run image identifier (which could be a digest reference or daemon image ID)
instead of falling back to image name when exporting to a daemon.

Previously, the digest reference was incorrect which caused the daemon not to find the image.
But when provided a correct digest reference the daemon can still find it.

Signed-off-by: Natalie Arellano <narellano@vmware.com>

* Add Contains method to structs that hold run image information for export

When determining if a provided reference is found in existing metadata, remove its digest -
except when setting the new run image "image" in analyzed.toml,
because we should always respect what the extension author wrote.

Signed-off-by: Natalie Arellano <narellano@vmware.com>

* When finding the run image info for export, use the run image "image" (name)
in analyzed.toml as the search key, because the run image "reference" could be a daemon image ID
or include the digest, which isn't helpful when retrieving image names that are supposed to float.

Signed-off-by: Natalie Arellano <narellano@vmware.com>

* Fix detector acceptance and add more logging

Signed-off-by: Natalie Arellano <narellano@vmware.com>

* Fix: use "image" instead of "reference" and also guard against image not found
when we are only updating the reference and target data in analyzed.toml

Signed-off-by: Natalie Arellano <narellano@vmware.com>

* Add comment

Signed-off-by: Natalie Arellano <narellano@vmware.com>

---------

Signed-off-by: Natalie Arellano <narellano@vmware.com>
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.

None yet

2 participants