Skip to content

Commit 1bf6936

Browse files
authored
Merge pull request #442 from oasisprotocol/anzoman/use-default-rofl-orc-registry
cmd&build: Push ORCs to Oasis-managed ROFL registry by default
2 parents 30afeba + 2401b3a commit 1bf6936

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

.golangci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ linters-settings:
8080
- github.com/opencontainers/image-spec/specs-go/v1
8181
- oras.land/oras-go/v2
8282
- github.com/wI2L/jsondiff
83+
- github.com/google/uuid
8384
exhaustive:
8485
# Switch statements are to be considered exhaustive if a 'default' case is
8586
# present, even if all enum members aren't listed in the switch.

build/rofl/oci.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"maps"
7+
"net/http"
78
"os"
89
"path/filepath"
910
"slices"
@@ -27,6 +28,9 @@ const (
2728
ociTypeOrcArtifact = "application/vnd.oasis.orc"
2829
)
2930

31+
// DefaultOCIRegistry is the default OCI registry.
32+
const DefaultOCIRegistry = "rofl.sh"
33+
3034
// PushBundleToOciRepository pushes an ORC bundle to the given remote OCI repository.
3135
//
3236
// Returns the OCI manifest digest and the ORC manifest hash.
@@ -118,11 +122,17 @@ func PushBundleToOciRepository(bundleFn, dst string) (string, hash.Hash, error)
118122
if err != nil {
119123
return "", hash.Hash{}, fmt.Errorf("failed to init OCI credential store: %w", err)
120124
}
121-
repo.Client = &auth.Client{
125+
client := &auth.Client{
122126
Client: retry.DefaultClient,
123127
Cache: auth.NewCache(),
124128
Credential: credentials.Credential(creds),
125129
}
130+
if strings.Contains(dst, DefaultOCIRegistry) {
131+
client.Header = http.Header{
132+
"X-Rofl-Registry-Caller": []string{"cli"},
133+
}
134+
}
135+
repo.Client = client
126136

127137
// Push to remote repository.
128138
if _, err = oras.Copy(ctx, store, tag, repo, tag, oras.DefaultCopyOptions); err != nil {

cmd/rofl/deploy.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import (
88
"maps"
99
"os"
1010
"sort"
11+
"time"
1112

13+
"github.com/google/uuid"
1214
"github.com/spf13/cobra"
1315
flag "github.com/spf13/pflag"
1416

@@ -117,15 +119,21 @@ var (
117119

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

125129
orcFilename := roflCommon.GetOrcFilename(manifest, deploymentName)
126130
ociDigest, manifestHash, err := buildRofl.PushBundleToOciRepository(orcFilename, deployment.OCIRepository)
127131
switch {
128132
case err == nil:
133+
// Save the OCI repository field to the configuration file so we avoid multiple uploads.
134+
if err := manifest.Save(); err != nil {
135+
cobra.CheckErr(fmt.Sprintf("Failed to update manifest with OCI repository: %s", err))
136+
}
129137
case errors.Is(err, os.ErrNotExist):
130138
cobra.CheckErr(fmt.Sprintf("ROFL app bundle '%s' not found. Run `oasis rofl build` first.", orcFilename))
131139
default:

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ require (
1818
github.com/ethereum/go-ethereum v1.15.0
1919
github.com/foxboron/go-uefi v0.0.0-20241017190036-fab4fdf2f2f3
2020
github.com/github/go-spdx/v2 v2.3.2
21+
github.com/google/uuid v1.6.0
2122
github.com/miguelmota/go-ethereum-hdwallet v0.1.2
2223
github.com/mitchellh/mapstructure v1.5.0
2324
github.com/oasisprotocol/curve25519-voi v0.0.0-20230904125328-1f23a7beb09a

0 commit comments

Comments
 (0)