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

feat: SAVE IMAGE --without-earthly-labels #4084

Merged
merged 4 commits into from May 6, 2024

Conversation

3manuek
Copy link
Contributor

@3manuek 3manuek commented May 2, 2024

This commit adds the --without-earthly-labels for the SAVE IMAGE instruction to not modify the digest of the final artifact if none of its contents changes. Enabled --allow-without-earthly-labels feature.

Certain custom registries may require strict checking of the image contents, so this option disables build information.

This commit adds the `--disable-earthly-labels` for the SAVE IMAGE
instruction for not impacting on the digest of the final artifact.

Certain custom registries may require strict checking of the image
contents, so this option disables build information.
@3manuek 3manuek requested a review from a team as a code owner May 2, 2024 20:20
@CLAassistant
Copy link

CLAassistant commented May 2, 2024

CLA assistant check
All committers have signed the CLA.

myimagewithlabels:
FROM scratch
COPY file /
SAVE IMAGE myimagewithlabels:test
Copy link
Collaborator

Choose a reason for hiding this comment

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

this will fail the +lint target; please make sure all files end with a newline.

Insecure bool `long:"insecure" description:"Use unencrypted connection for the push"`
NoManifestList bool `long:"no-manifest-list" description:"Do not include a manifest list (specifying the platform) in the creation of the image"`
CacheFrom []string `long:"cache-from" description:"Declare additional cache import as a Docker tag"`
DisableEarthlyLabels bool `long:"disable-earthly-labels" description:"Disable build information dev.earthly labels to reduce the chance of changing images digsest."`
Copy link
Contributor

Choose a reason for hiding this comment

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

a little bit of a nit pick might be more consistent with other flags to call this :
no-earthly-labels maybe?
CC @alexcb

Copy link
Collaborator

Choose a reason for hiding this comment

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

That's a good suggestion, another idea is --without-earthly-labels.

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 like both, I would probably go with the shortest.

Copy link
Contributor Author

@3manuek 3manuek May 3, 2024

Choose a reason for hiding this comment

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

The problem with --no-earthly-labels is that the feature attribute would be AllowNoEarthlyLabels, which is kinda confusing. without would probably don't have this issue, if we want to keep the consistency between feature and command flags.

@@ -63,4 +63,27 @@ echo "=== ($LINENO): Test New Behaviour referencing remote via build ==="
"$frontend" inspect myimage:buildtest >/dev/null
"$frontend" inspect earthly-test-saveimage:test >/dev/null

echo "=== ($LINENO): Test Disable Earthly Labels ==="
Copy link
Collaborator

@alexcb alexcb May 2, 2024

Choose a reason for hiding this comment

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

Instead of having this test here, can you do it in an Earthfile instead?

Perhaps something along the lines of:

$ cat ./tests/with-docker-validate-labels/Earthfile 
VERSION --allow-disable-earthly-labels 0.8 0.8

ARG --global DIND_IMAGE=earthly/dind:alpine-3.19-docker-25.0.5-r0
FROM $DIND_IMAGE

all:
    BUILD +test-with-labels
    BUILD +test-without-labels

myimage-with-labels:
    FROM alpine
    COPY file /
    SAVE IMAGE myimage:test

myimage-without-labels:
    FROM alpine
    COPY file /
    SAVE IMAGE myimage:test

test-with-labels:
    WITH DOCKER --load=+myimage-with-labels
        RUN docker inspect myimage:test | jq -r '.[].Config.Labels' # ....
    END

test-without-labels:
    ...

then under tests/Earthfile, you can call it by adding it to

ga-no-qemu-group12:
    ...
    BUILD --pass-args ./with-docker-validate-labels+all

@@ -74,6 +74,7 @@ type Features struct {
WildcardCopy bool `long:"wildcard-copy" description:"allow for the expansion of wildcard (glob) paths for COPY commands"`
RawOutput bool `long:"raw-output" description:"allow for --raw-output on RUN commands"`
GitAuthorEmailNameArgs bool `long:"git-author-email-name-args" description:"includes EARTHLY_GIT_AUTHOR_EMAIL and EARTHLY_GIT_AUTHOR_NAME builtin ARGs"`
AllowDisableEarthlyLabels bool `long:"allow-disable-earthly-labels" description:"Allow the usage of --disable-earthly-labels in SAVE IMAGE"`
Copy link
Collaborator

Choose a reason for hiding this comment

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

I like that you didn't call it --enable-disable-earthly-labels, the --allow-* prefix was a good call 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we change the SAVE IMAGE to --no-earthly-labels, the feature attribute might need to be changed to AllowNoEarthlyLabels. The "AllowNo" prefix sounds confusing, probably it makes more sense AllowWithoutEarhtlyLabels.

err = i.converter.Label(ctx, labels)
if err != nil {
return i.wrapError(err, cmd.SourceLocation, "failed to create dev.earthly.* labels during SAVE IMAGE")
if !opts.DisableEarthlyLabels {
Copy link
Collaborator

@alexcb alexcb May 2, 2024

Choose a reason for hiding this comment

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

there should be a check to make sure the AllowDisableEarthlyLabels feature was enabled.

e.g.

if opts.DisableEarthlyLabels {
	if !i.converter.ftrs.AllowDisableEarthlyLabels {
		return i.errorf(cmd.SourceLocation, "the SAVE IMAGE --disable-earthly-labels flag must be enabled with the VERSION --allow-disable-earthly-labels feature flag.")
	}
	// deliberately don't add any labels (i.e. do nothing here)
} else {
...
}

Copy link
Collaborator

@alexcb alexcb left a comment

Choose a reason for hiding this comment

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

thanks for the submission, just a few small requests.

- Renamed feature to --allow-without-eartly-labels
- Tests corrected and dockerized
@3manuek
Copy link
Contributor Author

3manuek commented May 3, 2024

New commit with changes in the review pushed. cc /@alexcb
I used earthly/dind:ubuntu-23.04-docker-25.0.2-1 due that other tests were using this version, let me know if this should be updated.

@3manuek 3manuek requested review from alexcb and idodod May 3, 2024 12:38
earthfile2llb/interpreter.go Outdated Show resolved Hide resolved
@alexcb alexcb added the approved-for-tests Commnity PRs that the tests can run on label May 6, 2024
Co-authored-by: Alex Couture-Beil <[email protected]>
@3manuek 3manuek requested a review from alexcb May 6, 2024 19:27
@alexcb alexcb added approved-for-tests Commnity PRs that the tests can run on and removed approved-for-tests Commnity PRs that the tests can run on labels May 6, 2024
Copy link
Collaborator

@alexcb alexcb left a comment

Choose a reason for hiding this comment

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

Thanks for the submission!

@alexcb alexcb changed the title [wip][feat]: Add --disable-earthly-labels in SAVE IMAGE feat: SAVE IMAGE --without-earthly-labels May 6, 2024
@alexcb alexcb merged commit eafa608 into earthly:main May 6, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved-for-tests Commnity PRs that the tests can run on
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

4 participants