This repository has been archived by the owner on Jan 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpush.go
84 lines (74 loc) · 1.59 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"io"
"os/exec"
"time"
"github.com/genuinetools/reg/registry"
"github.com/genuinetools/reg/repoutils"
)
func push(w io.Writer, c *config) error {
cmd := exec.Command(
"docker",
"push",
c.Docker.ImageAlias,
)
cmd.Stdout = w
cmd.Stderr = w
err := cmd.Run()
if err != nil {
return err
}
image, err := registry.ParseImage(c.Docker.Image)
if err != nil {
return err
}
alias, err := registry.ParseImage(c.Docker.ImageAlias)
if err != nil {
return err
}
r, err := createClient(
c.Docker.Auth.Username,
c.Docker.Auth.Password,
alias.Domain,
)
if err != nil {
return err
}
// STEP 1: get the manifest for the temporary (aliased)
// image tag.
manifest, err := r.Manifest(alias.Path, alias.Reference())
if err != nil {
return err
}
// STEP 2: upload the manifest with the user-defined
// image tag.
err = r.PutManifest(image.Path, image.Reference(), manifest)
if err != nil {
return err
}
// STEP 4: get the digest for the temporary (aliased)
// image tag.
digest, err := r.Digest(alias)
if err != nil {
return err
}
if err := alias.WithDigest(digest); err != nil {
return err
}
// STEP 5: delete the digest for the temporary (aliased)
// image tag.
return r.Delete(alias.Path, digest)
}
func createClient(username, password, domain string) (*registry.Registry, error) {
auth, err := repoutils.GetAuthConfig(username, password, domain)
if err != nil {
return nil, err
}
// Create the registry client.
return registry.New(auth, registry.Opt{
Insecure: false,
Debug: false,
SkipPing: false,
Timeout: time.Minute,
})
}