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

dockerfile: generate lint rules documentation #4990

Merged
merged 6 commits into from
Jun 6, 2024

Conversation

crazy-max
Copy link
Member

@crazy-max crazy-max commented Jun 4, 2024

relates to #4823 and #4980

Generates lint rules documentation in ./frontend/dockerfile/docs/rules that can then be used on https://github.com/docker/docs through vendoring with Hugo.

Keep in draft as some markdown files are incomplete.

Comment on lines 73 to 76
if errors.Is(err, os.ErrNotExist) {
log.Printf("WARNING: Markdown file %q not found for %s\n", mdfilename, rule.Name)
return false, nil
}
Copy link
Member Author

Choose a reason for hiding this comment

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

It needs a markdown file that contains examples for the rule. Atm we skip docs generation if the markdown file is not found but I think it should be required and fails if not found (cc @dvdksn)

Copy link
Member Author

@crazy-max crazy-max Jun 4, 2024

Choose a reason for hiding this comment

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

Updated to make validation fails if markdown files are missing.

Copy link
Member Author

Choose a reason for hiding this comment

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

I just have a markdown file for this rule atm but we should have one for each of them.

@dvdksn Feel free to push to my branch other ones.

description: {{.Rule.Description}}
---

{{.Content}}
Copy link
Collaborator

@dvdksn dvdksn Jun 4, 2024

Choose a reason for hiding this comment

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

here's a far out ask. Is there any way we can generate the sample error using the Format field? https://github.com/moby/buildkit/blob/master/frontend/dockerfile/linter/linter.go#L79

Just thinking if there's a way to make sure the sample error in the doc and the actual error look the same. If generating the sample error isn't easily doable, maybe we could update the tests to check that generated errors have the same format as what's in the doc.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we could but where to put Format in the template and what layout would this have?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if we could put the templating logic in the Markdown files directly. For example, consider frontend/dockerfile/linter/docs/RuleName.md

---
title: {{ .Name }}
description: {{ .Description }}
---

Example warning:

{{ .Format "foo" "bar" }}

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod...

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes sounds good

Copy link
Collaborator

Choose a reason for hiding this comment

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

This file is outdated, I created it a while ago. Would be nice to generate it too (I think we need an index for all of these rules)

Copy link
Member Author

@crazy-max crazy-max Jun 5, 2024

Choose a reason for hiding this comment

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

@crazy-max
Copy link
Member Author

Picked changes from @dvdksn branch to include additional markdown files: crazy-max#18

@crazy-max crazy-max force-pushed the docs-dockerfile-gen branch 2 times, most recently from dd2e9f4 to 5b63ac6 Compare June 5, 2024 12:34
@crazy-max crazy-max added this to the v0.14.0 milestone Jun 5, 2024
@crazy-max

This comment was marked as resolved.

@crazy-max crazy-max force-pushed the docs-dockerfile-gen branch 3 times, most recently from d844815 to f6c970b Compare June 6, 2024 08:13
Copy link
Member Author

Choose a reason for hiding this comment

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

Missing content

Copy link
Member Author

Choose a reason for hiding this comment

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

As discussed it's fine to merge even if content is empty. We can update it later. We just want URL to be set.

Copy link
Member Author

@crazy-max crazy-max left a comment

Choose a reason for hiding this comment

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

@colinhemmings PTAL on rule's description related to #4980 (comment)

@crazy-max

This comment was marked as resolved.

@crazy-max crazy-max marked this pull request as ready for review June 6, 2024 16:06
@thompson-shaun thompson-shaun force-pushed the docs-dockerfile-gen branch 2 times, most recently from cc631ae to 7c85e86 Compare June 6, 2024 18:45
URL: "https://docs.docker.com/go/dockerfile/rule/reserved-stage-name/",
Format: func(reservedStageName string) string {
return fmt.Sprintf("Stage name should not use the same name as reserved stage %q", reservedStageName)
},
}
RuleJSONArgsRecommended = LinterRule[func(instructionName string) string]{
Name: "JSONArgsRecommended",
Description: "JSON arguments recommended for ENTRYPOINT/CMD to prevent unintended behavior related to OS signals",
Description: "JSON arguments recommended for ENTRYPOINT/CMD to prevent unintended behavior related to OS signals, unless using a custom shell",
Copy link
Member

@tonistiigi tonistiigi Jun 6, 2024

Choose a reason for hiding this comment

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

nit: "unless using a custom shell" is not needed here. If the user knows what "custom shell" is then they will not see this warning. Otherwise it will just confuse them.

Explaining the "custom shell" behavior in the linked URL is good.

Dockerfile Outdated
@@ -378,7 +378,7 @@ exec dlv exec /usr/bin/buildkitd \\
--continue \\
-- "\$@"
EOF
ENV DELVE_PORT 5000
ENV DELVE_PORT=5000
Copy link
Member

Choose a reason for hiding this comment

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

nit: these changes could be in another PR

Copy link
Collaborator

Choose a reason for hiding this comment

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

💯 -- sorry about that, those were driving me nuts

@thompson-shaun thompson-shaun force-pushed the docs-dockerfile-gen branch 3 times, most recently from 053d42c to 3b4139b Compare June 6, 2024 21:47
@@ -0,0 +1,26 @@
---
title: UndefinedArgInFrom
Copy link
Member

Choose a reason for hiding this comment

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

These are for follow-up.

Copy link
Member Author

@crazy-max crazy-max left a comment

Choose a reason for hiding this comment

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

Needs to align generated docs: https://github.com/moby/buildkit/actions/runs/9408268148/job/25915879498?pr=4990#step:5:319

#20 [validate 1/1] RUN --mount=target=/context   --mount=target=.,type=tmpfs <<EOT (set -e...)
#20 0.814 ERROR: Dockerfile docs result differs. Please update with "make docs-dockerfile"
#20 0.842  M frontend/dockerfile/docs/rules/_index.md

crazy-max and others added 6 commits June 6, 2024 15:11
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com>
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
Signed-off-by: Shaun Thompson <shaun.thompson@docker.com>
@tonistiigi tonistiigi merged commit aebcc1f into moby:master Jun 6, 2024
75 checks passed
@crazy-max crazy-max deleted the docs-dockerfile-gen branch June 7, 2024 08:27
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

4 participants