constellation/hack/build-manifest/main.go
Thomas Tendyck bd63aa3c6b add license headers
sed -i '1i/*\nCopyright (c) Edgeless Systems GmbH\n\nSPDX-License-Identifier: AGPL-3.0-only\n*/\n' `grep -rL --include='*.go' 'DO NOT EDIT'`
gofumpt -w .
2022-09-05 09:17:25 +02:00

66 lines
1.6 KiB
Go

/*
Copyright (c) Edgeless Systems GmbH
SPDX-License-Identifier: AGPL-3.0-only
*/
package main
import (
"context"
"encoding/json"
"os"
"github.com/edgelesssys/constellation/hack/build-manifest/azure"
"github.com/edgelesssys/constellation/hack/build-manifest/gcp"
"github.com/edgelesssys/constellation/internal/logger"
"go.uber.org/zap/zapcore"
)
const (
AzureSubscriptionIDEnv = "AZURE_SUBSCRIPTION_ID"
)
func main() {
ctx := context.Background()
log := logger.New(logger.PlainLog, zapcore.InfoLevel)
manifests := OldManifests()
fetchAzureImages(ctx, manifests, log)
fetchGCPImages(ctx, manifests, log)
if err := json.NewEncoder(os.Stdout).Encode(&manifests); err != nil {
log.Fatalf("%v", err)
}
}
func fetchAzureImages(ctx context.Context, manifests Manifest, log *logger.Logger) {
options := azure.DefaultOptions()
if err := options.SetSubscription(os.Getenv(AzureSubscriptionIDEnv)); err != nil {
log.Fatalf("please provide a valid subscription UUID via '%s' envar", AzureSubscriptionIDEnv)
}
client := azure.NewClient(log, options)
images, err := client.FetchImages(ctx)
if err != nil {
log.Fatalf("unable to fetch Azure image: %v", err)
}
for version, image := range images {
manifests.SetAzureImage(version, image)
}
}
func fetchGCPImages(ctx context.Context, manifests Manifest, log *logger.Logger) {
options := gcp.DefaultOptions()
client := gcp.NewClient(ctx, log, options)
images, err := client.FetchImages(ctx)
if err != nil {
log.Fatalf("unable to fetch GCP images: %v", err)
}
for version, image := range images {
manifests.SetGCPImage(version, image)
}
}