| 
									
										
										
										
											2017-02-11 00:48:15 +08:00
										 |  |  | package buildah | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import ( | 
					
						
							| 
									
										
										
										
											2017-05-09 23:56:44 +08:00
										 |  |  | 	"io" | 
					
						
							| 
									
										
										
										
											2018-10-23 18:42:35 +08:00
										 |  |  | 	"os" | 
					
						
							|  |  |  | 	"path/filepath" | 
					
						
							| 
									
										
										
										
											2018-10-03 01:48:45 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-06 19:40:34 +08:00
										 |  |  | 	"github.com/containers/common/pkg/unshare" | 
					
						
							| 
									
										
										
										
											2019-10-26 05:19:30 +08:00
										 |  |  | 	cp "github.com/containers/image/v5/copy" | 
					
						
							|  |  |  | 	"github.com/containers/image/v5/types" | 
					
						
							| 
									
										
										
										
											2019-03-14 04:03:13 +08:00
										 |  |  | 	"github.com/containers/storage" | 
					
						
							| 
									
										
										
										
											2017-02-11 00:48:15 +08:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-24 00:10:17 +08:00
										 |  |  | const ( | 
					
						
							|  |  |  | 	// OCI used to define the "oci" image format
 | 
					
						
							|  |  |  | 	OCI = "oci" | 
					
						
							|  |  |  | 	// DOCKER used to define the "docker" image format
 | 
					
						
							|  |  |  | 	DOCKER = "docker" | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-16 01:23:38 +08:00
										 |  |  | func getCopyOptions(store storage.Store, reportWriter io.Writer, sourceSystemContext *types.SystemContext, destinationSystemContext *types.SystemContext, manifestType string, removeSignatures bool, addSigner string) *cp.Options { | 
					
						
							| 
									
										
										
										
											2019-03-14 04:03:13 +08:00
										 |  |  | 	sourceCtx := getSystemContext(store, nil, "") | 
					
						
							| 
									
										
										
										
											2018-10-03 01:48:45 +08:00
										 |  |  | 	if sourceSystemContext != nil { | 
					
						
							|  |  |  | 		*sourceCtx = *sourceSystemContext | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-14 04:03:13 +08:00
										 |  |  | 	destinationCtx := getSystemContext(store, nil, "") | 
					
						
							| 
									
										
										
										
											2018-10-03 01:48:45 +08:00
										 |  |  | 	if destinationSystemContext != nil { | 
					
						
							|  |  |  | 		*destinationCtx = *destinationSystemContext | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-06-05 21:42:30 +08:00
										 |  |  | 	return &cp.Options{ | 
					
						
							| 
									
										
										
										
											2017-11-10 01:52:50 +08:00
										 |  |  | 		ReportWriter:          reportWriter, | 
					
						
							| 
									
										
										
										
											2018-10-03 01:48:45 +08:00
										 |  |  | 		SourceCtx:             sourceCtx, | 
					
						
							|  |  |  | 		DestinationCtx:        destinationCtx, | 
					
						
							| 
									
										
										
										
											2017-11-10 01:52:50 +08:00
										 |  |  | 		ForceManifestMIMEType: manifestType, | 
					
						
							| 
									
										
										
										
											2020-01-16 01:23:38 +08:00
										 |  |  | 		RemoveSignatures:      removeSignatures, | 
					
						
							|  |  |  | 		SignBy:                addSigner, | 
					
						
							| 
									
										
										
										
											2017-05-09 23:56:44 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-02-11 00:48:15 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-14 04:03:13 +08:00
										 |  |  | func getSystemContext(store storage.Store, defaults *types.SystemContext, signaturePolicyPath string) *types.SystemContext { | 
					
						
							| 
									
										
										
										
											2017-02-11 00:48:15 +08:00
										 |  |  | 	sc := &types.SystemContext{} | 
					
						
							| 
									
										
										
										
											2017-06-29 05:07:58 +08:00
										 |  |  | 	if defaults != nil { | 
					
						
							|  |  |  | 		*sc = *defaults | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-02-11 00:48:15 +08:00
										 |  |  | 	if signaturePolicyPath != "" { | 
					
						
							|  |  |  | 		sc.SignaturePolicyPath = signaturePolicyPath | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-03-14 04:03:13 +08:00
										 |  |  | 	if store != nil { | 
					
						
							|  |  |  | 		if sc.BlobInfoCacheDir == "" { | 
					
						
							|  |  |  | 			sc.BlobInfoCacheDir = filepath.Join(store.GraphRoot(), "cache") | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-03-25 18:23:56 +08:00
										 |  |  | 		if sc.SystemRegistriesConfPath == "" && unshare.IsRootless() { | 
					
						
							| 
									
										
										
										
											2019-03-14 04:03:13 +08:00
										 |  |  | 			userRegistriesFile := filepath.Join(store.GraphRoot(), "registries.conf") | 
					
						
							|  |  |  | 			if _, err := os.Stat(userRegistriesFile); err == nil { | 
					
						
							|  |  |  | 				sc.SystemRegistriesConfPath = userRegistriesFile | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-10-23 18:42:35 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-02-11 00:48:15 +08:00
										 |  |  | 	return sc | 
					
						
							|  |  |  | } |