Skip to content

Commit bd1a2a3

Browse files
authored
Merge pull request #252 from nicholasSUSE/fix-push-oci
Fix push oci
2 parents 00ee786 + 2661ebd commit bd1a2a3

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

pkg/auto/oci.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ func UpdateOCI(ctx context.Context, rootFs billy.Filesystem, ociDNS, ociUser, oc
5454
}
5555

5656
func setupOCI(ctx context.Context, ociDNS, ociUser, ociPass string, debug bool) (*oci, error) {
57+
// Strip http:// or https:// scheme if present
58+
ociDNS = strings.TrimPrefix(ociDNS, "https://")
59+
ociDNS = strings.TrimPrefix(ociDNS, "http://")
60+
5761
var err error
5862
o := &oci{
5963
DNS: ociDNS,
@@ -128,13 +132,24 @@ func setupHelm(ctx context.Context, ociDNS, ociUser, ociPass string, debug bool)
128132

129133
// Production code with Secure Mode and authentication
130134
default:
131-
regClient, err = registry.NewClient(registry.ClientOptDebug(false))
135+
logger.Log(ctx, slog.LevelInfo, "production mode")
136+
regClient, err = registry.NewRegistryClientWithTLS(
137+
os.Stdout, // output writer
138+
"", // certFile (none)
139+
"", // keyFile (none)
140+
"", // caFile (none)
141+
false, // insecureSkipTLSverify
142+
"", // registryConfig (use default)
143+
false, // debug
144+
)
132145
if err != nil {
146+
logger.Log(ctx, slog.LevelError, "failed to create registry client")
133147
return nil, err
134148
}
135149
if err = regClient.Login(registryHost,
136150
registry.LoginOptInsecure(false),
137151
registry.LoginOptBasicAuth(ociUser, ociPass)); err != nil {
152+
logger.Log(ctx, slog.LevelError, "failed to login")
138153
return nil, err
139154
}
140155
}
@@ -181,7 +196,6 @@ func (o *oci) update(ctx context.Context, release *options.ReleaseOptions) ([]st
181196
// Never overwrite a previously released chart!
182197
exists, err := o.checkAsset(ctx, o.helmClient, o.DNS, chart, version)
183198
if err != nil {
184-
logger.Log(ctx, slog.LevelError, "failed to check registry for asset", slog.String("asset", asset))
185199
return pushedAssets, err
186200
}
187201
if exists {
@@ -261,7 +275,7 @@ func checkAsset(ctx context.Context, helmClient *registry.Client, ociDNS, chart,
261275
logger.Log(ctx, slog.LevelDebug, "asset does not exist at registry", slog.String("chart", chart))
262276
return false, nil
263277
}
264-
logger.Err(err)
278+
logger.Log(ctx, slog.LevelError, "failed to check registry for asset", slog.String("asset", chart))
265279
return false, err
266280
}
267281

0 commit comments

Comments
 (0)