Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions cmd/buildah/addcopy.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type addCopyResults struct {
contextdir string
from string
blobCache string
blobInfoCache string
decryptionKeys []string
removeSignatures bool
signaturePolicy string
Expand Down Expand Up @@ -75,6 +76,10 @@ func applyFlagVars(flags *pflag.FlagSet, opts *addCopyResults) {
if err := flags.MarkHidden("blob-cache"); err != nil {
panic(fmt.Sprintf("error marking blob-cache as hidden: %v", err))
}
flags.StringVar(&opts.blobInfoCache, "blob-info-cache-dir", "", "cache information about blobs in the specified directory instead of the default location")
if err := flags.MarkHidden("blob-info-cache-dir"); err != nil {
panic(fmt.Sprintf("error marking blob-info-cache-dir as hidden: %v", err))
}
flags.StringVar(&opts.certDir, "cert-dir", "", "use certificates at the specified path to access registries and sources in HTTPS locations")
flags.StringVar(&opts.checksum, "checksum", "", "checksum the HTTP source content")
flags.StringVar(&opts.chown, "chown", "", "set the user and group ownership of the destination content")
Expand Down
5 changes: 5 additions & 0 deletions cmd/buildah/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type commitInputOptions struct {
authfile string
omitHistory bool
blobCache string
blobInfoCache string
certDir string
changes []string
compressionFormat string
Expand Down Expand Up @@ -110,6 +111,10 @@ func commitListFlagSet(cmd *cobra.Command, opts *commitInputOptions) {
if err := flags.MarkHidden("blob-cache"); err != nil {
panic(fmt.Sprintf("error marking blob-cache as hidden: %v", err))
}
flags.StringVar(&opts.blobInfoCache, "blob-info-cache-dir", "", "cache information about blobs in the specified directory instead of the default location")
if err := flags.MarkHidden("blob-info-cache-dir"); err != nil {
panic(fmt.Sprintf("error marking blob-info-cache-dir as hidden: %v", err))
}
flags.StringSliceVar(&opts.encryptionKeys, "encryption-key", nil, "key with the encryption protocol to use needed to encrypt the image (e.g. jwe:/path/to/key.pem)")
_ = cmd.RegisterFlagCompletionFunc("encryption-key", completion.AutocompleteDefault)
flags.IntSliceVar(&opts.encryptLayers, "encrypt-layer", nil, "layers to encrypt, 0-indexed layer indices with support for negative indexing (e.g. 0 is the first layer, -1 is the last layer). If not defined, will encrypt all layers if encryption-key flag is specified")
Expand Down
5 changes: 5 additions & 0 deletions cmd/buildah/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type pullOptions struct {
allTags bool
authfile string
blobCache string
blobInfoCache string
certDir string
creds string
signaturePolicy string
Expand Down Expand Up @@ -60,6 +61,10 @@ func pullInit() {
flags.BoolVarP(&opts.allTags, "all-tags", "a", false, "download all tagged images in the repository")
flags.StringVar(&opts.authfile, "authfile", auth.GetDefaultAuthFile(), "path of the authentication file. Use REGISTRY_AUTH_FILE environment variable to override")
flags.StringVar(&opts.blobCache, "blob-cache", "", "store copies of pulled image blobs in the specified directory")
flags.StringVar(&opts.blobInfoCache, "blob-info-cache-dir", "", "cache information about blobs in the specified directory instead of the default location")
if err := flags.MarkHidden("blob-info-cache-dir"); err != nil {
panic(fmt.Sprintf("error marking blob-info-cache-dir as hidden: %v", err))
}
flags.StringVar(&opts.certDir, "cert-dir", "", "use certificates at the specified path to access the registry")
flags.StringVar(&opts.creds, "creds", "", "use `[username[:password]]` for accessing the registry")
flags.StringVar(&opts.pullPolicy, "policy", "missing", "missing, always, ifnewer, or never.")
Expand Down
5 changes: 5 additions & 0 deletions cmd/buildah/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type pushOptions struct {
all bool
authfile string
blobCache string
blobInfoCache string
certDir string
creds string
digestfile string
Expand Down Expand Up @@ -86,6 +87,10 @@ func pushInit() {
flags.BoolVar(&opts.all, "all", false, "push all of the images referenced by the manifest list")
flags.StringVar(&opts.authfile, "authfile", auth.GetDefaultAuthFile(), "path of the authentication file. Use REGISTRY_AUTH_FILE environment variable to override")
flags.StringVar(&opts.blobCache, "blob-cache", "", "assume image blobs in the specified directory will be available for pushing")
flags.StringVar(&opts.blobInfoCache, "blob-info-cache-dir", "", "cache information about blobs in the specified directory instead of the default location")
if err := flags.MarkHidden("blob-info-cache-dir"); err != nil {
panic(fmt.Sprintf("error marking blob-info-cache-dir as hidden: %v", err))
}
flags.StringVar(&opts.certDir, "cert-dir", "", "use certificates at the specified path to access the registry")
flags.StringVar(&opts.creds, "creds", "", "use `[username[:password]]` for accessing the registry")
flags.StringVar(&opts.digestfile, "digestfile", "", "after copying the image, write the digest of the resulting image to the file")
Expand Down
4 changes: 3 additions & 1 deletion cmd/buildah/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ func runInit() {
flags.StringSliceVar(&opts.capAdd, "cap-add", []string{}, "add the specified capability (default [])")
flags.StringSliceVar(&opts.capDrop, "cap-drop", []string{}, "drop the specified capability (default [])")
flags.StringVar(&opts.cdiConfigDir, "cdi-config-dir", "", "`directory` of CDI configuration files")
_ = flags.MarkHidden("cdi-config-dir")
if err := flags.MarkHidden("cdi-config-dir"); err != nil {
panic(fmt.Sprintf("error marking cdi-config-dir as hidden: %v", err))
}
flags.StringVar(&opts.contextDir, "contextdir", "", "context directory path")
flags.StringArrayVar(&opts.devices, "device", []string{}, "additional devices to provide")
flags.StringArrayVarP(&opts.env, "env", "e", []string{}, "add environment variable to be set temporarily when running command (default [])")
Expand Down
7 changes: 6 additions & 1 deletion pkg/cli/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ type BudResults struct {
type FromAndBudResults struct {
AddHost []string
BlobCache string
BlobInfoCache string
CapAdd []string
CapDrop []string
CDIConfigDir string
Expand Down Expand Up @@ -422,7 +423,11 @@ func GetFromAndBudFlags(flags *FromAndBudResults, usernsResults *UserNSResults,
fs.StringSliceVar(&flags.AddHost, "add-host", []string{}, "add a custom host-to-IP mapping (`host:ip`) (default [])")
fs.StringVar(&flags.BlobCache, "blob-cache", "", "assume image blobs in the specified directory will be available for pushing")
if err := fs.MarkHidden("blob-cache"); err != nil {
panic(fmt.Sprintf("error marking net flag as hidden: %v", err))
panic(fmt.Sprintf("error marking blob-cache flag as hidden: %v", err))
}
fs.StringVar(&flags.BlobInfoCache, "blob-info-cache-dir", "", "cache information about blobs in the specified directory instead of the default location")
if err := fs.MarkHidden("blob-info-cache-dir"); err != nil {
panic(fmt.Sprintf("error marking blob-info-cache flag as hidden: %v", err))
}
fs.StringSliceVar(&flags.CapAdd, "cap-add", []string{}, "add the specified capability when running (default [])")
fs.StringSliceVar(&flags.CapDrop, "cap-drop", []string{}, "drop the specified capability when running (default [])")
Expand Down
4 changes: 4 additions & 0 deletions pkg/parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,10 @@ func SystemContextFromFlagSet(flags *pflag.FlagSet, findFlagFunc func(name strin
if err == nil && findFlagFunc("short-name-alias-conf").Changed {
ctx.UserShortNameAliasConfPath = shortNameAliasConf
}
blobInfoCacheDir, err := flags.GetString("blob-info-cache-dir")
if err == nil && findFlagFunc("blob-info-cache-dir").Changed {
ctx.BlobInfoCacheDir = blobInfoCacheDir
}
ctx.DockerRegistryUserAgent = fmt.Sprintf("Buildah/%s", define.Version)
if findFlagFunc("os") != nil && findFlagFunc("os").Changed {
var os string
Expand Down
20 changes: 8 additions & 12 deletions tests/bud.bats
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,6 @@ EOF
}

@test "bud: build push with --force-compression" {
skip_if_no_podman
blobcachedir=${TEST_SCRATCH_DIR}/blobcachelocal
mkdir -p ${blobcachedir}
local contextdir=${TEST_SCRATCH_DIR}/bud/platform
Expand All @@ -408,7 +407,7 @@ _EOF
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 $imgname --platform linux/amd64 $contextdir

# Helper function. push our image with the given options, and run skopeo inspect
# Helper function. push our image with the given options, and run imgtype to inspect
function _test_buildah_push() {
run_buildah push \
--blob-cache=${blobcachedir} \
Expand All @@ -419,15 +418,12 @@ _EOF
$imgname \
docker://localhost:${REGISTRY_PORT}/$imgname

echo "# skopeo inspect $imgname"
run podman run --rm \
--mount type=bind,src=${TEST_SCRATCH_DIR}/test.auth,target=/test.auth,Z \
--net host \
quay.io/skopeo/stable inspect \
--authfile=/test.auth \
--tls-verify=false \
--raw \
echo "# imgtype -show-manifest docker://localhost:${REGISTRY_PORT}/$imgname"
run imgtype -show-manifest \
-authfile=${TEST_SCRATCH_DIR}/test.auth \
-tls-verify=false \
docker://localhost:${REGISTRY_PORT}/$imgname
assert $status -eq 0 "imgtype failed"
echo "$output"
}

Expand All @@ -439,11 +435,11 @@ _EOF
_test_buildah_push --compression-format zstd --force-compression=false
assert "$output" !~ "zstd" "zstd found even though push was without --force-compression"

# layers should container `zstd`
# layers should contain `zstd`
_test_buildah_push --compression-format zstd
expect_output --substring "zstd" "layers must contain zstd compression"

# layers should container `zstd`
# layers should contain `zstd`
_test_buildah_push --compression-format zstd --force-compression
expect_output --substring "zstd" "layers must contain zstd compression"
}
Expand Down
28 changes: 21 additions & 7 deletions tests/copy/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func main() {
var logLevel string
var maxParallelDownloads uint
var compressionFormat string
var forceCompressionFormat bool
var manifestFormat string
compressionLevel := -1

Expand Down Expand Up @@ -62,9 +63,9 @@ func main() {
systemContext.CompressionFormat = &alg
}
switch strings.ToLower(manifestFormat) {
case "oci":
case "oci", "ociv1":
manifestFormat = v1.MediaTypeImageManifest
case "docker", "dockerv2s2":
case "docker", "dockerv2s2", "v2s2":
manifestFormat = manifest.DockerV2Schema2MediaType
}

Expand Down Expand Up @@ -119,11 +120,16 @@ func main() {
}()

options := cp.Options{
ReportWriter: os.Stdout,
SourceCtx: &systemContext,
DestinationCtx: &systemContext,
MaxParallelDownloads: maxParallelDownloads,
ForceManifestMIMEType: manifestFormat,
ReportWriter: os.Stdout,
SourceCtx: &systemContext,
DestinationCtx: &systemContext,
MaxParallelDownloads: maxParallelDownloads,
ForceManifestMIMEType: manifestFormat,
ForceCompressionFormat: forceCompressionFormat,
}
if compressionFormat != "" && !cmd.Flag("dest-force-compression-format").Changed {
options.ForceCompressionFormat = true
systemContext.DirForceCompress = true
}
if _, err = cp.Image(context.TODO(), policyContext, dest, src, &options); err != nil {
return err
Expand All @@ -145,17 +151,25 @@ func main() {
rootCmd.PersistentFlags().BoolVar(&storeOptions.TransientStore, "transient-store", false, "store some information in transient storage")
rootCmd.PersistentFlags().StringVar(&storeOptions.GraphDriverName, "storage-driver", "", "storage driver")
rootCmd.PersistentFlags().StringSliceVar(&storeOptions.GraphDriverOptions, "storage-opt", nil, "storage option")
rootCmd.PersistentFlags().StringVar(&systemContext.DockerCertPath, "cert-dir", "", "location of certificates to use for communicating with registries")
rootCmd.PersistentFlags().StringVar(&systemContext.SystemRegistriesConfPath, "registries-conf", "", "location of registries.conf")
rootCmd.PersistentFlags().StringVar(&systemContext.SystemRegistriesConfDirPath, "registries-conf-dir", "", "location of registries.d")
rootCmd.PersistentFlags().StringVar(&systemContext.SignaturePolicyPath, "signature-policy", "", "`pathname` of signature policy file")
rootCmd.PersistentFlags().StringVar(&systemContext.UserShortNameAliasConfPath, "short-name-alias-conf", "", "`pathname` of short name alias cache file (not usually used)")
rootCmd.PersistentFlags().StringVar(&logLevel, "log-level", "warn", "logging level")
rootCmd.PersistentFlags().UintVar(&maxParallelDownloads, "max-parallel-downloads", 0, "maximum `number` of blobs to copy at once")
rootCmd.PersistentFlags().StringVar(&manifestFormat, "format", "", "image manifest type")
rootCmd.PersistentFlags().StringVar(&systemContext.BlobInfoCacheDir, "blob-info-cache-dir", "", "cache information about blobs in the specified directory instead of the default location")
rootCmd.PersistentFlags().BoolVar(&systemContext.DirForceCompress, "dest-compress", false, "force compression of layers for dir: destinations")
rootCmd.PersistentFlags().BoolVar(&systemContext.DirForceDecompress, "dest-decompress", false, "force decompression of layers for dir: destinations")
rootCmd.PersistentFlags().BoolVar(&forceCompressionFormat, "dest-force-compression-format", false, "force compression of layers for dir: destinations")
rootCmd.PersistentFlags().StringVar(&compressionFormat, "dest-compress-format", "", "compression type")
rootCmd.PersistentFlags().IntVar(&compressionLevel, "dest-compress-level", 0, "compression level")
rootCmd.PersistentFlags().StringVar(&systemContext.AuthFilePath, "authfile", "", "registry credentials")
rootCmd.PersistentFlags().StringVar(&systemContext.LegacyFormatAuthFilePath, "legacy-format-authfile", "", "registry credentials in legacy format")
rootCmd.PersistentFlags().StringVar(&systemContext.DockerCompatAuthFilePath, "docker-compat-authfile", "", "registry credentials in docker-compatible format")

rootCmd.PersistentFlags().SetInterspersed(true)
if err := rootCmd.Execute(); err != nil {
os.Exit(1)
}
Expand Down
31 changes: 29 additions & 2 deletions tests/imgtype/imgtype.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ func main() {
rebuildm := flag.Bool("rebuild-manifest", false, "rebuild the manifest JSON")
showc := flag.Bool("show-config", false, "output the configuration JSON")
rebuildc := flag.Bool("rebuild-config", false, "rebuild the configuration JSON")
authFile := flag.String("authfile", "", "location of credentials for accessing registries")
legacyAuthFile := flag.String("legacy-format-authfile", "", "location of credentials for accessing registries in legacy format")
blobInfoCacheDir := flag.String("blob-info-cache-dir", "", "cache information about blobs in the specified directory instead of the default location")

certDir := flag.String("cert-dir", "", "location of certificates for use with registries")
dockerCompatAuthFile := flag.String("docker-compat-authfile", "", "location of credentials for accessing registries in docker format")
tlsVerify := flag.Bool("tls-verify", true, "use HTTPS with certificate verification when accessing registries")
flag.Parse()
logrus.SetLevel(logrus.ErrorLevel)
if debug != nil && *debug {
Expand All @@ -67,7 +74,7 @@ func main() {
default:
logrus.Errorf("unknown -expected-manifest-type value, expected either %q or %q or %q",
define.OCIv1ImageManifest, define.Dockerv2ImageManifest, "*")
return
os.Exit(1)
}
if root != nil {
storeOptions.GraphRoot = *root
Expand All @@ -91,10 +98,29 @@ func main() {
systemContext := &types.SystemContext{
SignaturePolicyPath: *policy,
}
if authFile != nil {
systemContext.AuthFilePath = *authFile
}
if legacyAuthFile != nil {
systemContext.LegacyFormatAuthFilePath = *legacyAuthFile
}
if blobInfoCacheDir != nil {
systemContext.BlobInfoCacheDir = *blobInfoCacheDir
}
if dockerCompatAuthFile != nil {
systemContext.DockerCompatAuthFilePath = *dockerCompatAuthFile
}
if certDir != nil {
systemContext.DockerCertPath = *certDir
}
if tlsVerify != nil {
systemContext.OCIInsecureSkipTLSVerify = !*tlsVerify
systemContext.DockerInsecureSkipTLSVerify = types.NewOptionalBool(!*tlsVerify)
}
args := flag.Args()
if len(args) == 0 {
flag.Usage()
return
os.Exit(1)
}
store, err := storage.GetStore(storeOptions)
if err != nil {
Expand All @@ -109,6 +135,7 @@ func main() {
if errors {
os.Exit(1)
}
os.Exit(0)
}()
for _, image := range args {
var ref types.ImageReference
Expand Down