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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 11 additions & 1 deletion
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

Lines changed: 10 additions & 2 deletions
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

Lines changed: 1 addition & 0 deletions
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)