Skip to content

cmd&build: Push ORCs to Oasis-managed ROFL registry by default #442

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ linters-settings:
- github.com/opencontainers/image-spec/specs-go/v1
- oras.land/oras-go/v2
- github.com/wI2L/jsondiff
- github.com/google/uuid
exhaustive:
# Switch statements are to be considered exhaustive if a 'default' case is
# present, even if all enum members aren't listed in the switch.
Expand Down
12 changes: 11 additions & 1 deletion build/rofl/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"maps"
"net/http"
"os"
"path/filepath"
"slices"
Expand All @@ -27,6 +28,9 @@ const (
ociTypeOrcArtifact = "application/vnd.oasis.orc"
)

// DefaultOCIRegistry is the default OCI registry.
const DefaultOCIRegistry = "rofl.sh"

// PushBundleToOciRepository pushes an ORC bundle to the given remote OCI repository.
//
// Returns the OCI manifest digest and the ORC manifest hash.
Expand Down Expand Up @@ -118,11 +122,17 @@ func PushBundleToOciRepository(bundleFn, dst string) (string, hash.Hash, error)
if err != nil {
return "", hash.Hash{}, fmt.Errorf("failed to init OCI credential store: %w", err)
}
repo.Client = &auth.Client{
client := &auth.Client{
Client: retry.DefaultClient,
Cache: auth.NewCache(),
Credential: credentials.Credential(creds),
}
if strings.Contains(dst, DefaultOCIRegistry) {
client.Header = http.Header{
"X-Rofl-Registry-Caller": []string{"cli"},
}
}
repo.Client = client

// Push to remote repository.
if _, err = oras.Copy(ctx, store, tag, repo, tag, oras.DefaultCopyOptions); err != nil {
Expand Down
12 changes: 10 additions & 2 deletions cmd/rofl/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import (
"maps"
"os"
"sort"
"time"

"github.com/google/uuid"
"github.com/spf13/cobra"
flag "github.com/spf13/pflag"

Expand Down Expand Up @@ -117,15 +119,21 @@ var (

// Push ORC to OCI repository.
if deployment.OCIRepository == "" {
// TODO: Support default OCI repository.
cobra.CheckErr(fmt.Sprintf("Missing OCI repository for deployment '%s'.", deploymentName))
// Use default OCI repository with random name and timestamp tag.
deployment.OCIRepository = fmt.Sprintf(
"%s/%s:%d", buildRofl.DefaultOCIRegistry, uuid.New(), time.Now().Unix(),
)
}
fmt.Printf("Pushing ROFL app to OCI repository '%s'...\n", deployment.OCIRepository)

orcFilename := roflCommon.GetOrcFilename(manifest, deploymentName)
ociDigest, manifestHash, err := buildRofl.PushBundleToOciRepository(orcFilename, deployment.OCIRepository)
switch {
case err == nil:
// Save the OCI repository field to the configuration file so we avoid multiple uploads.
if err := manifest.Save(); err != nil {
cobra.CheckErr(fmt.Sprintf("Failed to update manifest with OCI repository: %s", err))
}
case errors.Is(err, os.ErrNotExist):
cobra.CheckErr(fmt.Sprintf("ROFL app bundle '%s' not found. Run `oasis rofl build` first.", orcFilename))
default:
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ require (
github.com/ethereum/go-ethereum v1.15.0
github.com/foxboron/go-uefi v0.0.0-20241017190036-fab4fdf2f2f3
github.com/github/go-spdx/v2 v2.3.2
github.com/google/uuid v1.6.0
github.com/miguelmota/go-ethereum-hdwallet v0.1.2
github.com/mitchellh/mapstructure v1.5.0
github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a
Expand Down
Loading