2021-05-26 04:44:52 +10:00
|
|
|
/*
|
|
|
|
Copyright 2018 Google LLC All Rights Reserved.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
2019-03-14 14:23:47 -04:00
|
|
|
|
2019-04-26 15:56:15 -07:00
|
|
|
package commands
|
2019-03-14 14:23:47 -04:00
|
|
|
|
|
|
|
import (
|
2019-11-10 01:23:09 +08:00
|
|
|
"context"
|
2019-03-14 14:23:47 -04:00
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/google/go-containerregistry/pkg/name"
|
2019-03-21 19:07:56 -04:00
|
|
|
"github.com/google/ko/pkg/build"
|
|
|
|
"github.com/google/ko/pkg/publish"
|
2019-03-14 14:23:47 -04:00
|
|
|
)
|
|
|
|
|
2021-05-26 04:44:52 +10:00
|
|
|
// PublishImages publishes images
|
|
|
|
func PublishImages(ctx context.Context, importpaths []string, pub publish.Interface, b build.Interface) (map[string]name.Reference, error) {
|
|
|
|
return publishImages(ctx, importpaths, pub, b)
|
|
|
|
}
|
|
|
|
|
2019-11-10 01:23:09 +08:00
|
|
|
func publishImages(ctx context.Context, importpaths []string, pub publish.Interface, b build.Interface) (map[string]name.Reference, error) {
|
2019-03-14 14:23:47 -04:00
|
|
|
imgs := make(map[string]name.Reference)
|
|
|
|
for _, importpath := range importpaths {
|
2021-06-11 01:29:30 +10:00
|
|
|
importpath, err := b.QualifyImport(importpath)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2020-05-03 18:42:51 -07:00
|
|
|
}
|
2020-10-31 12:55:28 -04:00
|
|
|
if err := b.IsSupportedReference(importpath); err != nil {
|
2021-11-05 13:26:09 -04:00
|
|
|
return nil, fmt.Errorf("importpath %q is not supported: %w", importpath, err)
|
2019-03-14 14:23:47 -04:00
|
|
|
}
|
|
|
|
|
2019-11-10 01:23:09 +08:00
|
|
|
img, err := b.Build(ctx, importpath)
|
2019-03-14 14:23:47 -04:00
|
|
|
if err != nil {
|
2021-11-05 13:26:09 -04:00
|
|
|
return nil, fmt.Errorf("error building %q: %w", importpath, err)
|
2019-03-14 14:23:47 -04:00
|
|
|
}
|
2020-12-21 11:47:05 -08:00
|
|
|
ref, err := pub.Publish(ctx, img, importpath)
|
2019-03-14 14:23:47 -04:00
|
|
|
if err != nil {
|
2021-11-05 13:26:09 -04:00
|
|
|
return nil, fmt.Errorf("error publishing %s: %w", importpath, err)
|
2019-03-14 14:23:47 -04:00
|
|
|
}
|
|
|
|
imgs[importpath] = ref
|
|
|
|
}
|
2019-04-30 13:08:54 -05:00
|
|
|
return imgs, nil
|
2019-03-14 14:23:47 -04:00
|
|
|
}
|