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

add sboms #144

Merged
merged 34 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
b8e84fe
wip, not working but snapshot
aerickson Jul 17, 2024
59366d8
wip, getting close
aerickson Jul 17, 2024
075370e
cleanup, todo
aerickson Jul 17, 2024
8a44e8d
add missing file, fix via rename, reorder postprocessor addition
aerickson Jul 17, 2024
75fcbc2
only set dirty if tracked files have changes
aerickson Jul 17, 2024
f52fdf3
comment cleanup
aerickson Jul 17, 2024
00bfd10
sbom mover creates dest if not created already
aerickson Jul 17, 2024
413794e
add readme in sboms dir
aerickson Jul 17, 2024
81d30d2
add sbom script, fix path to script
aerickson Jul 17, 2024
9914148
bug fix
aerickson Jul 17, 2024
2bfefdb
fixes
aerickson Jul 17, 2024
2b230c3
add -m option to mover
aerickson Jul 18, 2024
4a3315f
tweak how mover script operates since args can't be given
aerickson Jul 18, 2024
b7db2cc
remove file from changge
aerickson Jul 18, 2024
a2d5363
postprocessor: don't explode if no sbom present/generated
aerickson Jul 18, 2024
d3117f4
add sboms gitignore
aerickson Jul 18, 2024
3d4e028
add ubuntu-sbom to all modern builders
aerickson Jul 18, 2024
bd85a42
bug fix
aerickson Jul 18, 2024
ef440a0
pytest fixing
aerickson Jul 18, 2024
3f3e7c6
testing image doesn't use env file for tc version
aerickson Jul 18, 2024
3f0c06f
update sbom tool to version that includes hyperlink
aerickson Jul 18, 2024
0eadc78
add v101 of sbom tool
aerickson Jul 18, 2024
6014ed1
v2 is working on monopacker-testing-image
aerickson Jul 25, 2024
5d25a63
move rest of configs to v2
aerickson Jul 25, 2024
c3daeaf
commented-out code cleanup
aerickson Jul 25, 2024
4d9a540
add pytest-watch to --dev
aerickson Jul 25, 2024
ebedbb8
add test for sboms
aerickson Jul 25, 2024
015b4e8
improve test helper
aerickson Jul 25, 2024
a2b70e4
test fixing
aerickson Jul 25, 2024
7b76303
add pytest-cov and generate coverage in the github actions
aerickson Jul 25, 2024
ea2848f
coverage goes to terminal
aerickson Jul 25, 2024
a1b7b65
poetry update
aerickson Jul 25, 2024
db34121
rename barebones tc script
aerickson Jul 25, 2024
03e897f
templating readme: document new features
aerickson Jul 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ jobs:
- name: Run tests
run: |
poetry run python -m pytest -sxv
- name: Generate coverage report
run: |
poetry run pytest -vv --cov=monopacker --cov-report=term-missing
# poetry-update-check:
# runs-on: ubuntu-latest
# steps:
Expand Down
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ packer-artifacts.json
output-vagrant*

### Secrets ###
real_secrets.yaml
**/*secret*.yaml
**/*secret*

# Python cache
*.pyc
Expand Down
2 changes: 2 additions & 0 deletions SBOMs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.md
!README.md
5 changes: 5 additions & 0 deletions SBOMs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# monopacker SBOMs

## overview

