cloudapi: Add support for GCP as upload target
Add support for GCP as an upload target to the internal API. Extend the cloudapi to allow GCP as an upload target in the compose request. Regenerate the cloudapi go code. Added GCP-specific upload result component in the API definition, similar to AWS. It is not yet used, but it will be once returning a target-specific result from worker is supported. Add support for GCP upload target to the worker job implementation. Signed-off-by: Tomas Hozza <thozza@redhat.com>
This commit is contained in:
parent
ff95059748
commit
94d399f010
7 changed files with 251 additions and 36 deletions
|
|
@ -18,15 +18,17 @@ import (
|
|||
"github.com/osbuild/osbuild-composer/internal/target"
|
||||
"github.com/osbuild/osbuild-composer/internal/upload/awsupload"
|
||||
"github.com/osbuild/osbuild-composer/internal/upload/azure"
|
||||
"github.com/osbuild/osbuild-composer/internal/upload/gcp"
|
||||
"github.com/osbuild/osbuild-composer/internal/upload/koji"
|
||||
"github.com/osbuild/osbuild-composer/internal/upload/vmware"
|
||||
"github.com/osbuild/osbuild-composer/internal/worker"
|
||||
)
|
||||
|
||||
type OSBuildJobImpl struct {
|
||||
Store string
|
||||
Output string
|
||||
KojiServers map[string]koji.GSSAPICredentials
|
||||
Store string
|
||||
Output string
|
||||
KojiServers map[string]koji.GSSAPICredentials
|
||||
GCPCredsPath string
|
||||
}
|
||||
|
||||
func packageMetadataToSignature(pkg osbuild.RPMPackageMetadata) *string {
|
||||
|
|
@ -235,6 +237,51 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error {
|
|||
r = append(r, err)
|
||||
continue
|
||||
}
|
||||
case *target.GCPTargetOptions:
|
||||
if !osbuildOutput.Success {
|
||||
continue
|
||||
}
|
||||
|
||||
// Check if the credentials file was provided in the worker configuration,
|
||||
// otherwise let it up to the Google client library to authenticate
|
||||
var gcpCreds []byte
|
||||
if impl.GCPCredsPath != "" {
|
||||
gcpCreds, err = ioutil.ReadFile(impl.GCPCredsPath)
|
||||
if err != nil {
|
||||
r = append(r, err)
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
gcpCreds = nil
|
||||
}
|
||||
|
||||
g, err := gcp.New(gcpCreds)
|
||||
if err != nil {
|
||||
r = append(r, err)
|
||||
continue
|
||||
}
|
||||
|
||||
err = g.Upload(path.Join(outputDirectory, options.Filename), options.Bucket, options.Object)
|
||||
if err != nil {
|
||||
r = append(r, err)
|
||||
continue
|
||||
}
|
||||
|
||||
err = g.Import(options.Bucket, options.Object, t.ImageName, options.Os, options.Region)
|
||||
if err != nil {
|
||||
r = append(r, err)
|
||||
continue
|
||||
}
|
||||
|
||||
err = g.Share(t.ImageName, options.ShareWithAccounts)
|
||||
if err != nil {
|
||||
r = append(r, err)
|
||||
continue
|
||||
}
|
||||
// TODO: report back the information below, which is necessary to find and use the image
|
||||
// imageName := t.ImageName
|
||||
// projectID := gcp.GetProjectID()
|
||||
|
||||
case *target.KojiTargetOptions:
|
||||
// Koji for some reason needs TLS renegotiation enabled.
|
||||
// Clone the default http transport and enable renegotiation.
|
||||
|
|
|
|||
|
|
@ -83,6 +83,9 @@ func main() {
|
|||
KeyTab string `toml:"keytab"`
|
||||
} `toml:"kerberos,omitempty"`
|
||||
} `toml:"koji"`
|
||||
GCP struct {
|
||||
Credentials string `toml:"credentials"`
|
||||
} `toml:"gcp"`
|
||||
}
|
||||
var unix bool
|
||||
flag.BoolVar(&unix, "unix", false, "Interpret 'address' as a path to a unix domain socket instead of a network address")
|
||||
|
|
@ -153,9 +156,10 @@ func main() {
|
|||
|
||||
jobImpls := map[string]JobImplementation{
|
||||
"osbuild": &OSBuildJobImpl{
|
||||
Store: store,
|
||||
Output: output,
|
||||
KojiServers: kojiServers,
|
||||
Store: store,
|
||||
Output: output,
|
||||
KojiServers: kojiServers,
|
||||
GCPCredsPath: config.GCP.Credentials,
|
||||
},
|
||||
"osbuild-koji": &OSBuildKojiJobImpl{
|
||||
Store: store,
|
||||
|
|
|
|||
|
|
@ -65,6 +65,39 @@ type Customizations struct {
|
|||
Subscription *Subscription `json:"subscription,omitempty"`
|
||||
}
|
||||
|
||||
// GCPUploadRequestOptions defines model for GCPUploadRequestOptions.
|
||||
type GCPUploadRequestOptions struct {
|
||||
|
||||
// Name of an existing STANDARD Storage class Bucket.
|
||||
Bucket string `json:"bucket"`
|
||||
|
||||
// The name to use for the imported and shared Compute Node image.
|
||||
// The image name must be unique within the GCP project, which is used
|
||||
// for the OS image upload and import. If not specified a random
|
||||
// 'composer-api-<uuid>' string is used as the image name.
|
||||
ImageName *string `json:"image_name,omitempty"`
|
||||
|
||||
// The GCP region where the OS image will be imported to and shared from.
|
||||
// The value must be a valid GCP location. See https://cloud.google.com/storage/docs/locations.
|
||||
// If not specified, the multi-region location closest to the source
|
||||
// (source Storage Bucket location) is chosen automatically.
|
||||
Region *string `json:"region,omitempty"`
|
||||
|
||||
// List of valid Google accounts to share the imported Compute Node image with.
|
||||
// Each string must contain a specifier of the account type. Valid formats are:
|
||||
// - 'user:{emailid}': An email address that represents a specific
|
||||
// Google account. For example, 'alice@example.com'.
|
||||
// - 'serviceAccount:{emailid}': An email address that represents a
|
||||
// service account. For example, 'my-other-app@appspot.gserviceaccount.com'.
|
||||
// - 'group:{emailid}': An email address that represents a Google group.
|
||||
// For example, 'admins@example.com'.
|
||||
// - 'domain:{domain}': The G Suite domain (primary) that represents all
|
||||
// the users of that domain. For example, 'google.com' or 'example.com'.
|
||||
// If not specified, the imported Compute Node image is not shared with any
|
||||
// account.
|
||||
ShareWithAccounts *[]string `json:"share_with_accounts,omitempty"`
|
||||
}
|
||||
|
||||
// ImageRequest defines model for ImageRequest.
|
||||
type ImageRequest struct {
|
||||
Architecture string `json:"architecture"`
|
||||
|
|
@ -114,6 +147,7 @@ type UploadTypes string
|
|||
// List of UploadTypes
|
||||
const (
|
||||
UploadTypes_aws UploadTypes = "aws"
|
||||
UploadTypes_gcp UploadTypes = "gcp"
|
||||
)
|
||||
|
||||
// Version defines model for Version.
|
||||
|
|
@ -777,33 +811,43 @@ func HandlerFromMux(si ServerInterface, r chi.Router) http.Handler {
|
|||
// Base64 encoded, gzipped, json marshaled Swagger object
|
||||
var swaggerSpec = []string{
|
||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ew60O8pSyFnDbkI7wU24vUkoQFlmA6XMBfObfuFjxBkAj9i9a",
|
||||
"4dtIAlfq/JJSlwTNWHsL+tyu+12ZzqPPV02tJOhCckU0ZkMkwiJDO5uKxS63nA4EdahuasomR9MYI9p0",
|
||||
"7njQDLygdj715mwpt7xrKdcPumZ9qT79beFXQvS4jnZU7Ceou2qz+X8AAAD//7ZFVao+HgAA",
|
||||
}
|
||||
|
||||
// GetSwagger returns the Swagger specification corresponding to the generated code
|
||||
|
|
|
|||
|
|
@ -122,6 +122,15 @@ components:
|
|||
ami_id:
|
||||
type: string
|
||||
example: 'ami-0c830793775595d4b'
|
||||
GCPUploadStatus:
|
||||
type: object
|
||||
properties:
|
||||
project_id:
|
||||
type: string
|
||||
example: 'ascendant-braid-303513'
|
||||
image_name:
|
||||
type: string
|
||||
example: 'my-image'
|
||||
ComposeRequest:
|
||||
type: object
|
||||
required:
|
||||
|
|
@ -188,9 +197,10 @@ components:
|
|||
options:
|
||||
oneOf:
|
||||
- $ref: '#/components/schemas/AWSUploadRequestOptions'
|
||||
- $ref: '#/components/schemas/GCPUploadRequestOptions'
|
||||
UploadTypes:
|
||||
type: string
|
||||
enum: ['aws']
|
||||
enum: ['aws', 'gcp']
|
||||
AWSUploadRequestOptions:
|
||||
type: object
|
||||
required:
|
||||
|
|
@ -243,6 +253,59 @@ components:
|
|||
example: ['123456789012']
|
||||
items:
|
||||
type: string
|
||||
GCPUploadRequestOptions:
|
||||
type: object
|
||||
required:
|
||||
- bucket
|
||||
properties:
|
||||
region:
|
||||
type: string
|
||||
example: 'eu'
|
||||
description: |
|
||||
The GCP region where the OS image will be imported to and shared from.
|
||||
The value must be a valid GCP location. See https://cloud.google.com/storage/docs/locations.
|
||||
If not specified, the multi-region location closest to the source
|
||||
(source Storage Bucket location) is chosen automatically.
|
||||
bucket:
|
||||
type: string
|
||||
example: 'my-example-bucket'
|
||||
description: 'Name of an existing STANDARD Storage class Bucket.'
|
||||
# don't expose the os type for now
|
||||
# os:
|
||||
# type: string
|
||||
# example: 'rhel-8-byol'
|
||||
# description: 'OS of the disk image being imported needed for installation of GCP guest tools.'
|
||||
image_name:
|
||||
type: string
|
||||
example: 'my-image'
|
||||
description: |
|
||||
The name to use for the imported and shared Compute Node image.
|
||||
The image name must be unique within the GCP project, which is used
|
||||
for the OS image upload and import. If not specified a random
|
||||
'composer-api-<uuid>' string is used as the image name.
|
||||
share_with_accounts:
|
||||
type: array
|
||||
example: [
|
||||
'user:alice@example.com',
|
||||
'serviceAccount:my-other-app@appspot.gserviceaccount.com',
|
||||
'group:admins@example.com',
|
||||
'domain:example.com'
|
||||
]
|
||||
description: |
|
||||
List of valid Google accounts to share the imported Compute Node image with.
|
||||
Each string must contain a specifier of the account type. Valid formats are:
|
||||
- 'user:{emailid}': An email address that represents a specific
|
||||
Google account. For example, 'alice@example.com'.
|
||||
- 'serviceAccount:{emailid}': An email address that represents a
|
||||
service account. For example, 'my-other-app@appspot.gserviceaccount.com'.
|
||||
- 'group:{emailid}': An email address that represents a Google group.
|
||||
For example, 'admins@example.com'.
|
||||
- 'domain:{domain}': The G Suite domain (primary) that represents all
|
||||
the users of that domain. For example, 'google.com' or 'example.com'.
|
||||
If not specified, the imported Compute Node image is not shared with any
|
||||
account.
|
||||
items:
|
||||
type: string
|
||||
Customizations:
|
||||
type: object
|
||||
properties:
|
||||
|
|
|
|||
|
|
@ -204,9 +204,47 @@ func (server *Server) Compose(w http.ResponseWriter, r *http.Request) {
|
|||
t.ImageName = key
|
||||
}
|
||||
|
||||
targets = append(targets, t)
|
||||
} else if uploadRequest.Type == "gcp" {
|
||||
var gcpUploadOptions GCPUploadRequestOptions
|
||||
jsonUploadOptions, err := json.Marshal(uploadRequest.Options)
|
||||
if err != nil {
|
||||
http.Error(w, "Unable to marshal gcp upload request", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
err = json.Unmarshal(jsonUploadOptions, &gcpUploadOptions)
|
||||
if err != nil {
|
||||
http.Error(w, "Unable to unmarshal gcp upload request", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
var share []string
|
||||
if gcpUploadOptions.ShareWithAccounts != nil {
|
||||
share = *gcpUploadOptions.ShareWithAccounts
|
||||
}
|
||||
var region string
|
||||
if gcpUploadOptions.Region != nil {
|
||||
region = *gcpUploadOptions.Region
|
||||
}
|
||||
object := fmt.Sprintf("composer-api-%s", uuid.New().String())
|
||||
t := target.NewGCPTarget(&target.GCPTargetOptions{
|
||||
Filename: imageType.Filename(),
|
||||
Region: region,
|
||||
Os: "", // not exposed in cloudapi for now
|
||||
Bucket: gcpUploadOptions.Bucket,
|
||||
Object: object,
|
||||
ShareWithAccounts: share,
|
||||
})
|
||||
// Import will fail if an image with this name already exists
|
||||
if gcpUploadOptions.ImageName != nil {
|
||||
t.ImageName = *gcpUploadOptions.ImageName
|
||||
} else {
|
||||
t.ImageName = object
|
||||
}
|
||||
|
||||
targets = append(targets, t)
|
||||
} else {
|
||||
http.Error(w, "Unknown upload request type, only aws is supported", http.StatusBadRequest)
|
||||
http.Error(w, "Unknown upload request type, only 'aws' and 'gcp' is supported", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
|
|||
16
internal/target/gcp_target.go
Normal file
16
internal/target/gcp_target.go
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
package target
|
||||
|
||||
type GCPTargetOptions struct {
|
||||
Filename string `json:"filename"`
|
||||
Region string `json:"region"`
|
||||
Os string `json:"os"` // not exposed in cloudapi for now
|
||||
Bucket string `json:"bucket"`
|
||||
Object string `json:"object"`
|
||||
ShareWithAccounts []string `json:"shareWithAccounts"`
|
||||
}
|
||||
|
||||
func (GCPTargetOptions) isTargetOptions() {}
|
||||
|
||||
func NewGCPTarget(options *GCPTargetOptions) *Target {
|
||||
return newTarget("org.osbuild.gcp", options)
|
||||
}
|
||||
|
|
@ -3,9 +3,10 @@ package target
|
|||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/osbuild/osbuild-composer/internal/common"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Target struct {
|
||||
|
|
@ -68,6 +69,8 @@ func UnmarshalTargetOptions(targetName string, rawOptions json.RawMessage) (Targ
|
|||
options = new(AzureTargetOptions)
|
||||
case "org.osbuild.aws":
|
||||
options = new(AWSTargetOptions)
|
||||
case "org.osbuild.gcp":
|
||||
options = new(GCPTargetOptions)
|
||||
case "org.osbuild.local":
|
||||
options = new(LocalTargetOptions)
|
||||
case "org.osbuild.koji":
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue