-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
image: Refactor to use cas/ref engines instead of walkers #5
Open
wking
wants to merge
14
commits into
opencontainers:master
Choose a base branch
from
wking:cas-api
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
fbae6d9
image/cas: Add a generic CAS interface
wking 1a2c78f
image/refs: Add a generic name-based reference interface
wking b27e428
specs-go: Add ImageLayoutVersion and check oci-layout in tar engines
wking 9263d6e
image/layout/tar.go: Add TarEntryByName
wking fe8f7cd
image/cas/put: Add a PutJSON helper
wking 753408b
vendor: Bundle golang.org/x/net/context
wking 8c55e0c
image/*/interface: Add unstable warnings to Engines
wking 7ea54f2
image/cas: Implement Engine.Put
wking d2c026b
image/refs: Implement Engine.Put
wking 5c748c9
image/layout/tar: Add a CreateTarFile helper
wking 7bd8bcf
image: Refactor to use cas/ref engines instead of walkers
wking 94f5137
cmd: Document the cas, refs, and init commands
wking 2564e3d
.tool/lint: Ignore dupl complaints for cmd/oci-*/get.go
wking ca90284
image: Add image-layout directory based CAS and ref engines
wking File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
/oci-cas | ||
/oci-create-runtime-bundle | ||
/oci-unpack | ||
/oci-image-init | ||
/oci-image-validate | ||
/oci-refs | ||
/oci-unpack |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright 2016 The Linux Foundation | ||
// | ||
// 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 ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/opencontainers/image-tools/image/cas/layout" | ||
"github.com/spf13/cobra" | ||
"golang.org/x/net/context" | ||
) | ||
|
||
type deleteCmd struct { | ||
path string | ||
digest string | ||
} | ||
|
||
func newDeleteCmd() *cobra.Command { | ||
state := &deleteCmd{} | ||
|
||
return &cobra.Command{ | ||
Use: "delete PATH DIGEST", | ||
Short: "Remove a blob from from the store", | ||
Run: state.Run, | ||
} | ||
} | ||
|
||
func (state *deleteCmd) Run(cmd *cobra.Command, args []string) { | ||
if len(args) != 2 { | ||
fmt.Fprintln(os.Stderr, "both PATH and DIGEST must be provided") | ||
if err := cmd.Usage(); err != nil { | ||
fmt.Fprintln(os.Stderr, err) | ||
} | ||
os.Exit(1) | ||
} | ||
|
||
state.path = args[0] | ||
state.digest = args[1] | ||
|
||
err := state.run() | ||
if err != nil { | ||
fmt.Fprintln(os.Stderr, err) | ||
os.Exit(1) | ||
} | ||
|
||
os.Exit(0) | ||
} | ||
|
||
func (state *deleteCmd) run() (err error) { | ||
ctx := context.Background() | ||
|
||
engine, err := layout.NewEngine(ctx, state.path) | ||
if err != nil { | ||
return err | ||
} | ||
defer engine.Close() | ||
|
||
return engine.Delete(ctx, state.digest) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Copyright 2016 The Linux Foundation | ||
// | ||
// 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 ( | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
|
||
"github.com/opencontainers/image-tools/image/cas/layout" | ||
"github.com/spf13/cobra" | ||
"golang.org/x/net/context" | ||
) | ||
|
||
type getCmd struct { | ||
path string | ||
digest string | ||
} | ||
|
||
func newGetCmd() *cobra.Command { | ||
state := &getCmd{} | ||
|
||
return &cobra.Command{ | ||
Use: "get PATH DIGEST", | ||
Short: "Retrieve a blob from the store", | ||
Long: "Retrieve a blob from the store and write it to stdout.", | ||
Run: state.Run, | ||
} | ||
} | ||
|
||
func (state *getCmd) Run(cmd *cobra.Command, args []string) { | ||
if len(args) != 2 { | ||
fmt.Fprintln(os.Stderr, "both PATH and DIGEST must be provided") | ||
if err := cmd.Usage(); err != nil { | ||
fmt.Fprintln(os.Stderr, err) | ||
} | ||
os.Exit(1) | ||
} | ||
|
||
state.path = args[0] | ||
state.digest = args[1] | ||
|
||
err := state.run() | ||
if err != nil { | ||
fmt.Fprintln(os.Stderr, err) | ||
os.Exit(1) | ||
} | ||
|
||
os.Exit(0) | ||
} | ||
|
||
func (state *getCmd) run() (err error) { | ||
ctx := context.Background() | ||
|
||
engine, err := layout.NewEngine(ctx, state.path) | ||
if err != nil { | ||
return err | ||
} | ||
defer engine.Close() | ||
|
||
reader, err := engine.Get(ctx, state.digest) | ||
if err != nil { | ||
return err | ||
} | ||
defer reader.Close() | ||
|
||
bytes, err := ioutil.ReadAll(reader) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
n, err := os.Stdout.Write(bytes) | ||
if err != nil { | ||
return err | ||
} | ||
if n < len(bytes) { | ||
return fmt.Errorf("wrote %d of %d bytes", n, len(bytes)) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2016 The Linux Foundation | ||
// | ||
// 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 ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func main() { | ||
cmd := &cobra.Command{ | ||
Use: "oci-cas", | ||
Short: "Content-addressable storage manipulation", | ||
} | ||
|
||
cmd.AddCommand(newGetCmd()) | ||
cmd.AddCommand(newPutCmd()) | ||
cmd.AddCommand(newDeleteCmd()) | ||
|
||
err := cmd.Execute() | ||
if err != nil { | ||
fmt.Fprintln(os.Stderr, err) | ||
os.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
% OCI(1) OCI-IMAGE-TOOL User Manuals | ||
% OCI Community | ||
% SEPTEMBER 2016 | ||
# NAME | ||
|
||
oci-cas-get \- Remove a blob from the store | ||
|
||
# SYNOPSIS | ||
|
||
**oci-cas delete** [OPTIONS] PATH DIGEST | ||
|
||
# DESCRIPTION | ||
|
||
`oci-cas delete` removes the blob referenced by `DIGEST` from the store at `PATH`. | ||
|
||
# OPTIONS | ||
|
||
**--help** | ||
Print usage statement | ||
|
||
# SEE ALSO | ||
|
||
**oci-cas**(1), **oci-cas-get**(1), **oci-cas-put**(1) | ||
|
||
# HISTORY | ||
|
||
September 2016, Originally compiled by W. Trevor King (wking at tremily dot us) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
% OCI(1) OCI-IMAGE-TOOL User Manuals | ||
% OCI Community | ||
% AUGUST 2016 | ||
# NAME | ||
|
||
oci-cas-get \- Retrieve a blob from the store | ||
|
||
# SYNOPSIS | ||
|
||
**oci-cas get** [OPTIONS] PATH DIGEST | ||
|
||
# DESCRIPTION | ||
|
||
`oci-cas get` retrieves a blob referenced by `DIGEST` from the store at `PATH` and writes it to standard output. | ||
|
||
# OPTIONS | ||
|
||
**--help** | ||
Print usage statement | ||
|
||
# SEE ALSO | ||
|
||
**oci-cas**(1), **oci-cas-put**(1), **oci-cas-delete**(1) | ||
|
||
# HISTORY | ||
|
||
August 2016, Originally compiled by W. Trevor King (wking at tremily dot us) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
% OCI(1) OCI-IMAGE-TOOL User Manuals | ||
% OCI Community | ||
% AUGUST 2016 | ||
# NAME | ||
|
||
oci-cas-put \- Write a blob to the store | ||
|
||
# SYNOPSIS | ||
|
||
**oci-cas put** [OPTIONS] PATH | ||
|
||
# DESCRIPTION | ||
|
||
`oci-cas put` reads a blob from stdin, writes it to the store at `PATH`, and prints the digest to standard output. | ||
|
||
# OPTIONS | ||
|
||
**--help** | ||
Print usage statement | ||
|
||
# SEE ALSO | ||
|
||
**oci-cas**(1), **oci-cas-get**(1), **oci-cas-delete**(1) | ||
|
||
# HISTORY | ||
|
||
August 2016, Originally compiled by W. Trevor King (wking at tremily dot us) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
% OCI(1) OCI-User Manuals | ||
% OCI Community | ||
% AUGUST 2016 | ||
# NAME | ||
|
||
oci-cas \- Content-addressable storage manipulation | ||
|
||
# SYNOPSIS | ||
|
||
**oci-cas** [command] | ||
|
||
# DESCRIPTION | ||
|
||
`oci-cas` manipulates content-addressable storage. | ||
|
||
# OPTIONS | ||
|
||
**--help** | ||
Print usage statement | ||
|
||
# COMMANDS | ||
|
||
**get** | ||
Retrieve a blob from the store. | ||
See **oci-cas-get**(1) for full documentation on the **get** command. | ||
|
||
**put** | ||
Write a blob to the store. | ||
See **oci-cas-put**(1) for full documentation on the **put** command. | ||
|
||
**delete** | ||
Remove a blob from the store. | ||
See **oci-cas-delete**(1) for full documentation on the **delete** command. | ||
|
||
# EXAMPLES | ||
|
||
``` | ||
$ oci-image-init image-layout image | ||
$ echo hello | oci-cas put image | ||
sha256:5891b5b522d5df086d0ff0b110fbd9d21bb4fc7163af34d08286a2e846f6be03 | ||
$ oci-cas get image sha256:5891b5b522d5df086d0ff0b110fbd9d21bb4fc7163af34d08286a2e846f6be03 | ||
hello | ||
$ oci-cas delete image sha256:5891b5b522d5df086d0ff0b110fbd9d21bb4fc7163af34d08286a2e846f6be03 | ||
``` | ||
|
||
# SEE ALSO | ||
|
||
**oci-image-tools**(7), **oci-cas-get**(1), **oci-cas-put**(1), **oci-cas-delete**(1), **oci-image-init**(1) | ||
|
||
# HISTORY | ||
|
||
August 2016, Originally compiled by W. Trevor King (wking at tremily dot us) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you remove this from
.gitignore
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's down below, I just alphabetized it.