mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-12 10:55:20 +02:00
8dc2a1bfb4
* imagePushToRegistry new step * adding copy and push functionality * including only copy correctly * groovy step for imagePushToRegistry * create .docker folder * imagePushToRegistry new step * adding copy and push functionality * including only copy correctly * groovy step for imagePushToRegistry * create .docker folder * fix CopyImage * test * test * Correct docker config path * Update * Update * Update * Update * Update * Use creds from Vault * Use creds from Vault * Use creds from Vault * Use creds from Vault * Test * Comment some logic * Test: move regexp logic * Test * Update * Update * Clean up * Update * Update * Update interface * Rename function * imagePushToRegistry: small refactoring (#4688) * imagePushToRegistry new step * adding copy and push functionality * including only copy correctly * groovy step for imagePushToRegistry * create .docker folder * Correct docker config path * Update * Update * Update * Update * Update * Use creds from Vault * Use creds from Vault * Use creds from Vault * Use creds from Vault * Test * Comment some logic * Test: move regexp logic * Test * Update * Update * Clean up * Update * Update --------- Co-authored-by: Keshav <anil.keshav@sap.com> Co-authored-by: Muhammadali Nazarov <muhammadalinazarov@gmail.com> * Update step yaml file * Update interface * Rename func * Update tests * Update interface, create mock methods, update tests * Update mock * Add md file * Fix groovy doc, unit test, go unit test * Update * Add unit tests * Support tagLatest param * Fetch source creds from Vault * Update yaml file * Support multiple images * Update test * Support copy images in parallel * Update yaml * Clean up * Return err if no creds provided * Fix tests * Add err msg * Add debug log * Do not use CPE for targetImages * Support platform * Delete Jenkins specific creds * Update groovy: do not handle Jenkins creds * Delete unused code * Fix: Support platform * Fix: Support platform * Apply suggestion from code review Co-authored-by: Egor Balakin <14162703+m1ron0xFF@users.noreply.github.com> * Apply suggestion from code review Co-authored-by: Egor Balakin <14162703+m1ron0xFF@users.noreply.github.com> * Add tests for parseDockerImageName * Add comment that tagArtifactVersion is not supported yet * Set limit of running goroutines * Fix: Set limit of running goroutines * The tagArtifactVersion is not supported yet --------- Co-authored-by: Muhammadali Nazarov <muhammadalinazarov@gmail.com> Co-authored-by: Egor Balakin <egor.balakin@sap.com> Co-authored-by: Vyacheslav Starostin <vyacheslav.starostin@sap.com> Co-authored-by: Vyacheslav Starostin <32613074+vstarostin@users.noreply.github.com> Co-authored-by: Egor Balakin <14162703+m1ron0xFF@users.noreply.github.com>
41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
package docker
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/google/go-containerregistry/pkg/crane"
|
|
v1 "github.com/google/go-containerregistry/pkg/v1"
|
|
)
|
|
|
|
type CraneUtilsBundle struct{}
|
|
|
|
func (c *CraneUtilsBundle) CopyImage(ctx context.Context, src, dest, platform string) error {
|
|
p, err := parsePlatform(platform)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return crane.Copy(src, dest, crane.WithContext(ctx), crane.WithPlatform(p))
|
|
}
|
|
|
|
func (c *CraneUtilsBundle) PushImage(ctx context.Context, im v1.Image, dest, platform string) error {
|
|
p, err := parsePlatform(platform)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return crane.Push(im, dest, crane.WithContext(ctx), crane.WithPlatform(p))
|
|
}
|
|
|
|
func (c *CraneUtilsBundle) LoadImage(ctx context.Context, src string) (v1.Image, error) {
|
|
return crane.Load(src, crane.WithContext(ctx))
|
|
}
|
|
|
|
// parsePlatform is a wrapper for v1.ParsePlatform. It is necessary because
|
|
// v1.ParsePlatform returns an empty struct when the platform is equal to an empty string,
|
|
// whereas we expect 'nil'
|
|
func parsePlatform(p string) (*v1.Platform, error) {
|
|
if p == "" {
|
|
return nil, nil
|
|
}
|
|
return v1.ParsePlatform(p)
|
|
}
|