Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Commit

Permalink
ref(duffle): hide http-based workflow commands (pull, push, search) (#…
Browse files Browse the repository at this point in the history
…491)

Signed-off-by: Matthew Fisher <[email protected]>
  • Loading branch information
Matthew Fisher authored Nov 21, 2018
1 parent 8c02e76 commit 07b495d
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 154 deletions.
41 changes: 16 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ Duffle is a command line tool that allows you to install and manage CNAB bundles
```

2. Clone this repo:
```
cd $GOPATH/src/github.com/deis/
git clone [email protected]:deis/duffle.git
cd duffle
```console
$ cd $GOPATH/src/github.com/deis/
$ git clone [email protected]:deis/duffle.git
$ cd duffle
```

3. Vendor dependencies and build the `duffle` binary:
```
make bootstrap build
```console
$ make bootstrap build
```

4. Run the command to set duffle up on your machine:
Expand All @@ -37,27 +37,13 @@ Duffle is a command line tool that allows you to install and manage CNAB bundles
==> repo added in 1.096263107s
```

5. Search for available bundles:
```console
$ duffle search
NAME REPOSITORY VERSION
helloazure github.com/deis/bundles.git 0.1.0
hellohelm github.com/deis/bundles.git 0.1.0
helloworld github.com/deis/bundles.git 1.0
```
*Notes:*
* The source code for these bundles are in the [bundles repo](https://github.com/deis/bundles) on github, and are built and hosted by <https://hub.cnlabs.io>.
* Learn more about what a bundle is and its components [here](https://github.com/deis/duffle/blob/master/docs/100-CNAB.md).
* Get a feel for what CNAB bundles look like by referencing the [examples](examples/) directory.

6. Build and install your first bundle:
5. Build and install your first bundle:

```console
```console
$ duffle build ./examples/helloworld/
Duffle Build Started: 'helloworld': 01CS02FNS3FTM9907V83GAQQMT
helloworld: Building CNAB components: SUCCESS ⚓ (1.0090s)

$ duffle credentials generate helloworld-creds -f examples/helloworld/cnab/bundle.json
name: helloworld-creds
credentials:
Expand All @@ -66,13 +52,18 @@ Duffle is a command line tool that allows you to install and manage CNAB bundles
value: EMPTY
destination:
path: pquux

$ duffle install helloworld-demo -c helloworld-creds -f examples/helloworld/cnab/bundle.json
Executing install action...

Install action
Action install complete for helloworld-demo
```

*Notes:*
* Learn more about what a bundle is and its components [here](https://github.com/deislabs/cnab-spec/blob/master/100-CNAB.md).
* Get a feel for what CNAB bundles look like by referencing the [bundles repo](https://github.com/deis/bundles) on github.

# Debugging using VS Code

For instructions on using VS Code to debug the Duffle binary, see [the debugging document](docs/001-debugging.md).
2 changes: 1 addition & 1 deletion cmd/duffle/bundle_remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
const bundleRemoveDesc = `Remove a bundle from the local storage.
This removes a bundle from the local storage so that it will no longer be locally
available. Remote bundles can be re-fetched with 'duffle pull'.
available. Bundles can be rebuilt with 'duffle build'.
If a SemVer range is provided with '--version'/'-r' then only releases that match
that range will be removed.
Expand Down
5 changes: 2 additions & 3 deletions cmd/duffle/bundle_sign.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,11 @@ func bundleFileOrArg1(args []string, bundle string) (string, error) {
return "", errors.New("please specify a BUNDLE or use -f for a file")
case len(args) == 1:
// passing insecure: true, as currently we can only sign an unsinged bundle
return loadOrPullBundle(args[0], true)
return getBundleFilepath(args[0], true)
}
return bundle, nil
}
func (bs *bundleSignCmd) signBundle(bundleFile, keyring string) error {
def := home.DefaultRepository()
// Verify that file exists
if fi, err := os.Stat(bundleFile); err != nil {
return fmt.Errorf("cannot find bundle file to sign: %v", err)
Expand Down Expand Up @@ -141,7 +140,7 @@ func (bs *bundleSignCmd) signBundle(bundleFile, keyring string) error {
}

// TODO - write pkg method in bundle that writes file and records the reference
if err := recordBundleReference(bs.home, fmt.Sprintf("%s/%s", def, b.Name), b.Version, digest); err != nil {
if err := recordBundleReference(bs.home, b.Name, b.Version, digest); err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/duffle/credential_generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func getBundleFileFromCredentialsArg(args []string, bundleFile string, w io.Writ
case len(args) < 2 && bundleFile == "":
return "", errors.New("required arguments are NAME (name for the credentialset) and BUNDLE (CNAB bundle name) or file")
case len(args) == 2:
return pullBundle(args[1], insecure)
return getBundleFilepath(args[1], insecure)
}
return bundleFile, nil
}
2 changes: 1 addition & 1 deletion cmd/duffle/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func newInspectCmd(w io.Writer) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
bundleName := args[0]

bundleFile, err := loadOrPullBundle(bundleName, insecure)
bundleFile, err := getBundleFilepath(bundleName, insecure)
if err != nil {
return err
}
Expand Down
16 changes: 7 additions & 9 deletions cmd/duffle/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Windows Example:
For unpublished CNAB bundles, you can also load the bundle.json directly:
$ duffle install dev_bundle -f path/to/bundle.json
Verifying and --insecure:
Expand Down Expand Up @@ -165,7 +165,7 @@ func bundleFileOrArg2(args []string, bun string, w io.Writer, insecure bool) (st
case len(args) < 2 && bun == "":
return "", errors.New("required arguments are NAME (name of the installation) and BUNDLE (CNAB bundle name) or file")
case len(args) == 2:
return loadOrPullBundle(args[1], insecure)
return getBundleFilepath(args[1], insecure)
}
return bun, nil
}
Expand All @@ -183,12 +183,12 @@ func optBundleFileOrArg2(args []string, bun string, w io.Writer, insecure bool)
// No bundle provided
return "", nil
case len(args) == 2:
return pullBundle(args[1], insecure)
return getBundleFilepath(args[1], insecure)
}
return bun, nil
}

