@@ -13,6 +13,7 @@ import (
13
13
14
14
"github.com/docker/distribution/reference"
15
15
"github.com/gitpod-io/gitpod/installer/pkg/common"
16
+ configv1 "github.com/gitpod-io/gitpod/installer/pkg/config/v1"
16
17
"github.com/spf13/cobra"
17
18
)
18
19
@@ -61,67 +62,11 @@ image to the "target" repo`,
61
62
return err
62
63
}
63
64
64
- // Throw error if set to the default Gitpod repository
65
- if cfg .Repository == common .GitpodContainerRegistry {
66
- return fmt .Errorf ("cannot mirror images to repository %s" , common .GitpodContainerRegistry )
67
- }
68
-
69
- // Get the target repository from the config
70
- targetRepo := strings .TrimRight (cfg .Repository , "/" )
71
-
72
- // Use the default Gitpod registry to pull from
73
- cfg .Repository = common .GitpodContainerRegistry
74
-
75
- k8s , err := renderKubernetesObjects (cfgVersion , cfg )
65
+ images , err := generateMirrorList (cfgVersion , cfg )
76
66
if err != nil {
77
67
return err
78
68
}
79
69
80
- // Map of images used for deduping
81
- allImages := make (map [string ]bool )
82
-
83
- rawImages := make ([]string , 0 )
84
- for _ , item := range k8s {
85
- rawImages = append (rawImages , getPodImages (item )... )
86
- rawImages = append (rawImages , getGenericImages (item )... )
87
- }
88
-
89
- images := make ([]mirrorListRepo , 0 )
90
- for _ , img := range rawImages {
91
- // Dedupe
92
- if _ , ok := allImages [img ]; ok {
93
- continue
94
- }
95
- allImages [img ] = true
96
-
97
- // Convert target
98
- target := img
99
- if strings .Contains (img , cfg .Repository ) {
100
- // This is the Gitpod registry
101
- target = strings .Replace (target , cfg .Repository , targetRepo , 1 )
102
- } else if ! mirrorListOpts .ExcludeThirdParty {
103
- // Amend third-party images - remove the first part
104
- thirdPartyImg := strings .Join (strings .Split (img , "/" )[1 :], "/" )
105
- target = fmt .Sprintf ("%s/%s" , targetRepo , thirdPartyImg )
106
- } else {
107
- // Excluding third-party images - just skip this one
108
- continue
109
- }
110
-
111
- images = append (images , mirrorListRepo {
112
- Original : img ,
113
- Target : target ,
114
- })
115
- }
116
-
117
- // Sort it by the Original
118
- sort .Slice (images , func (i , j int ) bool {
119
- scoreI := images [i ].Original
120
- scoreJ := images [j ].Original
121
-
122
- return scoreI < scoreJ
123
- })
124
-
125
70
fc , err := common .ToJSONString (images )
126
71
if err != nil {
127
72
return err
@@ -140,6 +85,71 @@ func init() {
140
85
mirrorListCmd .Flags ().StringVarP (& mirrorListOpts .ConfigFN , "config" , "c" , os .Getenv ("GITPOD_INSTALLER_CONFIG" ), "path to the config file" )
141
86
}
142
87
88
+ func generateMirrorList (cfgVersion string , cfg * configv1.Config ) ([]mirrorListRepo , error ) {
89
+ // Throw error if set to the default Gitpod repository
90
+ if cfg .Repository == common .GitpodContainerRegistry {
91
+ return nil , fmt .Errorf ("cannot mirror images to repository %s" , common .GitpodContainerRegistry )
92
+ }
93
+
94
+ // Get the target repository from the config
95
+ targetRepo := strings .TrimRight (cfg .Repository , "/" )
96
+
97
+ // Use the default Gitpod registry to pull from
98
+ cfg .Repository = common .GitpodContainerRegistry
99
+
100
+ k8s , err := renderKubernetesObjects (cfgVersion , cfg )
101
+ if err != nil {
102
+ return nil , err
103
+ }
104
+
105
+ // Map of images used for deduping
106
+ allImages := make (map [string ]bool )
107
+
108
+ rawImages := make ([]string , 0 )
109
+ for _ , item := range k8s {
110
+ rawImages = append (rawImages , getPodImages (item )... )
111
+ rawImages = append (rawImages , getGenericImages (item )... )
112
+ }
113
+
114
+ images := make ([]mirrorListRepo , 0 )
115
+ for _ , img := range rawImages {
116
+ // Dedupe
117
+ if _ , ok := allImages [img ]; ok {
118
+ continue
119
+ }
120
+ allImages [img ] = true
121
+
122
+ // Convert target
123
+ target := img
124
+ if strings .Contains (img , cfg .Repository ) {
125
+ // This is the Gitpod registry
126
+ target = strings .Replace (target , cfg .Repository , targetRepo , 1 )
127
+ } else if ! mirrorListOpts .ExcludeThirdParty {
128
+ // Amend third-party images - remove the first part
129
+ thirdPartyImg := strings .Join (strings .Split (img , "/" )[1 :], "/" )
130
+ target = fmt .Sprintf ("%s/%s" , targetRepo , thirdPartyImg )
131
+ } else {
132
+ // Excluding third-party images - just skip this one
133
+ continue
134
+ }
135
+
136
+ images = append (images , mirrorListRepo {
137
+ Original : img ,
138
+ Target : target ,
139
+ })
140
+ }
141
+
142
+ // Sort it by the Original
143
+ sort .Slice (images , func (i , j int ) bool {
144
+ scoreI := images [i ].Original
145
+ scoreJ := images [j ].Original
146
+
147
+ return scoreI < scoreJ
148
+ })
149
+
150
+ return images , nil
151
+ }
152
+
143
153
// getGenericImages this is a bit brute force - anything starting "docker.io" or with Gitpod repo is found
144
154
// this will be in ConfigMaps and could be anything, so will need cleaning up
145
155
func getGenericImages (k8sObj string ) []string {
0 commit comments