Skip to content

Commit

Permalink
manifest: addCompression use default from containers.conf
Browse files Browse the repository at this point in the history
Replaces: containers#5014

Signed-off-by: Aditya R <arajan@redhat.com>
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
  • Loading branch information
flouthoc authored and TomSweeneyRedHat committed Feb 16, 2024
1 parent 21ec7ac commit 64b88ac
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 13 deletions.
6 changes: 0 additions & 6 deletions cmd/buildah/from.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/containers/buildah/pkg/cli"
"github.com/containers/buildah/pkg/parse"
"github.com/containers/common/pkg/auth"
"github.com/containers/common/pkg/config"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -188,11 +187,6 @@ func onBuild(builder *buildah.Builder, quiet bool) error {
}

func fromCmd(c *cobra.Command, args []string, iopts fromReply) error {
defaultContainerConfig, err := config.Default()
if err != nil {
return fmt.Errorf("failed to get container config: %w", err)
}

if len(args) == 0 {
return errors.New("an image name (or \"scratch\") must be specified")
}
Expand Down
11 changes: 6 additions & 5 deletions cmd/buildah/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ var rootCmd = &cobra.Command{
}

var (
globalFlagResults globalFlags
exitCode int
globalFlagResults globalFlags
exitCode int
defaultContainerConfig *config.Config
)

func init() {
Expand All @@ -79,12 +80,12 @@ func init() {
defaultStoreDriverOptions = optionSlice
}

containerConfig, err := config.Default()
defaultContainerConfig, err = config.Default()
if err != nil {
logrus.Errorf(err.Error())
os.Exit(1)
}
containerConfig.CheckCgroupsAndAdjustConfig()
defaultContainerConfig.CheckCgroupsAndAdjustConfig()

cobra.OnInitialize(initConfig)
// Disable the implicit `completion` command in cobra.
Expand All @@ -98,7 +99,7 @@ func init() {
rootCmd.PersistentFlags().StringVar(&globalFlagResults.UserShortNameAliasConfPath, "short-name-alias-conf", "", "path to short name alias cache file (not usually used)")
rootCmd.PersistentFlags().StringVar(&globalFlagResults.Root, "root", storageOptions.GraphRoot, "storage root dir")
rootCmd.PersistentFlags().StringVar(&globalFlagResults.RunRoot, "runroot", storageOptions.RunRoot, "storage state dir")
rootCmd.PersistentFlags().StringVar(&globalFlagResults.CgroupManager, "cgroup-manager", containerConfig.Engine.CgroupManager, "cgroup manager")
rootCmd.PersistentFlags().StringVar(&globalFlagResults.CgroupManager, "cgroup-manager", defaultContainerConfig.Engine.CgroupManager, "cgroup manager")
rootCmd.PersistentFlags().StringVar(&globalFlagResults.StorageDriver, "storage-driver", storageOptions.GraphDriverName, "storage-driver")
rootCmd.PersistentFlags().StringSliceVar(&globalFlagResults.StorageOpts, "storage-opt", defaultStoreDriverOptions, "storage driver option")
rootCmd.PersistentFlags().StringSliceVar(&globalFlagResults.UserNSUID, "userns-uid-map", []string{}, "default `ctrID:hostID:length` UID mapping to use")
Expand Down
2 changes: 1 addition & 1 deletion cmd/buildah/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func init() {
flags.StringVar(&manifestPushOpts.compressionFormat, "compression-format", "", "compression format to use")
flags.IntVar(&manifestPushOpts.compressionLevel, "compression-level", 0, "compression level to use")
flags.StringVarP(&manifestPushOpts.format, "format", "f", "", "manifest type (oci or v2s2) to attempt to use when pushing the manifest list (default is manifest type of source)")
flags.StringSliceVar(&manifestPushOpts.addCompression, "add-compression", nil, "add instances with selected compression while pushing")
flags.StringArrayVar(&manifestPushOpts.addCompression, "add-compression", defaultContainerConfig.Engine.AddCompression.Get(), "add instances with selected compression while pushing")
flags.BoolVarP(&manifestPushOpts.removeSignatures, "remove-signatures", "", false, "don't copy signatures when pushing images")
flags.StringVar(&manifestPushOpts.signBy, "sign-by", "", "sign the image using a GPG key with the specified `FINGERPRINT`")
flags.StringVar(&manifestPushOpts.signaturePolicy, "signature-policy", "", "`pathname` of signature policy file (not usually used)")
Expand Down
28 changes: 27 additions & 1 deletion tests/bud.bats
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,37 @@ load helpers
}

@test "bud: build manifest list and --add-compression zstd" {
start_registry
run_buildah login --tls-verify=false --authfile ${TEST_SCRATCH_DIR}/test.auth --username testuser --password testpassword localhost:${REGISTRY_PORT}
run_buildah build $WITH_POLICY_JSON -t image1 --platform linux/amd64 -f $BUDFILES/dockerfile/Dockerfile
run_buildah build $WITH_POLICY_JSON -t image2 --platform linux/arm64 -f $BUDFILES/dockerfile/Dockerfile

run_buildah manifest create foo
run_buildah manifest add foo image1
run_buildah manifest add foo image2

run_buildah manifest push $WITH_POLICY_JSON --authfile ${TEST_SCRATCH_DIR}/test.auth --all --add-compression zstd --tls-verify=false foo docker://localhost:${REGISTRY_PORT}/list

run_buildah manifest inspect --authfile ${TEST_SCRATCH_DIR}/test.auth --tls-verify=false localhost:${REGISTRY_PORT}/list
list="$output"

validate_instance_compression "0" "$list" "amd64" "gzip"
validate_instance_compression "1" "$list" "arm64" "gzip"
validate_instance_compression "2" "$list" "amd64" "zstd"
validate_instance_compression "3" "$list" "arm64" "zstd"
}

@test "bud: build manifest list and --add-compression with containers.conf" {
local contextdir=${TEST_SCRATCH_DIR}/bud/platform
mkdir -p $contextdir

cat > $contextdir/Dockerfile1 << _EOF
FROM alpine
_EOF

cat > $contextdir/containers.conf << _EOF
[engine]
add_compression = ["zstd"]
_EOF

start_registry
Expand All @@ -28,7 +54,7 @@ _EOF
run_buildah manifest add foo image1
run_buildah manifest add foo image2

run_buildah manifest push $WITH_POLICY_JSON --authfile ${TEST_SCRATCH_DIR}/test.auth --all --add-compression zstd --tls-verify=false foo docker://localhost:${REGISTRY_PORT}/list
CONTAINERS_CONF=$contextdir/containers.conf run_buildah manifest push $WITH_POLICY_JSON --authfile ${TEST_SCRATCH_DIR}/test.auth --all --tls-verify=false foo docker://localhost:${REGISTRY_PORT}/list

run_buildah manifest inspect --authfile ${TEST_SCRATCH_DIR}/test.auth --tls-verify=false localhost:${REGISTRY_PORT}/list
list="$output"
Expand Down

0 comments on commit 64b88ac

Please sign in to comment.