func loadOrPullBundle(bun string, insecure bool) (string, error) {
func getBundleFilepath(bun string, insecure bool) (string, error) {
home := home.Home(homePath())
ref, err := getReference(bun)
if err != nil {
Expand All @@ -202,12 +202,10 @@ func loadOrPullBundle(bun string, insecure bool) (string, error) {
}

digest, err := index.Get(ref.Name(), ref.Tag())
if err == nil {
return filepath.Join(home.Bundles(), digest), nil
if err != nil {
return "", fmt.Errorf("could not find %s:%s in %s: %v", ref.Name(), ref.Tag(), home.Repositories(), err)
}

// the bundle was not found locally, so we pull it
return pullBundle(bun, insecure)
return filepath.Join(home.Bundles(), digest), nil
}

// overrides parses the --set data and returns values that should override other params.
Expand Down
39 changes: 1 addition & 38 deletions cmd/duffle/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (

"github.com/deis/duffle/pkg/bundle"
"github.com/deis/duffle/pkg/duffle/home"
"github.com/deis/duffle/pkg/reference"
)

func TestGetBundle(t *testing.T) {
Expand Down Expand Up @@ -42,7 +41,7 @@ func TestGetBundle(t *testing.T) {
tc := tc // capture range variable
t.Run(tc.Name, func(t *testing.T) {
t.Parallel()
bundle, err := pullBundle(tc.File, true)
bundle, err := getBundleFilepath(tc.File, true)
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -77,39 +76,3 @@ func TestOverrides(t *testing.T) {
_, err = overrides([]string{"undefined=foo"}, defs)
is.Error(err)
}

func TestRepoURLFromReference(t *testing.T) {
tests := []struct {
Name string
Reference reference.NamedTagged
Expected string
}{
{
Name: "basic repository",
// discard the digest; we don't care about that
Reference: &NamedRepository{"hub.cnlabs.io/helloazure", "0.1.0", ""},
Expected: "https://hub.cnlabs.io/repositories/helloazure/tags/0.1.0",
},
{
Name: "namespaced repository",
// discard the digest; we don't care about that
Reference: &NamedRepository{"hub.cnlabs.io/library/helloazure", "0.2.0", ""},
Expected: "https://hub.cnlabs.io/repositories/library/helloazure/tags/0.2.0",
},
}

for _, tc := range tests {
tc := tc // capture range variable
t.Run(tc.Name, func(t *testing.T) {
t.Parallel()
url, err := repoURLFromReference(tc.Reference)
if err != nil {
t.Error(err)
}

if url.String() != tc.Expected {
t.Errorf("expected '%s', got '%s'", tc.Expected, url.String())
}
})
}
}
7 changes: 4 additions & 3 deletions cmd/duffle/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ Example:

var insecure bool
cmd := &cobra.Command{
Use: "pull",
Short: "pull a CNAB bundle from a repository",
Long: usage,
Hidden: true,
Use: "pull",
Short: "pull a CNAB bundle from a repository",
Long: usage,
RunE: func(cmd *cobra.Command, args []string) error {
path, err := pullBundle(args[0], insecure)
if err != nil {
Expand Down
51 changes: 0 additions & 51 deletions cmd/duffle/pull_test.go

This file was deleted.

9 changes: 5 additions & 4 deletions cmd/duffle/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ func newPushCmd(out io.Writer) *cobra.Command {
const usage = `Pushes a CNAB bundle to a repository.`

cmd := &cobra.Command{
Use: "push NAME",
Short: "push a CNAB bundle to a repository",
Long: usage,
Args: cobra.ExactArgs(1),
Hidden: true,
Use: "push NAME",
Short: "push a CNAB bundle to a repository",
Long: usage,
Args: cobra.ExactArgs(1),
RunE: func(_ *cobra.Command, args []string) error {
home := home.Home(homePath())
bundleName := args[0]
Expand Down
8 changes: 4 additions & 4 deletions cmd/duffle/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/spf13/cobra"

"github.com/deis/duffle/pkg/bundle"
"github.com/deis/duffle/pkg/duffle/home"
"github.com/deis/duffle/pkg/repo/remote"
)

Expand All @@ -40,8 +39,9 @@ func newSearchCmd(w io.Writer) *cobra.Command {
var output string

cmd := &cobra.Command{
Use: "search",
Short: "perform a fuzzy search on available bundles",
Hidden: true,
Use: "search",
Short: "perform a fuzzy search on available bundles",
RunE: func(cmd *cobra.Command, args []string) error {
output, err := validOutputOrErr(output, cmd.OutOrStdout())
if err != nil {
Expand Down Expand Up @@ -99,7 +99,7 @@ func search(keywords []string) (BundleList, error) {

url := &url.URL{
Scheme: "https",
Host: home.DefaultRepository(),
Host: "hub.cnlabs.io",
Path: remote.IndexPath,
}

Expand Down
10 changes: 1 addition & 9 deletions docs/proposal/200-duffle.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,6 @@ Status takes a claim's installation name, looks up a claim, and executes the sta

The `duffle list` command lists all claims. It serves as a record of installed (but not uninstalled) applications.

## Pushing images to a registry with `duffle push`

The `duffle push` command pushes a built CNAB bundle's images into the pre-configured container registry. It also pushes a `bundle.json` to its registry. Depending on configuration, it _should_ sign the bundle before pushing.

## Fetching CNAB bundles with `duffle pull`

The `duffle pull` command will pull a named CNAB bundle from a registry. It may also fetch associated images.

## Exporting a CNAB bundle with `duffle export`

The `duffle export` command exports a invocation image together with all of its associated images, generating a single gzipped tar file as output.
Expand Down Expand Up @@ -97,6 +89,7 @@ For operations that execute this installation image (install, upgrade, etc.), th
The following items remain to be specified:

- How `duffle init` works
- How Duffle interacts with an image registry (logging in, pushing/pulling bundles)
- Whether Duffle will support multi-runtimes in a single image.

| Method | Description |
Expand All @@ -106,4 +99,3 @@ The following items remain to be specified:
| automatic | A CNAB bundle may expose multiple runtimes, but automatically choose which applies to the current config |

Next section: [credential set](201-credentialset.md)

5 changes: 0 additions & 5 deletions pkg/duffle/home/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,3 @@ func DefaultHome() string {

return filepath.Join(homeEnvPath, ".duffle")
}

// DefaultRepository returns the name of the default repository.
func DefaultRepository() string {
return "hub.cnlabs.io"
}

0 comments on commit 07b495d

Please sign in to comment.