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: refactor create stages into separate lib #2223

Merged
merged 217 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from 216 commits
Commits
Show all changes
217 commits
Select commit Hold shift + click to select a range
26e1d6d
Initial commit to split cdToBaseDir into a new creator package
Jan 11, 2024
510fa92
Merge branch 'main' into 2188-refactor-create-stages-into-separate-lib
Jan 11, 2024
f26e88f
Fix lint warnings
Jan 11, 2024
83a3cf2
Remove deprecated migrations logic from readZarfYAML
Jan 11, 2024
f8e6569
Decouple running deprecated migrations and adding package warnings fr…
Jan 11, 2024
99cb14e
Move legacy layout warning logic to runMigrations
Jan 11, 2024
b5420c0
Extract set package arch logic to new receiver method
Jan 11, 2024
80fd2ec
Revert "Extract set package arch logic to new receiver method"
Jan 12, 2024
8e9790b
Split reading zarf.yaml and setting arch apart
Jan 12, 2024
fbda210
Revert "Split reading zarf.yaml and setting arch apart"
Jan 12, 2024
cef3660
Split reading zarf.yaml and setting arch apart
Jan 12, 2024
d7b8eed
Add a Loader interface for loading package definitions on create
Jan 12, 2024
902d966
Add comments to load code to fix linter warnings
Jan 12, 2024
4e56132
Move differential functions out of create_stages.go to differential.go
Jan 12, 2024
c5e83df
Move Creator interface to packager package
Jan 12, 2024
b5d37cb
Add comments to fix linter warnings
Jan 12, 2024
47dc136
Add comments to SkeletonCreator and PackageCreator structs
Jan 12, 2024
f2b2f03
Improve comments for differential methods
Jan 12, 2024
f94c7a0
Remove redundant err != nil check
Jan 12, 2024
d84ccd4
Do some cleanup for differential code
Jan 12, 2024
ff5e3ea
Fix SkeletonCreator comment
Jan 12, 2024
c2daf04
Cleanup for consistency
Jan 12, 2024
4400e10
Remove nested interfaces to reduce unnecessary complexity
Jan 12, 2024
df8f4a7
Do not set p.arch in operations that do not need to
Jan 12, 2024
8e6e5b5
p.arch needs to be set for remove
Jan 12, 2024
460f078
Embed the Creator interface to encapsulate create logic in Packager
Jan 16, 2024
9becd35
Undo creator changes
Jan 16, 2024
bf6d4b0
Get back to clean working slate
Jan 16, 2024
f1fa5c7
Move p.cdToBaseDir to new creator package
Jan 16, 2024
0a19f3a
Create new creator package and begin moving create logic to it
Jan 17, 2024
dbe2cd4
Fix create
Jan 17, 2024
1a6503d
Cleanup Creator interface and function signatures
Jan 19, 2024
5ee5c89
Fix package templating
Jan 19, 2024
ee7440c
Merge branch 'main' into 2188-refactor-create-stages-into-separate-lib
Jan 19, 2024
9b108e9
Fix ReloadYamlTemplate
Jan 19, 2024
41cb8a8
Ensure package arch is set
Jan 22, 2024
15b283b
Use archiver/v3
Jan 22, 2024
5ccfdee
Fix component migrations on create
Jan 22, 2024
90c34cd
Fix ProcessExtensions bug
Jan 22, 2024
7a08474
Fix component migratioin warnings
Jan 22, 2024
8df5a39
Set pkg build migrations in p.output on create
Jan 22, 2024
8dddf3b
Go back to original ReloadComponentTemplatesInPackage
Jan 22, 2024
d9188f4
Remove named return parameters from LoadPackageDef
Jan 22, 2024
72e2181
creator.New() does not need to return an error
Jan 22, 2024
f33b700
Embed dependencies in Creator implementations instead of passed as pa…
Jan 22, 2024
53107fa
Fix nil pointer when instantiating creator
Jan 22, 2024
16ca3e8
Merge branch 'main' into 2188-refactor-create-stages-into-separate-lib
Jan 22, 2024
08ca541
Fix nil pointer when creating differential packages
Jan 22, 2024
1bfb467
Remove unused componentMap from fillComponentTemplate
Jan 22, 2024
f6091a7
Move actions and variables logic to separate packages
Jan 23, 2024
4b76009
Merge branch 'main' into 2188-refactor-create-stages-into-separate-lib
Jan 23, 2024
797c6da
Progress
Jan 24, 2024
bc9860f
Merge main
Jan 24, 2024
5250f34
Merge branch 'main' into 2188-refactor-create-stages-into-separate-lib
Jan 24, 2024
3381c3d
Fix generateChecksums
Jan 24, 2024
d8ab516
Merge branch 'main' into 2188-refactor-create-stages-into-separate-lib
Jan 24, 2024
9118917
Move generateChecksums to its own file
Jan 24, 2024
a9a6846
Fix package signing
Jan 24, 2024
54425bb
Remove unused index parameter from pc.addComponent
Jan 24, 2024
ab5abc5
Make processExtensions private
Jan 24, 2024
6ba4916
Do not process files from URL source in skeleton packages
Jan 24, 2024
b935015
Merge branch 'main' into 2188-refactor-create-stages-into-separate-lib
Jan 29, 2024
9fb95af
Make addSignature() a private method
Jan 29, 2024
6fb3881
Move processExtensions() from Assemble() to LoadPackageDefinition() f…
Jan 29, 2024
e0f6830
Ensure FillActiveTemplate() does not return a nil pointer
Jan 29, 2024
c6fd2a1
Move component archiving and generateChecksums logic to Ouput() for s…
Jan 29, 2024
05010a4
Use ZarfPackage struct instead of pointers in creator functions
Jan 30, 2024
03a55b4
Revert "Use ZarfPackage struct instead of pointers in creator functions"
Jan 30, 2024
825f531
Merge branch 'main' into 2188-refactor-create-stages-into-separate-lib
Jan 30, 2024
a378a84
Return warnings for diff pkgs in LoadPackageDefinition()
Jan 30, 2024
52263a9
Merge branch 'main' into 2188-refactor-create-stages-into-separate-lib
Jan 31, 2024
fb187a6
Reduce dependency on PackagerConfig in Creator implementations
Jan 31, 2024
def07e2
Move confirm action logic to a utility function
Jan 31, 2024
2524bcc
Move stage SBOM files logic to utils
Jan 31, 2024
8b945c6
Merge branch 'main' into 2188-refactor-create-stages-into-separate-lib
Jan 31, 2024
1867cea
Fix dev deploy
Feb 1, 2024
a6b3cea
Merge branch 'main' into 2188-refactor-create-stages-into-separate-lib
Feb 1, 2024
fb789d7
Remove creator.CdToBaseDir
Feb 1, 2024
f36dda8
Get cwd before cd into create dir
Feb 1, 2024
10c7bb1
Move GenerateChecksums to *layout.PackagePaths receiver
Feb 1, 2024
1768143
Delete interactive.go file in packager
Feb 1, 2024
f7ddb70
Merge branch 'main' into 2188-refactor-create-stages-into-separate-lib
Feb 1, 2024
068101a
Add comment to ComposeComponents()
Feb 2, 2024
e84dd48
Add named returns to differential functions
Feb 2, 2024
ec0dc95
Add comments to exported functions in normal.go
Feb 2, 2024
5e5cccf
Change SetBaseDirectory() to take in createOpts instead of pkgerConfig
Feb 2, 2024
b92d045
Add comments to exported functions in skeleton.go
Feb 2, 2024
bb658fc
Add comment to FillActiveTemplate()
Feb 2, 2024
db32f78
Add comment to SignPackage and ArchivePackage
Feb 2, 2024
72a3318
Add comment to StageSBOMViewFiles()
Feb 2, 2024
ee81fc4
Catch return value of getSelectedComponents in dev deploy
Feb 2, 2024
b79329c
Use wrapped error in FindImages()
Feb 2, 2024
5e1e8e2
Merge branch 'main' into 2188-refactor-create-stages-into-separate-lib
Feb 5, 2024
1b22b64
Update comment for StageSBOMViewFiles
Feb 5, 2024
90d7d7f
Update comment for StageSBOMViewFiles
Feb 5, 2024
0cbd40f
Make PackagePaths first arg in all Creator methods
Feb 5, 2024
20d435a
Move filterComponents() to components.go and delete yaml.go
Feb 5, 2024
92b7942
Move confirm action logic back to packager
Feb 6, 2024
bd9446c
Merge branch 'main' into 2188-refactor-create-stages-into-separate-lib
Feb 6, 2024
6c6935c
Assign p.cfg.Pkg to loadedPkg to populate packager before confirmActi…
Feb 6, 2024
086ec1e
Add comment to actions.Run()
Feb 6, 2024
7b97d15
Remove outdated comments from processExtensions
Feb 6, 2024
44e663a
Make Creator implementations private
Feb 6, 2024
c2978b5
Update packageCreator comment
Feb 6, 2024
6338b0d
Merge branch 'main' into 2188-refactor-create-stages-into-separate-lib
Feb 7, 2024
2502161
Move cfg.SetVariableMap functions to receiver methods on PackagerConfig
Feb 7, 2024
f0c6ccc
Move IsInitConfig() and IsSBOMAble() to receiver methods on ZarfPacka…
Feb 7, 2024
f36eeb4
Move pp.addSignature logic to pp.SignPackage
Feb 7, 2024
7c1480c
Merge branch 'main' into 2188-refactor-create-stages-into-separate-lib
Feb 7, 2024
aa5d107
Move OutputSBOMFiles() to a SBOMs receiver
Feb 7, 2024
8a02c39
Create factory methods for creator implementations rather than return…
Feb 7, 2024
2d6ea9c
Make pkg variable naming less weird and confusing
Feb 7, 2024
8d281de
Update processExtensions to work with components directly
Feb 7, 2024
0bca3e0
Change Assemble() to accept components instead of a ZarfPackage
Feb 7, 2024
0533fdd
Merge branch 'main' into 2188-refactor-create-stages-into-separate-lib
Feb 7, 2024
a1a6c46
Merge branch 'main' into 2188-refactor-create-stages-into-separate-lib
Feb 8, 2024
b642690
Refactor removeCopiesFromDifferentialPackage to work with components …
Feb 8, 2024
e958ad9
Refactor loadDifferentialData to use sources and layout to load pkg
Feb 8, 2024
79cdf01
Merge branch 'main' into 2188-refactor-create-stages-into-separate-lib
Feb 8, 2024
f182d25
Use a tmpdir and isolated layout for loading diff pkg
Feb 8, 2024
501dcdf
Remove unused PackagePaths param from loadDifferentialData()
Feb 8, 2024
75e516b
Use ZarfPackage struct rather than pointer in Creator operations
Feb 9, 2024
e2b7444
Directly assign LoadPackageDefinition warnings to p.warnings
Feb 9, 2024
dd952a9
Use a fresh ZarfPackageOptions struct rathen than embedding in Packag…
Feb 9, 2024
26e2c1f
Update src/pkg/packager/creator/skeleton.go
lucasrod16 Feb 9, 2024
5ab9da4
Apply changes from PR feedback
Feb 9, 2024
579782d
Merge branch '2188-refactor-create-stages-into-separate-lib' of https…
Feb 9, 2024
2758b2f
Move SetBaseDirectory() to a reciever on ZarfCreateOptions
Feb 9, 2024
c0a6388
lint
Feb 9, 2024
8595e1f
Directly assign StageSBOMViewFiles warnings to p.warnings
Feb 9, 2024
fdeb7a4
Directly assign p.cfg.Pkg to output of ComposeComponents
Feb 9, 2024
0ac00cf
Fix prepare logic
Feb 9, 2024
da83c69
Fix migration warnings in ComposeComponents
Feb 9, 2024
7f26165
Set pkg arch in LoadPackageDefinition
Feb 9, 2024
4b77a90
lint
Feb 9, 2024
b5a05ca
Update Output() to receive a pointer ZarfPackage
Feb 9, 2024
038650a
Merge branch 'main' into 2188-refactor-create-stages-into-separate-lib
Feb 9, 2024
1b76715
Merge branch 'main' into 2188-refactor-create-stages-into-separate-lib
Feb 12, 2024
34384a9
Veryify to verify
Feb 12, 2024
ba92f70
Merge branch 'main' into 2188-refactor-create-stages-into-separate-lib
Feb 12, 2024
c2581c3
No need to double-check if diffPkgPath is not empty
Feb 12, 2024
a25d584
Refactor SetBaseDirectory() to match the razzle version
Feb 12, 2024
41bb66b
Move get pkg name functions to sources
Feb 12, 2024
0a49820
Bring back IsTarball
Feb 12, 2024
d4e9e85
Update package create lifecycle diagram
Feb 12, 2024
9a4a8be
Update src/pkg/layout/package.go
lucasrod16 Feb 12, 2024
b1746d1
Update src/pkg/layout/package_test.go
lucasrod16 Feb 12, 2024
849b162
Merge branch '2188-refactor-create-stages-into-separate-lib' of https…
Feb 12, 2024
a4a90dd
Remove unused pkg pattern vars
Feb 12, 2024
6903909
Apply PR feedback
Feb 12, 2024
12bb5dd
lint
Feb 12, 2024
f013bbf
Apply feedback to package create lifecycle diagram
Feb 13, 2024
f804d07
Apply feedback to package create lifecycle diagram
Feb 13, 2024
a4e160f
Update comment to include filter by flavor
Feb 13, 2024
dc6d5e3
Build kustomizations during skeleton create
Feb 14, 2024
bdcd265
Add logic to skeleton test suite to verify kustomize-generated manifests
Feb 14, 2024
5139b88
Verify kustomize-generated manifests in skeleton are of kind ConfigMap
Feb 14, 2024
bbb848d
Add line-wrapping and rename things to be more readable
Feb 15, 2024
9ae12d5
Fix lint warning
Feb 15, 2024
9f080fc
Use a single pkg var for assignment in FindImages()
Feb 15, 2024
753e441
Merge branch 'main' into 2188-refactor-create-stages-into-separate-lib
Feb 16, 2024
4160706
Merge branch 'main' into 2188-refactor-create-stages-into-separate-lib
Feb 20, 2024
8202655
Merge branch 'main' into 2188-refactor-create-stages-into-separate-lib
Feb 20, 2024
e5b53f0
Merge branch 'main' into 2188-refactor-create-stages-into-separate-lib
Feb 21, 2024
a3727c3
Merge branch 'main' into 2188-refactor-create-stages-into-separate-lib
Feb 21, 2024
4357e44
Merge branch 'main' into 2188-refactor-create-stages-into-separate-lib
Feb 21, 2024
c739413
Merge branch 'main' into 2188-refactor-create-stages-into-separate-lib
Feb 22, 2024
2332cee
Merge branch 'main' into 2188-refactor-create-stages-into-separate-lib
Feb 23, 2024
4e95244
Merge branch 'main' into 2188-refactor-create-stages-into-separate-lib
Feb 26, 2024
11abf45
Merge branch 'main' into 2188-refactor-create-stages-into-separate-lib
Feb 26, 2024
09ef713
Move pkgOpts to a single call in sources.New
Feb 27, 2024
6a34119
Move diffPkgPath field to createOpts and move diffData out of createOpts
Feb 27, 2024
77c2535
Change composeWarnings to warnings
Feb 27, 2024
c533353
Use LoadPackageDefinition in FindImages
Feb 27, 2024
f3efb76
Merge branch 'main' into 2188-refactor-create-stages-into-separate-lib
Feb 27, 2024
cabb9d2
Update src/types/packager.go
lucasrod16 Feb 27, 2024
a128a2e
Move loadDifferentialData from a PackageCreator receiver to a standal…
Feb 27, 2024
a8c4d11
Remove debug statements from removeCopiesFromComponents
Feb 27, 2024
b40aa62
make docs-and-schema
Feb 27, 2024
60d5b1a
Combine GetPackageName w/ NameFromMetadata
Feb 27, 2024
bd7b18a
Merge branch 'main' into 2188-refactor-create-stages-into-separate-lib
Feb 29, 2024
551c0ea
Merge branch 'main' into 2188-refactor-create-stages-into-separate-lib
Feb 29, 2024
db52da1
Bring back ReadZarfYAML as a PackagePaths receiver
Feb 29, 2024
17f34be
Use ReadZarfYAML on Deploy() and delete runMigrations()
Feb 29, 2024
a7a93a0
Use ReadZarfYAML in Inspect()
Feb 29, 2024
4bd3aca
Use ReadZarfYAML in Mirror()
Feb 29, 2024
1a322ff
Use ReadZarfYAML in Publish()
Feb 29, 2024
4a459ff
Use ReadZarfYAML in Remove()
Feb 29, 2024
eccb085
Fix ReadZarfYAML error
Feb 29, 2024
09d9960
Remove p.arch to reduce passing around arch across codebase
Mar 1, 2024
1ddf9a2
pc to sc for SkeletonCreator receiver
Mar 1, 2024
4c175d3
Record build migrations in recordPackageMetadata()
Mar 4, 2024
f8a67f6
Merge branch 'main' into 2188-refactor-create-stages-into-separate-lib
Mar 4, 2024
6b9f7a0
Merge branch 'main' into 2188-refactor-create-stages-into-separate-lib
Mar 4, 2024
77a8259
Merge branch 'main' into 2188-refactor-create-stages-into-separate-lib
Mar 4, 2024
f19458b
Merge branch 'main' into 2188-refactor-create-stages-into-separate-lib
Mar 6, 2024
ec503e9
Record pkg build version right after recording pkg metadata version f…
Mar 6, 2024
00a226f
Merge branch 'main' into 2188-refactor-create-stages-into-separate-lib
Mar 7, 2024
69472cf
Add SetVariableMapInConfig back to FindImages
Mar 7, 2024
b2b9446
Fix pkg var in FindImages
Mar 7, 2024
8f13467
Remove shadown pkg var in FindImages and directly modify p.cfg.Pkg
Mar 7, 2024
3a42c7e
Merge branch 'main' into 2188-refactor-create-stages-into-separate-lib
Noxsios Mar 12, 2024
c41f5e9
update to keep in sync
Noxsios Mar 12, 2024
1ad5e26
use build instead of metadata
Noxsios Mar 12, 2024
de2e1d7
dry
Noxsios Mar 12, 2024
ba17472
dry
Noxsios Mar 12, 2024
653b328
going back on my word
Noxsios Mar 12, 2024
38b3150
going back on my word
Noxsios Mar 12, 2024
42f3d96
going back on my word
Noxsios Mar 12, 2024
9bd4c04
file perms
Noxsios Mar 12, 2024
8b25731
put cleanup back in
Noxsios Mar 12, 2024
be5dcef
Merge branch 'main' into 2188-refactor-create-stages-into-separate-lib
Noxsios Mar 12, 2024
8748b0c
fix what i broke
Noxsios Mar 12, 2024
fd4a139
Merge branch 'main' into 2188-refactor-create-stages-into-separate-lib
Noxsios Mar 13, 2024
6fa3dd7
remove p.arch
Noxsios Mar 13, 2024
bbadddf
keep warnings where they belong
Noxsios Mar 13, 2024
a5d3566
Update src/pkg/packager/deploy.go
Noxsios Mar 13, 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
34 changes: 25 additions & 9 deletions docs/3-create-a-zarf-package/4-zarf-schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,25 @@ Must be one of:
</blockquote>
</details>

