Skip to content
This repository has been archived by the owner on Mar 24, 2023. It is now read-only.

Allow ship init to be pointed to valid go-getter ship.yaml path #682

Merged
merged 4 commits into from
Nov 6, 2018
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
24 changes: 19 additions & 5 deletions integration/init/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io/ioutil"
"os"
"path"
"path/filepath"
"testing"

"github.com/docker/docker/client"
Expand All @@ -19,9 +20,9 @@ import (
)

type TestMetadata struct {
Upstream string `yaml:"upstream"`
Args []string `yaml:"args"`

Upstream string `yaml:"upstream"`
Args []string `yaml:"args"`
MakeAbsolute bool `yaml:"make_absolute"`
// debugging
SkipCleanup bool `yaml:"skip_cleanup"`
}
Expand Down Expand Up @@ -78,20 +79,33 @@ var _ = Describe("ship init with arbitrary upstream", func() {
}, 20)

It("Should output the expected files", func() {
replacements := map[string]string{}
absoluteUpstream := testMetadata.Upstream

if testMetadata.MakeAbsolute {
relativePath := testMetadata.Upstream
pwdRoot, err := os.Getwd()
Expect(err).NotTo(HaveOccurred())
pwdRoot, err = filepath.Abs(pwdRoot)
Expect(err).NotTo(HaveOccurred())
absolutePath := filepath.Join(pwdRoot, "..")
absoluteUpstream = fmt.Sprintf("file::%s", filepath.Join(absolutePath, relativePath))
replacements["__upstream__"] = absoluteUpstream
}
cmd := cli.RootCmd()
buf := new(bytes.Buffer)
cmd.SetOutput(buf)
cmd.SetArgs(append([]string{
"init",
testMetadata.Upstream,
absoluteUpstream,
"--headless",
"--log-level=off",
}, testMetadata.Args...))
err := cmd.Execute()
Expect(err).NotTo(HaveOccurred())

// compare the files in the temporary directory with those in the "expected" directory
result, err := integration.CompareDir(path.Join(testPath, "expected"), testOutputPath, map[string]string{})
result, err := integration.CompareDir(path.Join(testPath, "expected"), testOutputPath, replacements)
Expect(err).NotTo(HaveOccurred())
Expect(result).To(BeTrue())
}, 60)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"v1": {
"config": null,
"releaseName": "ship",
"upstream": "__upstream__",
"metadata": null,
"contentSHA": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
}
}
4 changes: 4 additions & 0 deletions integration/init/local-single-file-gogetter/input/ship.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
lifecycle:
v1:
- message:
contents: "test message"
4 changes: 4 additions & 0 deletions integration/init/local-single-file-gogetter/metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
upstream: "input/ship.yaml"
make_absolute: true
args: []
skip_cleanup: false
10 changes: 6 additions & 4 deletions pkg/specs/apptype/determine_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ func (r *inspector) DetermineApplicationType(
}

upstream, subdir, isSingleFile := gogetter.UntreeGithub(upstream)
if !isSingleFile {
isSingleFile = gogetter.IsShipYaml(upstream)
}
if gogetter.IsGoGettable(upstream) {
// get with go-getter
fetcher := gogetter.GoGetter{Logger: r.logger, FS: r.fs, Subdir: subdir, IsSingleFile: isSingleFile}
Expand Down Expand Up @@ -137,10 +140,9 @@ func (r *inspector) determineTypeFromContents(
if err != nil {
return "", "", errors.Wrapf(err, "check for %s", filename)
}
}

if isReplicatedApp {
return "inline.replicated.app", finalPath, nil
if isReplicatedApp {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved this up because it checks for 2 different files, if the first is true and the second is false... 😢

return "inline.replicated.app", finalPath, nil
}
}

// if there's a Chart.yaml, assume its a chart
Expand Down
5 changes: 5 additions & 0 deletions pkg/specs/gogetter/go_getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,8 @@ func UntreeGithub(path string) (string, string, bool) {
}
return fmt.Sprintf("github.com/%s/%s?ref=%s//", githubURL.Owner, githubURL.Repo, githubURL.Ref), githubURL.Subdir, githubURL.IsBlob
}

func IsShipYaml(path string) bool {
base := filepath.Base(path)
return base == "ship.yaml" || base == "ship.yml"
}