TBD
27 changes: 27 additions & 0 deletions TEMPLATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,27 @@ simply create a `.jinja2` file with the name of your choice under `./template/bu
Ensure that your builder template has a `name` key set to `{{builder.vars.name}}`, as this is how `monopacker` templating
maps `builders` to `provisioners` in the Packer template.

## Rebooting while building

Monopacker has support for handling restarts during the build process.

If a script's name includes 'reboot', Monopacker will add a pause after the step to ensure that the host is back up before continuing.

## Software Bill of Materials (SBOMs)

Monopacker has support for generating SBOMs.

SBOM generation is enabled by adding a variable file to your builder that sets `monopacker_generate_sbom` to `true`. Here's an example variable file:

```
---
monopacker_generate_sbom: true
# defaults to ""
monopacker_sbom_command_args: "-b $MONOPACKER_BUILDER_NAME -c $MONOPACKER_GIT_SHA"
# default vaule is "monopacker_ubuntu_sbom.py"
# monoopacker_sbom_script: monopacker_ubuntu_sbom.py
```

# FAQ

## I'm getting `did not find expected key` in my template
Expand All @@ -174,3 +195,9 @@ A number of things could be going wrong here.
Ensure that the builder template properly
references all variables as being namespaced under `builder.vars` and that your `builder_var_files`
and `builder_vars` do _not_ have any namespacing. See above for a more thorough description.

## What's the difference between variables and environment variaboles?

Variables are set only in Packer's context.

Environment variables are set when scripts run on the target host.
1 change: 1 addition & 0 deletions builders/gw_fxci_gcp_l1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ builder_var_files:
- default_gcp
- googlecompute_jammy
- ubuntu_amd64
- monopacker_generate_sbom

script_directories:
- ubuntu-jammy-from-community
Expand Down
1 change: 1 addition & 0 deletions builders/gw_fxci_gcp_l1_arm64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ builder_var_files:
- default_gcp
- googlecompute_jammy_arm64
- ubuntu_arm64
- monopacker_generate_sbom

script_directories:
- ubuntu-jammy-from-community
Expand Down
1 change: 1 addition & 0 deletions builders/gw_fxci_gcp_l1_arm64_gui.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ builder_var_files:
- googlecompute_jammy_arm64
- ubuntu_arm64
- firefoxci_loopback
- monopacker_generate_sbom

script_directories:
- ubuntu-jammy-from-community
Expand Down
1 change: 1 addition & 0 deletions builders/gw_fxci_gcp_l1_gui.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ builder_var_files:
- googlecompute_jammy
- ubuntu_amd64
- firefoxci_loopback
- monopacker_generate_sbom

script_directories:
- ubuntu-jammy-from-community
Expand Down
1 change: 1 addition & 0 deletions builders/gw_fxci_gcp_l3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ builder_var_files:
- googlecompute_jammy
- ubuntu_amd64
- firefoxci_gcp_l3
- monopacker_generate_sbom

script_directories:
- ubuntu-jammy-from-community
Expand Down
1 change: 1 addition & 0 deletions builders/gw_fxci_gcp_l3_arm64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ builder_var_files:
- googlecompute_jammy_arm64
- ubuntu_arm64
- firefoxci_gcp_l3
- monopacker_generate_sbom

script_directories:
- ubuntu-jammy-from-community
Expand Down
1 change: 1 addition & 0 deletions builders/gw_fxci_gcp_l3_arm64_gui.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ builder_var_files:
- ubuntu_arm64
- firefoxci_loopback
- firefoxci_gcp_l3
- monopacker_generate_sbom

script_directories:
- ubuntu-jammy-from-community
Expand Down
1 change: 1 addition & 0 deletions builders/gw_fxci_gcp_l3_gui.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ builder_var_files:
- ubuntu_amd64
- firefoxci_loopback
- firefoxci_gcp_l3
- monopacker_generate_sbom

script_directories:
- ubuntu-jammy-from-community
Expand Down
1 change: 1 addition & 0 deletions builders/gw_translations_gcp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ builder_var_files:
- default_linux
- translations_gcp # TODO: merge this and following?
- googlecompute_translations
- monopacker_generate_sbom

script_directories:
- ubuntu-jammy
Expand Down
13 changes: 13 additions & 0 deletions builders/monopacker-testing-image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# a barebones image used for testing monopacker
template: googlecompute
platform: linux

builder_var_files:
- default_linux
- default_gcp
- googlecompute_jammy
- ubuntu_amd64
- monopacker_generate_sbom

script_directories:
- ubuntu-tc-barebones
54 changes: 54 additions & 0 deletions monopacker/post-processors/move_sbom_to_latest_artifact_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env python3

import json
import sys
import argparse
import os
import shutil

# Set up argparse
parser = argparse.ArgumentParser(description="Move temp_sbom.md to the last build's artifact name.md")
parser.add_argument('-d', '--debug', action='store_true', help='Print what would have happened instead of performing the move')
args = parser.parse_args()

# Load the JSON data from the file in the current working directory
file_path = 'packer-artifacts.json'
with open(file_path, 'r') as file:
data = json.load(file)

# Extract the last_run_uuid
last_run_uuid = data['last_run_uuid']

# Find the matching build in the builds array
matching_build = None
for build in data['builds']:
if build['packer_run_uuid'] == last_run_uuid:
matching_build = build
break

# Handle the move operation or describe the action if in debug mode
if matching_build:
artifact_id = matching_build['artifact_id']
source_path = 'SBOMs/temp_sbom.md'
destination_dir = 'SBOMs'
destination_path = f'{destination_dir}/{artifact_id}.md'

if not os.path.exists(source_path):
print(f'File {source_path} not found.')
sys.exit(0)

if args.debug:
print(f'Would move {source_path} to {destination_path}')
else:
try:
# Create the destination directory if it doesn't exist
os.makedirs(destination_dir, exist_ok=True)
# Move the file
shutil.move(source_path, destination_path)
print(f'Moved {source_path} to {destination_path}')
except Exception as e:
print(f'An error occurred: {e}')
sys.exit(1)
else:
print('No matching build found.')
sys.exit(1)
Loading
Loading