<details open>
<summary>
<strong> <a name="build_registryOverrides"></a>registryOverrides</strong>
</summary>
&nbsp;
<blockquote>

## build > registryOverrides

**Description:** Any registry domains that were overridden on package create when pulling images

| | |
| ------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| **Type** | `object` |
| **Additional properties** | [![Any type: allowed](https://img.shields.io/badge/Any%20type-allowed-green)](# "Additional Properties of any type are allowed.") |

</blockquote>
</details>

<details>
<summary>
<strong> <a name="build_differential"></a>differential</strong>
Expand All @@ -425,21 +444,18 @@ Must be one of:
</blockquote>
</details>

<details open>
<details>
<summary>
<strong> <a name="build_registryOverrides"></a>registryOverrides</strong>
<strong> <a name="build_differentialPackageVersion"></a>differentialPackageVersion</strong>
</summary>
&nbsp;
<blockquote>

## build > registryOverrides

**Description:** Any registry domains that were overridden on package create when pulling images
**Description:** Version of a previously built package used as the basis for creating this differential package

| | |
| ------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| **Type** | `object` |
| **Additional properties** | [![Any type: allowed](https://img.shields.io/badge/Any%20type-allowed-green)](# "Additional Properties of any type are allowed.") |
| | |
| -------- | -------- |
| **Type** | `string` |

</blockquote>
</details>
Expand Down
69 changes: 35 additions & 34 deletions docs/3-create-a-zarf-package/5-package-create-lifecycle.md
lucasrod16 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,51 @@ The following diagram shows the order of operations for the `zarf package create

```mermaid
graph TD
A1(set working directory)-->A2
A2(parse zarf.yaml)-->A3
A3(filter components by architecture)-->A4
A4(detect init package)-->A5
A5(handle deprecations)-->A6
A1(cd to directory with zarf.yaml)-->A2
A2(load zarf.yaml into memory)-->A3
A3(set package architecture if not provided)-->A4
A4(filter components by architecture and flavor)-->A5
A5(migrate deprecated component configs)-->A6
A6(parse component imports)-->A7
A7(process create-time variables)-->A8
A8(write build data and zarf.yaml)-->A9

A9(run validations)-->A10
A10(confirm package create):::prompt-->A11
A11{Init package?}
A11 -->|Yes| A12(add seed image)-->A13
A11 -->|No| A13
A8(process extensions)-->A9
A9(remove duplicate images/repos if --differential flag used)-->A10
A10(run validations)-->A11
A11(confirm package create):::prompt-->A12

subgraph
A13(add each component)-->A13
A13 --> A14(run each '.actions.onCreate.before'):::action-->A14
A14 --> A15(load '.charts')-->A16
A16(load '.files')-->A17
A17(load '.dataInjections')-->A18
A18(load '.manifests')-->A19
A19(load '.repos')-->A20
A20(run each '.actions.onCreate.after'):::action-->A20
A20-->A21{Success?}
A21-->|Yes|A22(run each\n'.actions.onCreate.success'):::action-->A22
A21-->|No|A23(run each\n'.actions.onCreate.failure'):::action-->A23-->A999
A12(run each '.actions.onCreate.before'):::action-->A13(load '.charts')
A13-->A14(load '.files')
A14-->A15(load '.dataInjections')
A15-->A16(load '.manifests')
A16-->A17(load '.repos')
A17-->A18(run each '.actions.onCreate.after'):::action
A18-->A19{Success?}
A19-->|Yes|A20(run each\n'.actions.onCreate.success'):::action
A19-->|No|A999
end

A22-->A24(load all '.images')
A24-->A25{Skip SBOM?}
A25-->|Yes|A27
A25-->|No|A26
A26(generate SBOM)-->A27
A27(reset working directory)-->A28
A28(create package archive)-->A29
A29{Is multipart?}
A29-->|Yes|A30(split package archive)-->A31
A29-->|No|A31
A31(handle sbom view/out flags)
A20-->A21(load all '.images')
A21-->A22(generate SBOMs unless --skip-sbom flag was used)
A22-->A23(cd back to original working directory)
A23-->A24(archive components into tarballs)
A24-->A25(generate checksums for all package files)
A25-->A26(record package build metadata)
A26-->A27(write the zarf.yaml to disk)
A27-->A28(sign the package if a key was provided)
A28-->A29{Output to OCI?}
A29-->|Yes|A30(publish package to OCI registry)
A29-->|No|A31(archive package into a tarball and write to disk)
A30-->A32
A31-->A32
A32(write SBOM files to disk if --sbom or --sbom-out flags used)-->A33
A33(view SBOMs if --sbom flag used)-->A34
A34[Zarf Package Create Successful]:::success

A999[Abort]:::fail

classDef prompt fill:#4adede,color:#000000
classDef action fill:#bd93f9,color:#000000
classDef fail fill:#aa0000
classDef success fill:#008000,color:#fff;
```
13 changes: 4 additions & 9 deletions src/cmd/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,10 @@
// Package common handles command configuration across all commands
package common

import (
"github.com/defenseunicorns/zarf/src/types"
)

// SetBaseDirectory sets base directory on package config when given in args
func SetBaseDirectory(args []string, pkgConfig *types.PackagerConfig) {
// SetBaseDirectory sets the base directory. This is a directory with a zarf.yaml.
func SetBaseDirectory(args []string) string {
if len(args) > 0 {
pkgConfig.CreateOpts.BaseDir = args[0]
} else {
pkgConfig.CreateOpts.BaseDir = "."
return args[0]
}
return "."
}
8 changes: 4 additions & 4 deletions src/cmd/dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var devDeployCmd = &cobra.Command{
Short: lang.CmdDevDeployShort,
Long: lang.CmdDevDeployLong,
Run: func(_ *cobra.Command, args []string) {
common.SetBaseDirectory(args, &pkgConfig)
pkgConfig.CreateOpts.BaseDir = common.SetBaseDirectory(args)

v := common.GetViper()
pkgConfig.CreateOpts.SetVariables = helpers.TransformAndMergeMap(
Expand Down Expand Up @@ -116,7 +116,7 @@ var devTransformGitLinksCmd = &cobra.Command{

if confirm {
// Overwrite the file
err = os.WriteFile(fileName, []byte(processedText), 0640)
err = os.WriteFile(fileName, []byte(processedText), helpers.ReadAllWriteUser)
if err != nil {
message.Fatal(err, lang.CmdDevPatchGitFileWriteErr)
}
Expand Down Expand Up @@ -207,7 +207,7 @@ var devFindImagesCmd = &cobra.Command{
Short: lang.CmdDevFindImagesShort,
Long: lang.CmdDevFindImagesLong,
Run: func(_ *cobra.Command, args []string) {
common.SetBaseDirectory(args, &pkgConfig)
pkgConfig.CreateOpts.BaseDir = common.SetBaseDirectory(args)

// Ensure uppercase keys from viper
v := common.GetViper()
Expand Down Expand Up @@ -256,7 +256,7 @@ var devLintCmd = &cobra.Command{
Short: lang.CmdDevLintShort,
Long: lang.CmdDevLintLong,
Run: func(_ *cobra.Command, args []string) {
common.SetBaseDirectory(args, &pkgConfig)
pkgConfig.CreateOpts.BaseDir = common.SetBaseDirectory(args)
v := common.GetViper()
pkgConfig.CreateOpts.SetVariables = helpers.TransformAndMergeMap(
v.GetStringMapString(common.VPkgCreateSet), pkgConfig.CreateOpts.SetVariables, strings.ToUpper)
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var initCmd = &cobra.Command{
}

// Continue running package deploy for all components like any other package
initPackageName := packager.GetInitPackageName("")
initPackageName := sources.GetInitPackageName()
pkgConfig.PkgOpts.PackageSource = initPackageName

// Try to use an init-package in the executable directory if none exist in current working directory
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ var packageCreateCmd = &cobra.Command{
Short: lang.CmdPackageCreateShort,
Long: lang.CmdPackageCreateLong,
Run: func(_ *cobra.Command, args []string) {
common.SetBaseDirectory(args, &pkgConfig)
pkgConfig.CreateOpts.BaseDir = common.SetBaseDirectory(args)

var isCleanPathRegex = regexp.MustCompile(`^[a-zA-Z0-9\_\-\/\.\~\\:]+$`)
if !isCleanPathRegex.MatchString(config.CommonOptions.CachePath) {
Expand Down Expand Up @@ -350,7 +350,7 @@ func bindCreateFlags(v *viper.Viper) {
createFlags.StringVar(&pkgConfig.CreateOpts.Output, "output-directory", v.GetString("package.create.output_directory"), lang.CmdPackageCreateFlagOutput)
createFlags.StringVarP(&pkgConfig.CreateOpts.Output, "output", "o", v.GetString(common.VPkgCreateOutput), lang.CmdPackageCreateFlagOutput)

createFlags.StringVar(&pkgConfig.CreateOpts.DifferentialData.DifferentialPackagePath, "differential", v.GetString(common.VPkgCreateDifferential), lang.CmdPackageCreateFlagDifferential)
createFlags.StringVar(&pkgConfig.CreateOpts.DifferentialPackagePath, "differential", v.GetString(common.VPkgCreateDifferential), lang.CmdPackageCreateFlagDifferential)
createFlags.StringToStringVar(&pkgConfig.CreateOpts.SetVariables, "set", v.GetStringMapString(common.VPkgCreateSet), lang.CmdPackageCreateFlagSet)
createFlags.BoolVarP(&pkgConfig.CreateOpts.ViewSBOM, "sbom", "s", v.GetBool(common.VPkgCreateSbom), lang.CmdPackageCreateFlagSbom)
createFlags.StringVar(&pkgConfig.CreateOpts.SBOMOutputDir, "sbom-out", v.GetString(common.VPkgCreateSbomOutput), lang.CmdPackageCreateFlagSbomOut)
Expand Down
9 changes: 5 additions & 4 deletions src/config/lang/english.go
Original file line number Diff line number Diff line change
Expand Up @@ -633,20 +633,21 @@ const (
AgentErrUnableTransform = "unable to transform the provided request; see zarf http proxy logs for more details"
)

// src/internal/packager/create
// Package create
const (
PkgCreateErrDifferentialSameVersion = "unable to create a differential package with the same version as the package you are using as a reference; the package version must be incremented"
PkgCreateErrDifferentialSameVersion = "unable to create differential package. Please ensure the differential package version and reference package version are not the same. The package version must be incremented"
PkgCreateErrDifferentialNoVersion = "unable to create differential package. Please ensure both package versions are set"
)

// src/internal/packager/deploy.
// Package deploy
const (
PkgDeployErrMultipleComponentsSameGroup = "You cannot specify multiple components (%q, %q) within the same group (%q) when using the --components flag."
PkgDeployErrNoDefaultOrSelection = "You must make a selection from %q with the --components flag as there is no default in their group."
PkgDeployErrNoCompatibleComponentsForSelection = "No compatible components found that matched %q. Please check spelling and try again."
PkgDeployErrComponentSelectionCanceled = "Component selection canceled: %s"
)

// src/internal/packager/validate.
// Package validate
const (
PkgValidateTemplateDeprecation = "Package template %q is using the deprecated syntax ###ZARF_PKG_VAR_%s###. This will be removed in Zarf v1.0.0. Please update to ###ZARF_PKG_TMPL_%s###."
PkgValidateMustBeUppercase = "variable name %q must be all uppercase and contain no special characters except _"
Expand Down
30 changes: 0 additions & 30 deletions src/internal/packager/sbom/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@ package sbom

import (
"fmt"
"os"
"path/filepath"

"github.com/AlecAivazis/survey/v2"
"github.com/defenseunicorns/zarf/src/pkg/message"
"github.com/defenseunicorns/zarf/src/pkg/utils"
"github.com/defenseunicorns/zarf/src/pkg/utils/exec"
"github.com/defenseunicorns/zarf/src/pkg/utils/helpers"
"github.com/defenseunicorns/zarf/src/types"
)

// ViewSBOMFiles opens a browser to view the SBOM files and pauses for user input.
Expand All @@ -41,29 +37,3 @@ func ViewSBOMFiles(directory string) {
message.Note("There were no images with software bill-of-materials (SBOM) included.")
}
}

// OutputSBOMFiles outputs the sbom files into a specified directory.
func OutputSBOMFiles(sourceDir, outputDir, packageName string) (string, error) {
packagePath := filepath.Join(outputDir, packageName)

if err := os.RemoveAll(packagePath); err != nil {
return "", err
}

if err := utils.CreateDirectory(packagePath, helpers.ReadWriteExecuteUser); err != nil {
return "", err
}

return packagePath, utils.CreatePathAndCopy(sourceDir, packagePath)
}

// IsSBOMAble checks if a package has contents that an SBOM can be created on (i.e. images, files, or data injections)
func IsSBOMAble(pkg types.ZarfPackage) bool {
for _, c := range pkg.Components {
if len(c.Images) > 0 || len(c.Files) > 0 || len(c.DataInjections) > 0 {
return true
}
}

return false
}
Loading
Loading