1
1
package main
2
2
3
3
import (
4
+ "context"
4
5
"fmt"
5
6
"os"
7
+ "strings"
6
8
7
9
"github.com/sirupsen/logrus"
8
10
"github.com/urfave/cli/v2"
@@ -20,10 +22,10 @@ var registryRepo = &repo.Entry{
20
22
var registryImageComponents = map [string ]addonComponent {
21
23
"docker.io/library/registry" : {
22
24
name : "registry" ,
23
- getCustomImageName : func (opts addonComponentOptions ) (string , error ) {
24
- // TODO (@salah): build with apko once distribution is out of beta: https://github.com/wolfi-dev/os/blob/main/distribution.yaml
25
- return "docker.io/library/registry:2.8.3" , nil
25
+ getWolfiPackageName : func (opts addonComponentOptions ) string {
26
+ return "distribution"
26
27
},
28
+ upstreamVersionInputOverride : "INPUT_REGISTRY_VERSION" ,
27
29
},
28
30
}
29
31
@@ -33,70 +35,109 @@ var updateRegistryAddonCommand = &cli.Command{
33
35
UsageText : environmentUsageText ,
34
36
Action : func (c * cli.Context ) error {
35
37
logrus .Infof ("updating registry addon" )
36
- latest , err := LatestChartVersion (registryRepo , "docker-registry" )
37
- if err != nil {
38
- return fmt .Errorf ("unable to get the latest registry version: %v" , err )
39
- }
40
- logrus .Printf ("latest registry chart version: %s" , latest )
41
38
42
- current := registry .Metadata
43
- if current .Version == latest && ! c .Bool ("force" ) {
44
- logrus .Infof ("registry version is already up-to-date" )
45
- return nil
39
+ nextChartVersion := os .Getenv ("INPUT_REGISTRY_CHART_VERSION" )
40
+ if nextChartVersion != "" {
41
+ logrus .Infof ("using input override from INPUT_REGISTRY_CHART_VERSION: %s" , nextChartVersion )
42
+ } else {
43
+ logrus .Infof ("fetching the latest registry chart version" )
44
+ latest , err := LatestChartVersion (registryRepo , "docker-registry" )
45
+ if err != nil {
46
+ return fmt .Errorf ("failed to get the latest registry chart version: %v" , err )
47
+ }
48
+ nextChartVersion = latest
49
+ logrus .Printf ("latest registry chart version: %s" , latest )
46
50
}
51
+ nextChartVersion = strings .TrimPrefix (nextChartVersion , "v" )
47
52
48
- logrus .Infof ("mirroring registry chart version %s" , latest )
49
- if err := MirrorChart (registryRepo , "docker-registry" , latest ); err != nil {
50
- return fmt .Errorf ("unable to mirror chart: %w" , err )
53
+ current := registry .Metadata
54
+ if current .Version == nextChartVersion && ! c .Bool ("force" ) {
55
+ logrus .Infof ("registry chart version is already up-to-date" )
56
+ } else {
57
+ logrus .Infof ("mirroring registry chart version %s" , nextChartVersion )
58
+ if err := MirrorChart (registryRepo , "docker-registry" , nextChartVersion ); err != nil {
59
+ return fmt .Errorf ("failed to mirror registry chart: %v" , err )
60
+ }
51
61
}
52
62
53
63
upstream := fmt .Sprintf ("%s/docker-registry" , os .Getenv ("CHARTS_DESTINATION" ))
54
- newmeta := release.AddonMetadata {
55
- Version : latest ,
56
- Location : fmt .Sprintf ("oci://proxy.replicated.com/anonymous/%s" , upstream ),
57
- Images : make (map [string ]release.AddonImage ),
58
- }
64
+ withproto := fmt .Sprintf ("oci://proxy.replicated.com/anonymous/%s" , upstream )
59
65
60
- values , err := release .GetValuesWithOriginalImages ("registry" )
61
- if err != nil {
62
- return fmt .Errorf ("unable to get openebs values: %v" , err )
63
- }
66
+ logrus .Infof ("updating registry images" )
64
67
65
- logrus .Infof ("extracting images from chart" )
66
- withproto := fmt .Sprintf ("oci://%s" , upstream )
67
- images , err := GetImagesFromOCIChart (withproto , "docker-registry" , latest , values )
68
+ err := updateRegistryAddonImages (c .Context , withproto , nextChartVersion )
68
69
if err != nil {
69
- return fmt .Errorf ("failed to get images from chart : %w" , err )
70
+ return fmt .Errorf ("failed to update registry images : %w" , err )
70
71
}
71
72
72
- for _ , image := range images {
73
- component , ok := registryImageComponents [RemoveTagFromImage (image )]
74
- if ! ok {
75
- return fmt .Errorf ("no component found for image %s" , image )
76
- }
77
- repo , tag , err := component .resolveImageRepoAndTag (c .Context , image )
78
- if err != nil {
79
- return fmt .Errorf ("failed to resolve image and tag for %s: %w" , image , err )
80
- }
81
- newmeta .Images [component .name ] = release.AddonImage {
82
- Repo : repo ,
83
- Tag : tag ,
84
- }
85
- }
73
+ logrus .Infof ("successfully updated registry addon" )
86
74
87
- logrus .Infof ("saving addon manifest" )
88
- newmeta .ReplaceImages = true
89
- if err := newmeta .Save ("registry" ); err != nil {
90
- return fmt .Errorf ("failed to save metadata: %w" , err )
91
- }
75
+ return nil
76
+ },
77
+ }
92
78
93
- logrus .Infof ("rendering values for registry ha" )
94
- err = newmeta .RenderValues ("registry" , "values-ha.tpl.yaml" , "values-ha.yaml" )
79
+ var updateRegistryImagesCommand = & cli.Command {
80
+ Name : "registry" ,
81
+ Usage : "Updates the registry images" ,
82
+ UsageText : environmentUsageText ,
83
+ Action : func (c * cli.Context ) error {
84
+ logrus .Infof ("updating registry images" )
85
+
86
+ current := registry .Metadata
87
+
88
+ err := updateRegistryAddonImages (c .Context , current .Location , current .Version )
95
89
if err != nil {
96
- return fmt .Errorf ("failed to render values-ha : %w" , err )
90
+ return fmt .Errorf ("failed to update registry images : %w" , err )
97
91
}
98
92
99
- logrus .Infof ("successfully updated registry addon" )
93
+ logrus .Infof ("successfully updated registry images" )
94
+
100
95
return nil
101
96
},
102
97
}
98
+
99
+ func updateRegistryAddonImages (ctx context.Context , chartURL string , chartVersion string ) error {
100
+ newmeta := release.AddonMetadata {
101
+ Version : chartVersion ,
102
+ Location : chartURL ,
103
+ Images : make (map [string ]release.AddonImage ),
104
+ }
105
+
106
+ values , err := release .GetValuesWithOriginalImages ("registry" )
107
+ if err != nil {
108
+ return fmt .Errorf ("failed to get registry values: %v" , err )
109
+ }
110
+
111
+ logrus .Infof ("extracting images from chart version %s" , chartVersion )
112
+ images , err := GetImagesFromOCIChart (chartURL , "docker-registry" , chartVersion , values )
113
+ if err != nil {
114
+ return fmt .Errorf ("failed to get images from registry chart: %w" , err )
115
+ }
116
+
117
+ if err := ApkoLogin (); err != nil {
118
+ return fmt .Errorf ("failed to apko login: %w" , err )
119
+ }
120
+
121
+ for _ , image := range images {
122
+ component , ok := registryImageComponents [RemoveTagFromImage (image )]
123
+ if ! ok {
124
+ return fmt .Errorf ("no component found for image %s" , image )
125
+ }
126
+ repo , tag , err := component .resolveImageRepoAndTag (ctx , image )
127
+ if err != nil {
128
+ return fmt .Errorf ("failed to resolve image and tag for %s: %w" , image , err )
129
+ }
130
+ newmeta .Images [component .name ] = release.AddonImage {
131
+ Repo : repo ,
132
+ Tag : tag ,
133
+ }
134
+ }
135
+
136
+ logrus .Infof ("saving addon manifest" )
137
+ newmeta .ReplaceImages = true
138
+ if err := newmeta .Save ("registry" ); err != nil {
139
+ return fmt .Errorf ("failed to save metadata: %w" , err )
140
+ }
141
+
142
+ return nil
143
+ }
0 commit comments