Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: "ociregistry: lint"
name: "oci: lint"

on:
pull_request:
paths:
- "ociregistry/**"
- ".github/workflows/ociregistry-lint.yml"
- "./**"
- ".github/workflows/oci-lint.yml"

permissions:
contents: read
Expand All @@ -13,19 +13,15 @@ jobs:
lint:
name: Lint
runs-on: ubuntu-latest
defaults:
run:
working-directory: ociregistry
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version-file: ociregistry/go.mod
cache-dependency-path: ociregistry/go.sum
go-version-file: go.mod
cache-dependency-path: go.sum

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v7
with:
version: v2.10.1
working-directory: ociregistry
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: "ociregistry: tag"
name: "oci: tag"

on:
push:
branches:
- main
paths:
- "ociregistry/**"
- ".github/workflows/ociregistry-tag.yml"
- "./**"
- ".github/workflows/oci-tag.yml"

permissions:
contents: write
Expand All @@ -25,8 +25,8 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DEFAULT_BUMP: patch
INITIAL_VERSION: 0.0.0
TAG_PREFIX: ociregistry/v
INITIAL_VERSION: 0.0.1
TAG_PREFIX: v
MAJOR_STRING_TOKEN: (MAJOR)
MINOR_STRING_TOKEN: (MINOR)
BRANCH_HISTORY: compare
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: "ociregistry: test"
name: "oci: test"

on:
pull_request:
paths:
- "ociregistry/**"
- ".github/workflows/ociregistry-test.yml"
- "./**"
- ".github/workflows/oci-test.yml"

permissions:
contents: read
Expand All @@ -13,16 +13,13 @@ jobs:
test:
name: Test
runs-on: ubuntu-latest
defaults:
run:
working-directory: ociregistry
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version-file: ociregistry/go.mod
cache-dependency-path: ociregistry/go.sum
go-version-file: go.mod
cache-dependency-path: go.sum

- name: Run tests
run: go test -race -count=1 ./...
2 changes: 1 addition & 1 deletion ociregistry/.golangci.yml → .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ linters:
# Inherited code: resp.Body.Close and io.Copy in HTTP handlers.
- linters:
- errcheck
source: "(resp\\.Write|io\\.Copy|ociregistry\\.WriteError)"
source: "(resp\\.Write|io\\.Copy|oci\\.WriteError)"
# Inherited code: string HTTP method constants.
- linters:
- usestdlibvars
Expand Down
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# OCI Go modules

This repository holds functionality related to OCI (Open Container Initiative).
Currently it holds only a single module: `ociregistry`.
See the documentation for [that package](./ociregistry) for details.

The top level package (`oci`) this module defines a [Go interface](./interface.go) that encapsulates the operations provided by an OCI
registry.

Full reference documentation can be found [here](https://pkg.go.dev/cuelabs.dev/go/oci/oci).

It also provides a lightweight in-memory implementation of that interface (`ocimem`)
and an HTTP server that implements the [OCI registry protocol](https://github.com/opencontainers/distribution-spec/blob/main/spec.md) on top of it.

The server currently passes the [conformance tests](https://pkg.go.dev/github.com/opencontainers/distribution-spec/conformance).

The aim is to provide an ergonomic interface for defining and layering
OCI registry implementations.

Although the API is fairly stable, it's still in v0 currently, so incompatible changes can't be ruled out.

The code was originally derived from [cue-labs/oci](https://github.com/cue-labs/oci) which was originally derived from
the [go-containerregistry](https://pkg.go.dev/github.com/google/go-containerregistry/pkg/registry) package, but has
considerably diverged since then.
File renamed without changes.
4 changes: 2 additions & 2 deletions cmd/ocisrv/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ go 1.25.0
require (
github.com/cue-exp/cueconfig v0.0.1
github.com/go-json-experiment/json v0.0.0-20240524174822-2d9f40f7385b
github.com/jcarter3/oci/ociregistry v0.0.0
github.com/jcarter3/oci v0.0.0
github.com/opencontainers/go-digest v1.0.0
github.com/rogpeppe/go-internal v1.14.1
github.com/rogpeppe/retry v0.1.0
)

replace github.com/jcarter3/oci/ociregistry => ../../ociregistry
replace github.com/jcarter3/oci => ../../oci

require (
cuelang.org/go v0.6.0-alpha.2.0.20230628162133-7be6224cbc4f // indirect
Expand Down
4 changes: 2 additions & 2 deletions cmd/ocisrv/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/cue-exp/cueconfig"
"github.com/go-json-experiment/json"
"github.com/go-json-experiment/json/jsontext"
"github.com/jcarter3/oci/ociregistry/ociserver"
"github.com/jcarter3/oci/ociserver"
)

var (
Expand All @@ -44,7 +44,7 @@ type config struct {

func main() {
if err := main1(); err != nil {
fmt.Fprintf(os.Stderr, "ociregistry: %v\n", err)
fmt.Fprintf(os.Stderr, "oci: %v\n", err)
os.Exit(1)
}
}
Expand Down
8 changes: 3 additions & 5 deletions cmd/ocisrv/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ import (
"testing"
"time"

"github.com/jcarter3/oci/ociregistry"
"github.com/jcarter3/oci/ociregistry/ociclient"
"github.com/opencontainers/go-digest"
"github.com/jcarter3/oci/ociclient"
"github.com/rogpeppe/go-internal/testscript"
"github.com/rogpeppe/retry"
)
Expand Down Expand Up @@ -80,7 +78,7 @@ func cmdPushBlob(ts *testscript.TestScript, neg bool, args []string) {
ts.Fatalf("blob digest mismatch")
}

_, err = r.PushBlob(context.Background(), repo, ociregistry.Descriptor{
_, err = r.PushBlob(context.Background(), repo, oci.Descriptor{
Size: int64(len(data)),
Digest: digest.Digest(dg),
}, bytes.NewReader(data))
Expand Down Expand Up @@ -125,7 +123,7 @@ var waitStrategy = retry.Strategy{
MaxDuration: 500 * time.Millisecond,
}

func connect(ts *testscript.TestScript) (ociregistry.Interface, error) {
func connect(ts *testscript.TestScript) (oci.Interface, error) {
addrFile := ts.Getenv("ADDR_FILE")
if addrFile == "" {
return nil, fmt.Errorf("$ADDR_FILE not set")
Expand Down
30 changes: 15 additions & 15 deletions cmd/ocisrv/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ import (
"regexp"
"strings"

"github.com/jcarter3/oci/ociregistry"
"github.com/jcarter3/oci/ociregistry/ociclient"
"github.com/jcarter3/oci/ociregistry/ocidebug"
"github.com/jcarter3/oci/ociregistry/ocifilter"
"github.com/jcarter3/oci/ociregistry/ocimem"
"github.com/jcarter3/oci/ociregistry/ociunify"
"github.com/jcarter3/oci"
"github.com/jcarter3/oci/ociclient"
"github.com/jcarter3/oci/ocidebug"
"github.com/jcarter3/oci/ocifilter"
"github.com/jcarter3/oci/ocimem"
"github.com/jcarter3/oci/ociunify"
)

var kindToRegistryType = make(map[string]reflect.Type)
Expand All @@ -50,7 +50,7 @@ func init() {
}

type registry interface {
new() (ociregistry.Interface, error)
new() (oci.Interface, error)
}

type clientRegistry struct {
Expand All @@ -59,7 +59,7 @@ type clientRegistry struct {
DebugID string `json:"debugID,omitempty"`
}

func (r clientRegistry) new() (ociregistry.Interface, error) {
func (r clientRegistry) new() (oci.Interface, error) {
return ociclient.New(r.Host, &ociclient.Options{
DebugID: r.DebugID,
Insecure: r.Insecure,
Expand All @@ -72,7 +72,7 @@ type selectRegistry struct {
Exclude *regexp.Regexp `json:"exclude,omitempty"`
}

func (r selectRegistry) new() (ociregistry.Interface, error) {
func (r selectRegistry) new() (oci.Interface, error) {
r1, err := r.Registry.new()
if err != nil {
return nil, err
Expand All @@ -92,7 +92,7 @@ type readOnlyRegistry struct {
Registry registry `json:"registry"`
}

func (r readOnlyRegistry) new() (ociregistry.Interface, error) {
func (r readOnlyRegistry) new() (oci.Interface, error) {
r1, err := r.Registry.new()
if err != nil {
return nil, err
Expand All @@ -104,7 +104,7 @@ type immutableRegistry struct {
Registry registry `json:"registry"`
}

func (r immutableRegistry) new() (ociregistry.Interface, error) {
func (r immutableRegistry) new() (oci.Interface, error) {
r1, err := r.Registry.new()
if err != nil {
return nil, err
Expand All @@ -117,11 +117,11 @@ type unifyRegistry struct {
// TODO options
}

func (r unifyRegistry) new() (ociregistry.Interface, error) {
func (r unifyRegistry) new() (oci.Interface, error) {
if len(r.Registries) != 2 {
return nil, fmt.Errorf("can currently unify exactly two registries only")
}
r1 := make([]ociregistry.Interface, len(r.Registries))
r1 := make([]oci.Interface, len(r.Registries))
for i := range r.Registries {
ri, err := r.Registries[i].new()
if err != nil {
Expand All @@ -134,15 +134,15 @@ func (r unifyRegistry) new() (ociregistry.Interface, error) {

type memRegistry struct{}

func (r memRegistry) new() (ociregistry.Interface, error) {
func (r memRegistry) new() (oci.Interface, error) {
return ocimem.New(), nil
}

type debugRegistry struct {
Registry registry `json:"registry"`
}

func (r debugRegistry) new() (ociregistry.Interface, error) {
func (r debugRegistry) new() (oci.Interface, error) {
r1, err := r.Registry.new()
if err != nil {
return nil, err
Expand Down
6 changes: 3 additions & 3 deletions ociregistry/error.go → error.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package ociregistry
package oci

import (
"encoding/json"
Expand Down Expand Up @@ -79,7 +79,7 @@ type WireError struct {
Detail_ json.RawMessage `json:"detail,omitempty"`
}

// Is makes it possible for users to write `if errors.Is(err, ociregistry.ErrBlobUnknown)`
// Is makes it possible for users to write `if errors.Is(err, oci.ErrBlobUnknown)`
// even when the error hasn't exactly wrapped that error.
func (e *WireError) Is(err error) bool {
var rerr Error
Expand Down Expand Up @@ -196,7 +196,7 @@ func (e *httpError) Unwrap() error {
return e.underlying
}

// Is makes it possible for users to write `if errors.Is(err, ociregistry.ErrRangeInvalid)`
// Is makes it possible for users to write `if errors.Is(err, oci.ErrRangeInvalid)`
// even when the error hasn't exactly wrapped that error.
func (e *httpError) Is(err error) bool {
switch e.statusCode {
Expand Down
2 changes: 1 addition & 1 deletion ociregistry/error_test.go → error_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ociregistry
package oci

import (
"encoding/json"
Expand Down
4 changes: 2 additions & 2 deletions ociregistry/func.go → func.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package ociregistry
package oci

import (
"context"
Expand All @@ -32,7 +32,7 @@ var _ Interface = (*Funcs)(nil)
// returns ErrUnsupported from its Err method.
//
// If Funcs is nil itself, all methods will behave as if the corresponding field was nil,
// so (*ociregistry.Funcs)(nil) is a useful placeholder to implement Interface.
// so (*oci.Funcs)(nil) is a useful placeholder to implement Interface.
//
// If you're writing your own implementation of Funcs, you'll need to embed a *Funcs
// value to get an implementation of the private method. This means that it will
Expand Down
2 changes: 1 addition & 1 deletion ociregistry/go.mod → go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/jcarter3/oci/ociregistry
module github.com/jcarter3/oci

go 1.25.0

Expand Down
File renamed without changes.
Loading
Loading