-
Notifications
You must be signed in to change notification settings - Fork 11
/
push.go
62 lines (52 loc) · 1.46 KB
/
push.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package cnab
import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"github.com/deislabs/cnab-go/bundle"
"github.com/docker/cnab-to-oci/remotes"
"github.com/docker/distribution/reference"
"github.com/docker/docker/client"
log "github.com/sirupsen/logrus"
)
// Push pushes a bundle to an OCI registry
func Push(bundleFile, ref string) error {
buf, err := ioutil.ReadFile(bundleFile)
if err != nil {
return fmt.Errorf("cannot read bundle file: %v", err)
}
var b bundle.Bundle
if err = json.Unmarshal(buf, &b); err != nil {
return err
}
resolver := createResolver(nil)
n, err := reference.ParseNormalizedNamed(ref)
if err != nil {
return err
}
cli, err := client.NewClientWithOpts(client.FromEnv)
if err != nil {
return err
}
fixupOpts := []remotes.FixupOption{
remotes.WithEventCallback(displayEvent),
remotes.WithInvocationImagePlatforms(nil),
// we explicitly DO NOT want to update the bundle file after the trust data has been pushed
// remotes.WithAutoBundleUpdate(),
remotes.WithPushImages(cli, os.Stdout),
remotes.WithComponentImagePlatforms(nil),
}
relocationMap, err := remotes.FixupBundle(context.Background(), &b, n, resolver, fixupOpts...)
if err != nil {
return err
}
log.Infof("Generated relocation map: %#v", relocationMap)
d, err := remotes.Push(context.Background(), &b, relocationMap, n, resolver, true)
if err != nil {
return err
}
log.Infof("Pushed successfully, with digest %q\n", d.Digest)
return nil
}