cloudapi: add support for uploading to a container registry

Worker
------
Add configuration for the default container registry.
Use the default container registry if not provided as part
of the image name.
When using the default registry use the configured values
Return the image url as part of the result.

Composer Worker API
-------------------
Add `ContainerTargetResultOptions` to return the image url

Composer API
------------
Add UploadOptions to allow setting of the image name and tag
Add UploadStatus to return the url of the uploaded image

Co-Developed-By: Christian Kellner <christian@kellner.me>
This commit is contained in:
Ygal Blum 2022-07-26 14:45:52 +03:00 committed by Tom Gundersen
parent 14208d872b
commit 3231aabbc0
9 changed files with 277 additions and 130 deletions

View file

@ -344,8 +344,6 @@ func (h *apiHandlers) PostCompose(ctx echo.Context) error {
fallthrough
case ImageTypesEdgeInstaller:
fallthrough
case ImageTypesEdgeContainer:
fallthrough
case ImageTypesEdgeCommit:
var awsS3UploadOptions AWSS3UploadOptions
jsonUploadOptions, err := json.Marshal(*ir.UploadOptions)
@ -365,6 +363,22 @@ func (h *apiHandlers) PostCompose(ctx echo.Context) error {
t.ImageName = key
t.OsbuildArtifact.ExportFilename = imageType.Filename()
irTarget = t
case ImageTypesEdgeContainer:
var containerUploadOptions ContainerUploadOptions
jsonUploadOptions, err := json.Marshal(*ir.UploadOptions)
if err != nil {
return HTTPError(ErrorJSONMarshallingError)
}
err = json.Unmarshal(jsonUploadOptions, &containerUploadOptions)
if err != nil {
return HTTPError(ErrorJSONUnMarshallingError)
}
t := target.NewContainerTarget(&target.ContainerTargetOptions{})
t.ImageName = fmt.Sprintf("%s:%s", containerUploadOptions.Name, containerUploadOptions.Tag)
t.OsbuildArtifact.ExportFilename = imageType.Filename()
irTarget = t
case ImageTypesGcp:
fallthrough
@ -544,6 +558,14 @@ func targetResultToUploadStatus(t *target.TargetResult) (*UploadStatus, error) {
uploadOptions = AzureUploadStatus{
ImageName: gcpOptions.ImageName,
}
case target.TargetNameContainer:
uploadType = UploadTypesContainer
containerOptions := t.Options.(*target.ContainerTargetResultOptions)
uploadOptions = ContainerUploadStatus{
Url: containerOptions.URL,
Digest: containerOptions.Digest,
}
default:
return nil, fmt.Errorf("unknown upload target: %s", t.Name)
}