Skip to content

Commit

Permalink
Merge branch 'main' into update-version-flag
Browse files Browse the repository at this point in the history
  • Loading branch information
zackbradys authored Dec 4, 2024
2 parents 39674a0 + 01faf39 commit f2d8360
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 15 deletions.
14 changes: 12 additions & 2 deletions cmd/hauler/cli/store/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,19 @@ import (
func LoadCmd(ctx context.Context, o *flags.LoadOpts, archiveRefs ...string) error {
l := log.FromContext(ctx)

storeDir := o.StoreDir

if storeDir == "" {
storeDir = os.Getenv(consts.HaulerStoreDir)
}

if storeDir == "" {
storeDir = consts.DefaultStoreName
}

for _, archiveRef := range archiveRefs {
l.Infof("loading content from [%s] to [%s]", archiveRef, o.StoreDir)
err := unarchiveLayoutTo(ctx, archiveRef, o.StoreDir, o.TempOverride)
l.Infof("loading content from [%s] to [%s]", archiveRef, storeDir)
err := unarchiveLayoutTo(ctx, archiveRef, storeDir, o.TempOverride)
if err != nil {
return err
}
Expand Down
16 changes: 13 additions & 3 deletions cmd/hauler/cli/store/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ import (
func SaveCmd(ctx context.Context, o *flags.SaveOpts, outputFile string) error {
l := log.FromContext(ctx)

storeDir := o.StoreDir

if storeDir == "" {
storeDir = os.Getenv(consts.HaulerStoreDir)
}

if storeDir == "" {
storeDir = consts.DefaultStoreName
}

// TODO: Support more formats?
a := archiver.NewTarZstd()
a.OverwriteExisting = true
Expand All @@ -42,7 +52,7 @@ func SaveCmd(ctx context.Context, o *flags.SaveOpts, outputFile string) error {
return err
}
defer os.Chdir(cwd)
if err := os.Chdir(o.StoreDir); err != nil {
if err := os.Chdir(storeDir); err != nil {
return err
}

Expand All @@ -55,7 +65,7 @@ func SaveCmd(ctx context.Context, o *flags.SaveOpts, outputFile string) error {
return err
}

l.Infof("saved store [%s] -> [%s]", o.StoreDir, absOutputfile)
l.Infof("saved store [%s] -> [%s]", storeDir, absOutputfile)
return nil
}

Expand Down Expand Up @@ -161,7 +171,7 @@ func writeExportsManifest(ctx context.Context, dir string, platformStr string) e
return err
}

return oci.WriteFile(consts.OCIImageManifestFile, buf.Bytes(), 0666)
return oci.WriteFile(consts.ImageManifestFile, buf.Bytes(), 0666)
}

func (x *exports) describe() tarball.Manifest {
Expand Down
13 changes: 10 additions & 3 deletions internal/flags/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type StoreRootOpts struct {

func (o *StoreRootOpts) AddFlags(cmd *cobra.Command) {
pf := cmd.PersistentFlags()
pf.StringVarP(&o.StoreDir, "store", "s", consts.DefaultStoreName, "Set the directory to use for the content store")
pf.StringVarP(&o.StoreDir, "store", "s", "", "Set the directory to use for the content store")
pf.IntVarP(&o.Retries, "retries", "r", consts.DefaultRetries, "Set the number of retries for operations")
}

Expand All @@ -28,6 +28,14 @@ func (o *StoreRootOpts) Store(ctx context.Context) (*store.Layout, error) {

storeDir := o.StoreDir

if storeDir == "" {
storeDir = os.Getenv(consts.HaulerStoreDir)
}

if storeDir == "" {
storeDir = consts.DefaultStoreName
}

abs, err := filepath.Abs(storeDir)
if err != nil {
return nil, err
Expand All @@ -36,8 +44,7 @@ func (o *StoreRootOpts) Store(ctx context.Context) (*store.Layout, error) {
l.Debugf("using store at %s", abs)

if _, err := os.Stat(abs); errors.Is(err, os.ErrNotExist) {
err := os.Mkdir(abs, os.ModePerm)
if err != nil {
if err := os.MkdirAll(abs, os.ModePerm); err != nil {
return nil, err
}
} else if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions internal/mapper/mappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func Images() map[string]Fn {
m := make(map[string]Fn)

manifestMapperFn := Fn(func(desc ocispec.Descriptor) (string, error) {
return consts.OCIImageManifestFile, nil
return consts.ImageManifestFile, nil
})

for _, l := range []string{consts.DockerManifestSchema2, consts.DockerManifestListSchema2, consts.OCIManifestSchema1} {
Expand All @@ -52,7 +52,7 @@ func Images() map[string]Fn {
}

configMapperFn := Fn(func(desc ocispec.Descriptor) (string, error) {
return consts.OCIImageConfigFile, nil
return consts.ImageConfigFile, nil
})

for _, l := range []string{consts.DockerConfigJSON} {
Expand Down
11 changes: 6 additions & 5 deletions pkg/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,15 @@ const (
// environment variables
HaulerDir = "HAULER_DIR"
HaulerTempDir = "HAULER_TEMP_DIR"
HaulerStoreDir = "HAULER_STORE_DIR"
HaulerIgnoreErrors = "HAULER_IGNORE_ERRORS"

// container files and directories
OCIImageIndexFile = "index.json"
OCIImageManifestFile = "manifest.json"
OCIImageConfigFile = "config.json"
OCIImageLayoutFile = "oci-layout"
OCIImageBlobsDir = "blobs"
OCIImageIndexFile = "index.json"
OCIImageLayoutFile = "oci-layout"
OCIImageBlobsDir = "blobs"
ImageManifestFile = "manifest.json"
ImageConfigFile = "config.json"

// other constraints
CarbideRegistry = "rgcrprod.azurecr.us"
Expand Down
1 change: 1 addition & 0 deletions pkg/cosign/cosign.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ func EnsureBinaryExists(ctx context.Context, bin embed.FS, ro *flags.CliRootOpts

// getCosignPath returns the binary path
func getCosignPath(haulerDir string) (string, error) {

if haulerDir == "" {
haulerDir = os.Getenv(consts.HaulerDir)
}
Expand Down

0 comments on commit f2d8360

Please sign in to comment.