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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/oci-discovery
__pycache__
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

all: oci-discovery

.PHONY: oci-discovery
oci-discovery:
go build -o oci-discovery ./tools/cmd

test: test-go test-python

test-debug: test-go-debug test-python-debug
Expand All @@ -27,3 +33,6 @@ test-python:

test-python-debug:
DEBUG=1 python3 -m unittest discover -v

clean:
rm -f oci-discovery
40 changes: 23 additions & 17 deletions tools/README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
# Discovery Tools

## Eaxmple:
## Example:

```
$ go run cmd/main.go --debug discovery example.com/app#1.0 2>/tmp/log
[
{
"mediaType": "application/vnd.oci.image.manifest.v1+json",
"digest": "sha256:e9770a03fbdccdd4632895151a93f9af58bbe2c91fdfaaf73160648d250e6ec3",
"size": 799,
"annotations": {
"org.opencontainers.image.ref.name": "1.0"
},
"platform": {
"architecture": "ppc64le",
"os": "linux"
}
}
]
$ oci-discovery --debug resolve example.com/app#1.0 2>/tmp/log
{
"example.com/app#1.0": [
{
"mediaType": "application/vnd.oci.descriptor.v1+json",
"root": {
"mediaType": "application/vnd.oci.image.manifest.v1+json",
"digest": "sha256:e9770a03fbdccdd4632895151a93f9af58bbe2c91fdfaaf73160648d250e6ec3"
"size": 799,
"annotations": {
"org.opencontainers.image.ref.name": "1.0"
},
"platform": {
"architecture": "ppc64le",
"os": "linux"
}
},
"uri": "https://example.com/oci-index/app"
}
]
}
$ cat /tmp/log
time="2017-09-19T12:43:41-07:00" level=debug msg="requesting application/vnd.oci.ref-engines.v1+json from http://example.com/.well-known/oci-host-ref-engines"
time="2017-09-19T12:43:41-07:00" level=debug msg="requesting application/vnd.oci.ref-engines.v1+json from https://example.com/.well-known/oci-host-ref-engines"
time="2017-09-19T12:43:41-07:00" level=debug msg="requesting application/vnd.oci.image.index.v1+json from https://example.com/oci-index/app"
```
35 changes: 16 additions & 19 deletions tools/cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
// Copyright 2017 oci-discovery contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
"os"

"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"github.com/xiekeyang/oci-discovery/tools/discovery"

_ "github.com/xiekeyang/oci-discovery/tools/indextemplate"
)

var discoveryCommand = cli.Command{
Name: "discovery",
Usage: "Resolve image names via OCI Ref-engine Discovery.",
Action: discovery.DiscoveryHandler,
Flags: []cli.Flag{
cli.StringFlag{
Name: "protocol",
Usage: "Protocol to use for ref-engine discovery",
},
cli.UintFlag{
Name: "port",
Usage: "Port to use for ref-engine discovery",
},
},
}

func main() {
app := cli.NewApp()
app.Name = "oci-discovery-tool"
app.Usage = "OCI (Open Container Initiative) image discovery tools"
app.Usage = "OCI (Open Container Initiative) image discovery tools."
app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "debug",
Expand All @@ -43,7 +40,7 @@ func main() {
return nil
}
app.Commands = []cli.Command{
discoveryCommand,
resolveCommand,
}

if err := app.Run(os.Args); err != nil {
Expand Down
88 changes: 88 additions & 0 deletions tools/cmd/resolve.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// Copyright 2017 oci-discovery contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
"encoding/json"
"fmt"
"os"

"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"github.com/xiekeyang/oci-discovery/tools/hostbasedimagenames"
"github.com/xiekeyang/oci-discovery/tools/refengine"
"github.com/xiekeyang/oci-discovery/tools/refenginediscovery"
"golang.org/x/net/context"
)

// resolved is a flag for breaking discovery iteration.
var resolved = fmt.Errorf("satisfactory resolution")

var resolveCommand = cli.Command{
Name: "resolve",
Usage: "Resolve image names via OCI Ref-Engine Discovery.",
Flags: []cli.Flag{
cli.StringFlag{
Name: "protocol",
Usage: "Protocol to use for ref-engine discovery",
},
cli.UintFlag{
Name: "port",
Usage: "Port to use for ref-engine discovery",
},
},
Action: func(c *cli.Context) error {
ctx := context.Background()
allRoots := map[string][]refengine.MerkleRoot{}

protocols := []string{}
if c.IsSet("protocol") {
protocols = append(protocols, c.String("protocol"))
}

for _, name := range c.Args() {
parsedName, err := hostbasedimagenames.Parse(name)
if err != nil {
logrus.Warn(err)
continue
}

err = refenginediscovery.Discover(
ctx, protocols, parsedName["host"],
func(ctx context.Context, refEngine refengine.Engine, casEngines []refenginediscovery.ResolvedCASEngines) error {
return resolveCallback(ctx, allRoots, refEngine, casEngines, name)
})
if err == resolved {
continue
} else if err != nil {
logrus.Warn(err)
}
}

encoder := json.NewEncoder(os.Stdout)
encoder.SetIndent("", "\t")
return encoder.Encode(allRoots)
},
}

func resolveCallback(ctx context.Context, allRoots map[string][]refengine.MerkleRoot, refEngine refengine.Engine, casEngines []refenginediscovery.ResolvedCASEngines, name string) (err error) {
roots, err := refEngine.Get(ctx, name)
if err != nil {
logrus.Warn(err)
return nil
}
allRoots[name] = roots
return resolved
}
129 changes: 0 additions & 129 deletions tools/discovery/discovery.go

This file was deleted.

35 changes: 0 additions & 35 deletions tools/discovery/resolve.go

This file was deleted.

Loading