-
Notifications
You must be signed in to change notification settings - Fork 147
SBOM: add a OperatingSystem package to each apk SBOM #2016
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0ba45d4
SBOM: add an OperatingSystem package to each apk SBOM
sil2100 339c09a
Add support for the docker runner.
sil2100 74c4a48
Make lint happy.
sil2100 43489a8
Merge branch 'main' of github.com:chainguard-dev/melange into sbom-os
sil2100 b319f90
Use ParseReleaseData from apko
sil2100 b09a438
Don't fail on missing os-release, as this might be a valid situation.
sil2100 0acf9c3
Forgot to include the goldenfiles testdata updates.
sil2100 f4d2d07
Fix the docker runner implementation as flush was not always happening.
sil2100 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright 2025 Chainguard, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package config | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"io" | ||
"strings" | ||
|
||
apko_build "chainguard.dev/apko/pkg/build" | ||
) | ||
|
||
// This is a copy of the ReleaseData related code from apko's pkg/build/sbom.go | ||
|
||
// ParseReleaseData parses the information from /etc/os-release | ||
// | ||
// If no os-release file is found, it returns a Data struct with ID set to "unknown". | ||
// TODO: this should best be imported from apko, but right now this function is not | ||
// exported and not ready to be used outside of apko. | ||
func ParseReleaseData(osRelease io.Reader) (*apko_build.ReleaseData, error) { | ||
scanner := bufio.NewScanner(osRelease) | ||
|
||
kv := map[string]string{} | ||
for scanner.Scan() { | ||
line := scanner.Text() | ||
if line == "" { | ||
continue | ||
} | ||
|
||
if strings.HasPrefix(line, "#") { | ||
continue | ||
} | ||
|
||
before, after, ok := strings.Cut(line, "=") | ||
if !ok { | ||
return nil, fmt.Errorf("invalid os-release line: %q", line) | ||
} | ||
|
||
kv[before] = strings.Trim(after, "\"") | ||
} | ||
|
||
if err := scanner.Err(); err != nil { | ||
return nil, fmt.Errorf("reading os-release: %w", err) | ||
} | ||
|
||
return &apko_build.ReleaseData{ | ||
ID: kv["ID"], | ||
Name: kv["NAME"], | ||
PrettyName: kv["PRETTY_NAME"], | ||
VersionID: kv["VERSION_ID"], | ||
}, nil | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.