From de7b38e43fbf17fc2a2bd37119512821b1813a20 Mon Sep 17 00:00:00 2001 From: Robert Oh Date: Tue, 6 Nov 2018 10:47:02 -0800 Subject: [PATCH 1/4] check if ship yml --- pkg/specs/apptype/determine_type.go | 10 ++++++---- pkg/specs/gogetter/go_getter.go | 5 +++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/pkg/specs/apptype/determine_type.go b/pkg/specs/apptype/determine_type.go index 97191a9a2..53381480b 100644 --- a/pkg/specs/apptype/determine_type.go +++ b/pkg/specs/apptype/determine_type.go @@ -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} @@ -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 { + return "inline.replicated.app", finalPath, nil + } } // if there's a Chart.yaml, assume its a chart diff --git a/pkg/specs/gogetter/go_getter.go b/pkg/specs/gogetter/go_getter.go index 338084c5d..5d8deb78a 100644 --- a/pkg/specs/gogetter/go_getter.go +++ b/pkg/specs/gogetter/go_getter.go @@ -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" +} From 9c147944a2b08bb60f960984b38084c31b126c29 Mon Sep 17 00:00:00 2001 From: Robert Oh Date: Tue, 6 Nov 2018 12:27:01 -0800 Subject: [PATCH 2/4] add integration --- integration/init/integration_test.go | 19 +++++++++++++++---- .../expected/.ship/state.json | 9 +++++++++ .../input/ship.yaml | 4 ++++ .../local-single-file-gogetter/metadata.yaml | 4 ++++ 4 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 integration/init/local-single-file-gogetter/expected/.ship/state.json create mode 100644 integration/init/local-single-file-gogetter/input/ship.yaml create mode 100644 integration/init/local-single-file-gogetter/metadata.yaml diff --git a/integration/init/integration_test.go b/integration/init/integration_test.go index 90fdd8f72..7c1b1724a 100644 --- a/integration/init/integration_test.go +++ b/integration/init/integration_test.go @@ -7,6 +7,7 @@ import ( "io/ioutil" "os" "path" + "path/filepath" "testing" "github.com/docker/docker/client" @@ -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"` } @@ -78,12 +79,22 @@ var _ = Describe("ship init with arbitrary upstream", func() { }, 20) It("Should output the expected files", func() { + 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()) + absoluteUpstream = fmt.Sprintf("file::%s", filepath.Join(pwdRoot, "..", relativePath)) + fmt.Println("absolute 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...)) diff --git a/integration/init/local-single-file-gogetter/expected/.ship/state.json b/integration/init/local-single-file-gogetter/expected/.ship/state.json new file mode 100644 index 000000000..2c8a480a8 --- /dev/null +++ b/integration/init/local-single-file-gogetter/expected/.ship/state.json @@ -0,0 +1,9 @@ +{ + "v1": { + "config": null, + "releaseName": "ship", + "upstream": "file::/Users/robert/go/src/github.com/replicatedhq/ship/integration/init/local-single-file-gogetter/input/ship.yaml", + "metadata": null, + "contentSHA": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" + } +} \ No newline at end of file diff --git a/integration/init/local-single-file-gogetter/input/ship.yaml b/integration/init/local-single-file-gogetter/input/ship.yaml new file mode 100644 index 000000000..4aad478c1 --- /dev/null +++ b/integration/init/local-single-file-gogetter/input/ship.yaml @@ -0,0 +1,4 @@ +lifecycle: + v1: + - message: + contents: "test message" diff --git a/integration/init/local-single-file-gogetter/metadata.yaml b/integration/init/local-single-file-gogetter/metadata.yaml new file mode 100644 index 000000000..0ab039006 --- /dev/null +++ b/integration/init/local-single-file-gogetter/metadata.yaml @@ -0,0 +1,4 @@ +upstream: "input/ship.yaml" +make_absolute: true +args: [] +skip_cleanup: false From ffde7ffc9c5263eca863681d0409cd8bad08fbd6 Mon Sep 17 00:00:00 2001 From: Robert Oh Date: Tue, 6 Nov 2018 13:59:10 -0800 Subject: [PATCH 3/4] update integration --- integration/init/integration_test.go | 9 ++++++--- .../local-single-file-gogetter/expected/.ship/state.json | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/integration/init/integration_test.go b/integration/init/integration_test.go index 7c1b1724a..c48873939 100644 --- a/integration/init/integration_test.go +++ b/integration/init/integration_test.go @@ -79,15 +79,18 @@ 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()) - absoluteUpstream = fmt.Sprintf("file::%s", filepath.Join(pwdRoot, "..", relativePath)) - fmt.Println("absolute upstream", absoluteUpstream) + absolutePath := filepath.Join(pwdRoot, "..") + absoluteUpstream = fmt.Sprintf("file::%s", filepath.Join(absolutePath, relativePath)) + replacements["__upstream__"] = absolutePath } cmd := cli.RootCmd() buf := new(bytes.Buffer) @@ -102,7 +105,7 @@ var _ = Describe("ship init with arbitrary upstream", func() { 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) diff --git a/integration/init/local-single-file-gogetter/expected/.ship/state.json b/integration/init/local-single-file-gogetter/expected/.ship/state.json index 2c8a480a8..a88bddad6 100644 --- a/integration/init/local-single-file-gogetter/expected/.ship/state.json +++ b/integration/init/local-single-file-gogetter/expected/.ship/state.json @@ -2,7 +2,7 @@ "v1": { "config": null, "releaseName": "ship", - "upstream": "file::/Users/robert/go/src/github.com/replicatedhq/ship/integration/init/local-single-file-gogetter/input/ship.yaml", + "upstream": "file::__upstream__/input/ship.yaml", "metadata": null, "contentSHA": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" } From 6e162433548abae48d22fabb41ba2c7ff50ec020 Mon Sep 17 00:00:00 2001 From: Robert Oh Date: Tue, 6 Nov 2018 14:53:15 -0800 Subject: [PATCH 4/4] address comment --- integration/init/integration_test.go | 2 +- .../init/local-single-file-gogetter/expected/.ship/state.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/integration/init/integration_test.go b/integration/init/integration_test.go index c48873939..735d7360a 100644 --- a/integration/init/integration_test.go +++ b/integration/init/integration_test.go @@ -90,7 +90,7 @@ var _ = Describe("ship init with arbitrary upstream", func() { Expect(err).NotTo(HaveOccurred()) absolutePath := filepath.Join(pwdRoot, "..") absoluteUpstream = fmt.Sprintf("file::%s", filepath.Join(absolutePath, relativePath)) - replacements["__upstream__"] = absolutePath + replacements["__upstream__"] = absoluteUpstream } cmd := cli.RootCmd() buf := new(bytes.Buffer) diff --git a/integration/init/local-single-file-gogetter/expected/.ship/state.json b/integration/init/local-single-file-gogetter/expected/.ship/state.json index a88bddad6..efa42fb35 100644 --- a/integration/init/local-single-file-gogetter/expected/.ship/state.json +++ b/integration/init/local-single-file-gogetter/expected/.ship/state.json @@ -2,7 +2,7 @@ "v1": { "config": null, "releaseName": "ship", - "upstream": "file::__upstream__/input/ship.yaml", + "upstream": "__upstream__", "metadata": null, "contentSHA": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" }