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

fix: Fix offline build errors in CVE feed #45016

Closed

Conversation

sergeyshevch
Copy link
Member

@sergeyshevch sergeyshevch commented Feb 4, 2024

Hello! This PR addresses issue #44223. I added checks for nil in getJson shortcode usage and now the website can be built without internet access if all required images already exist on the machine.

How to check:

  • run make container-serve locally
  • wait until build will be completed and stop it (you will pull all required images)
  • disable internet access on your machine
  • run make container-serve again. It should be completed with warnings about CVE feed missing

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Feb 4, 2024
@k8s-ci-robot k8s-ci-robot added the sig/docs Categorizes an issue or PR as relevant to SIG Docs. label Feb 4, 2024
Copy link

netlify bot commented Feb 4, 2024

Pull request preview available for checking

Built without sensitive environment variables

Name Link
🔨 Latest commit 58455df
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-io-main-staging/deploys/65f9eb2331b92f00089bce10
😎 Deploy Preview https://deploy-preview-45016--kubernetes-io-main-staging.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@sftim
Copy link
Contributor

sftim commented Feb 4, 2024

/area web-development

@k8s-ci-robot k8s-ci-robot added the area/web-development Issues or PRs related to the kubernetes.io's infrastructure, design, or build processes label Feb 4, 2024
sftim
sftim previously requested changes Feb 4, 2024
Copy link
Contributor

@sftim sftim left a comment

Choose a reason for hiding this comment

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

Thanks.

One important thing to change: for production builds, let's make sure we never skip building the CVE feed.

layouts/_default/cve-feed.rss.xml Outdated Show resolved Hide resolved
layouts/shortcodes/cve-feed.html Outdated Show resolved Hide resolved
@sergeyshevch
Copy link
Member Author

@sftim Thanks for your commits. I applied suggested changes

@sftim sftim dismissed their stale review February 14, 2024 00:13

Review was stale

hugo.toml Show resolved Hide resolved
@sftim
Copy link
Contributor

sftim commented Feb 14, 2024

This helps with #42162

Copy link
Member

@dipesh-rawat dipesh-rawat left a comment

Choose a reason for hiding this comment

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

The changes look good based on my testing. However, it's important to make similar changes in release-binaries.htmland cve-feed.json, as highlighted in the earlier review feedback (here).

{{ if ne $feed.version "https://jsonfeed.org/version/1.1" }}
{{ warnf "CVE feed shortcode. KEP-3203: CVE feed does not comply with JSON feed v1.1." }}
{{ end }}
<table class="security-cves">
<!-- Handle case if CVE feed is not available. For example for offline build -->
{{ if ne $feed nil }}
Copy link
Member

Choose a reason for hiding this comment

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

Optional improvement: Instead of just displaying an empty table with headers, we could enhance the user experience by showing a helpful message, perhaps in a note, indicating that the offline preview does not support the CVE Feed.

Copy link
Contributor

Choose a reason for hiding this comment

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

There is another way.

If we change the fetch to use https://gohugo.io/functions/resources/getremote/, then we can attempt to fetch offline and warn at build time. And, yes, we can substitute something in.

For a production build, we should error out instead of warning.

Copy link
Member Author

Choose a reason for hiding this comment

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

User will receive a warning message in build log. I guess that build should works offline if some of resources are unavailable.

Yes we won't display some content that require remote files but other content will be ok and editable

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Mar 19, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign reylejano for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sergeyshevch
Copy link
Member Author

I rebased this PR on actual main and addressed all comments above

@@ -1,4 +1,11 @@
{{ $feed := getJSON .Site.Params.cveFeedBucket -}}
Copy link
Contributor

Choose a reason for hiding this comment

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

Really, we should switch this to use transform.GetRemote; see https://gohugo.io/functions/resources/getremote/#remote-data for an example that includes error handling. Then I don't think we need to edit the hugo.toml to ignore error-remote-getjson.

(If we switch, we can still change the error handling based on which environment we're in)

Copy link
Member

@dipesh-rawat dipesh-rawat Mar 21, 2024

Choose a reason for hiding this comment

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

There's already an existing PR #45375 that focuses on enhancing data retrieval by replacing 'getJSON' with 'transform.Unmarshal'. Perhaps we could consider combining these changes into a single PR.

(EDIT: I have updated the PR-45375 to include the error handling based on environment.)

@@ -1,9 +1,19 @@
{{ $feed := getJSON .Site.Params.cveFeedBucket }}
Copy link
Contributor

Choose a reason for hiding this comment

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

Really, we should switch this to use transform.GetRemote; see https://gohugo.io/functions/resources/getremote/#remote-data for an example that includes error handling. Then I don't think we need to edit the hugo.toml to ignore error-remote-getjson.

(If we switch, we can still change the error handling based on which environment we're in)

@@ -1,5 +1,13 @@
<!-- Fetch release_binaries.json from kubernetes-sigs/downloadkubernetes to render in table -->
{{ $response := getJSON "https://raw.githubusercontent.com/kubernetes-sigs/downloadkubernetes/master/dist/release_binaries.json" }}
Copy link
Contributor

Choose a reason for hiding this comment

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

Really, we should switch this to use transform.GetRemote; see https://gohugo.io/functions/resources/getremote/#remote-data for an example that includes error handling. Then I don't think we need to edit the hugo.toml to ignore error-remote-getjson.

(If we switch, we can still change the error handling based on which environment we're in)

@sftim
Copy link
Contributor

sftim commented Mar 20, 2024

I'd prefer to see this PR switch to using transform.GetRemote, leaving the existing hugo.toml intact.

@sergeyshevch
Copy link
Member Author

sergeyshevch commented Mar 25, 2024

@dipesh-rawat Looks like that #45375 fully include this PR fix. Maybe we should close this one then? I'm totally ok with that

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 25, 2024
@k8s-ci-robot
Copy link
Contributor

PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/web-development Issues or PRs related to the kubernetes.io's infrastructure, design, or build processes cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. sig/docs Categorizes an issue or PR as relevant to SIG Docs. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants