Skip to content

Commit

Permalink
Merge branch 'main' into feat/jfrog-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobmoellerdev authored Jan 6, 2025
2 parents 3100dc6 + 1817c87 commit 8efeb55
Show file tree
Hide file tree
Showing 48 changed files with 2,550 additions and 113 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/publish-latest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ jobs:
uses: docker/build-push-action@v6
with:
context: .
# supported platforms of https://hub.docker.com/_/golang/tags?page=1&name=1.23-alpine3.20
# platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x
# supported platforms: https://github.com/GoogleContainerTools/distroless?tab=readme-ov-file#what-images-are-available
platforms: linux/amd64,linux/arm64 #linux/arm,linux/ppc64le,linux/s390x
push: true
tags: |
ghcr.io/open-component-model/ocm:latest
Expand Down Expand Up @@ -166,4 +166,4 @@ jobs:
key: ${{ env.cache_name }}-${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}-${{ hashFiles('**/go.mod') }}
upload-chunk-size: 256000000 # default of 32MB is not really optimal for our large cache, choose 256MB instead
env:
cache_name: ocm-cli-latest-go-cache # needs to be the same key in the end as in the build step
cache_name: ocm-cli-latest-go-cache # needs to be the same key in the end as in the build step
1 change: 1 addition & 0 deletions api/credentials/builtin/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ package builtin

import (
_ "ocm.software/ocm/api/credentials/builtin/github"
_ "ocm.software/ocm/api/tech/git/identity"
)
12 changes: 6 additions & 6 deletions api/oci/cpi/support/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@ func (a *artifactBase) IsReadOnly() bool {
}

func (a *artifactBase) IsIndex() bool {
d := a.state.GetState().(*artdesc.Artifact)
return d.IsIndex()
d, ok := a.state.GetState().(*artdesc.Artifact)
return ok && d.IsIndex()
}

func (a *artifactBase) IsManifest() bool {
d := a.state.GetState().(*artdesc.Artifact)
return d.IsManifest()
d, ok := a.state.GetState().(*artdesc.Artifact)
return ok && d.IsManifest()
}

func (a *artifactBase) IsValid() bool {
d := a.state.GetState().(*artdesc.Artifact)
return d.IsValid()
d, ok := a.state.GetState().(*artdesc.Artifact)
return ok && d.IsValid()
}

func (a *artifactBase) blob() (cpi.BlobAccess, error) {
Expand Down
2 changes: 1 addition & 1 deletion api/oci/internal/uniform.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type UniformRepositorySpec struct {
// Host is the hostname of an oci ref.
Host string `json:"host,omitempty"`
// Info is the file path used to host ctf component versions
Info string `json:"filePath,omitempty"`
Info string `json:"info,omitempty"`

// CreateIfMissing indicates whether a file based or dynamic repo should be created if it does not exist
CreateIfMissing bool `json:"createIfMissing,omitempty"`
Expand Down
58 changes: 58 additions & 0 deletions api/ocm/elements/artifactaccess/gitaccess/options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package gitaccess

import (
"github.com/mandelsoft/goutils/optionutils"
)

type Option = optionutils.Option[*Options]

type Options struct {
URL string
Ref string
Commit string
}

var _ Option = (*Options)(nil)

func (o *Options) ApplyTo(opts *Options) {
if o.URL != "" {
opts.URL = o.URL
}
}

func (o *Options) Apply(opts ...Option) {
optionutils.ApplyOptions(o, opts...)
}

// //////////////////////////////////////////////////////////////////////////////
// Local options

type url string

func (h url) ApplyTo(opts *Options) {
opts.URL = string(h)
}

func WithURL(h string) Option {
return url(h)
}

type ref string

func (h ref) ApplyTo(opts *Options) {
opts.Ref = string(h)
}

func WithRef(h string) Option {
return ref(h)
}

type commitSpec string

func (h commitSpec) ApplyTo(opts *Options) {
opts.Commit = string(h)
}

func WithCommit(c string) Option {
return commitSpec(c)
}
25 changes: 25 additions & 0 deletions api/ocm/elements/artifactaccess/gitaccess/resource.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package gitaccess

import (
"github.com/mandelsoft/goutils/optionutils"

"ocm.software/ocm/api/ocm"
"ocm.software/ocm/api/ocm/compdesc"
"ocm.software/ocm/api/ocm/cpi"
"ocm.software/ocm/api/ocm/elements/artifactaccess/genericaccess"
access "ocm.software/ocm/api/ocm/extensions/accessmethods/git"
resourcetypes "ocm.software/ocm/api/ocm/extensions/artifacttypes"
)

const TYPE = resourcetypes.DIRECTORY_TREE

func Access[M any, P compdesc.ArtifactMetaPointer[M]](ctx ocm.Context, meta P, opts ...Option) cpi.ArtifactAccess[M] {
eff := optionutils.EvalOptions(opts...)
if meta.GetType() == "" {
meta.SetType(TYPE)
}

spec := access.New(eff.URL, access.WithRef(eff.Ref), access.WithCommit(eff.Commit))
// is global access, must work, otherwise there is an error in the lib.
return genericaccess.MustAccess(ctx, meta, spec)
}
93 changes: 93 additions & 0 deletions api/ocm/extensions/accessmethods/git/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@

# Access Method `git` - Git Commit Access

## Synopsis

```yaml
type: git/v1
```
Provided blobs use the following media type for: `application/x-tgz`

The artifact content is provided as gnu-zipped tar archive

### Description

This method implements the access of the content of a git commit stored in a
git repository.

Supported specification version is `v1alpha1`

### Specification Versions

#### Version `v1alpha1`

The type specific specification fields are:

- **`repository`** *string*

Repository URL with or without scheme.

- **`ref`** (optional) *string*

Original ref used to get the commit from

- **`commit`** *string*

The sha/id of the git commit

### Go Bindings

The go binding can be found [here](method.go)

#### Example

```go
package main
import (
"archive/tar"
"bytes"
"compress/gzip"
"fmt"
"io"
"ocm.software/ocm/api/ocm"
"ocm.software/ocm/api/ocm/cpi"
me "ocm.software/ocm/api/ocm/extensions/accessmethods/git"
)
func main() {
ctx := ocm.New()
accessSpec := me.New(
"https://github.com/octocat/Hello-World.git",
me.WithRef("refs/heads/master"),
)
method, err := accessSpec.AccessMethod(&cpi.DummyComponentVersionAccess{Context: ctx})
if err != nil {
panic(err)
}
content, err := method.GetContent()
if err != nil {
panic(err)
}
unzippedContent, err := gzip.NewReader(bytes.NewReader(content))
r := tar.NewReader(unzippedContent)
file, err := r.Next()
if err != nil {
panic(err)
}
if file.Name != "README.md" {
panic("Expected README.md")
}
data, err := io.ReadAll(r)
if err != nil {
panic(err)
}
fmt.Println(string(data))
}
```
43 changes: 43 additions & 0 deletions api/ocm/extensions/accessmethods/git/cli.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package git

import (
"ocm.software/ocm/api/ocm/extensions/accessmethods/options"
"ocm.software/ocm/api/utils/cobrautils/flagsets"
)

func ConfigHandler() flagsets.ConfigOptionTypeSetHandler {
return flagsets.NewConfigOptionTypeSetHandler(
Type, AddConfig,
options.RepositoryOption,
options.ReferenceOption,
options.CommitOption,
)
}

func AddConfig(opts flagsets.ConfigOptions, config flagsets.Config) error {
flagsets.AddFieldByOptionP(opts, options.RepositoryOption, config, "repository", "repo", "repoUrl", "repoURL")
flagsets.AddFieldByOptionP(opts, options.CommitOption, config, "commit")
flagsets.AddFieldByOptionP(opts, options.ReferenceOption, config, "ref")
return nil
}

var usage = `
This method implements the access of the content of a git commit stored in a
Git repository.
`

var formatV1 = `
The type specific specification fields are:
- **<code>repoUrl</code>** *string*
Repository URL with or without scheme.
- **<code>ref</code>** (optional) *string*
Original ref used to get the commit from
- **<code>commit</code>** *string*
The sha/id of the git commit
`
Loading

0 comments on commit 8efeb55

Please sign in to comment.