diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1259d3c..58e3944 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -75,9 +75,78 @@ jobs: cf delete-route -f apic.eu-gb.mybluemix.net --hostname puppeteer cf delete-route -f eu-gb.mybluemix.net --hostname puppeteer + int_var_test_job: + name: Run integration tests with vars file + runs-on: ubuntu-latest + needs: [unit_test_job, int_test_job] + steps: + - name: Add CF Cli to apt-get + run: | + wget -q -O - https://packages.cloudfoundry.org/debian/cli.cloudfoundry.org.key | sudo apt-key add - + echo "deb https://packages.cloudfoundry.org/debian stable main" | sudo tee /etc/apt/sources.list.d/cloudfoundry-cli.list + - name: Install CF CLI + run: | + sudo apt-get update + sudo apt-get install cf-cli + - name: Checkout + uses: actions/checkout@v2 + - name: Compile plugin + run: | + mkdir -p ./artifacts + CGO_ENABLED=0 GOARCH=amd64 GOOS=linux go build -o ./artifacts/cf-puppeteer + - name: Install Puppeteer plugin + run: | + cf install-plugin -f ./artifacts/cf-puppeteer + cf plugins + - name: CF Login + run: | + cf login -a ${{ secrets.API_BM }} -u ${{secrets.USER_NAME_BM}} -p ${{secrets.PASSWORD_BM}} -o ${{secrets.ORG_BM}} -s dev + - name: Deploy test application with vars file + run: | + cf zero-downtime-push -f test/integration/application/manifest-vars.yml -p test/integration/application/ --vars-file test/integration/application/vars.yml + - name: Check deployment with vars file (route) + run: | + status_code=$(curl --write-out %{http_code} --silent --output /dev/null puppeteer2.eu-gb.mybluemix.net) + echo "Curl response status code: $status_code" + if [[ "$status_code" -ne 200 ]] ; then + exit 1 + else + exit 0 + fi + - name: Show application + run: | + cf apps + cf app puppeteer2 + - name: Delete application + run: | + cf delete -f puppeteer + cf delete-route -f apps.internal --hostname puppeteer2 + cf delete-route -f apic.eu-gb.mybluemix.net --hostname puppeteer2 + cf delete-route -f eu-gb.mybluemix.net --hostname puppeteer2 + - name: Deploy test application with vars file (legacy-push) + run: | + cf zero-downtime-push -f test/integration/application/manifest-vars.yml -p test/integration/application/ --vars-file test/integration/application/vars.yml --legacy-push + - name: Check legacy deployment with vars file (route) + run: | + status_code=$(curl --write-out %{http_code} --silent --output /dev/null puppeteer2.eu-gb.mybluemix.net) + if [[ "$status_code" -ne 200 ]] ; then + exit 1 + else + exit 0 + fi + - name: Show application + run: | + cf app puppeteer2 + - name: Delete application + run: | + cf delete -f puppeteer + cf delete-route -f apps.internal --hostname puppeteer2 + cf delete-route -f apic.eu-gb.mybluemix.net --hostname puppeteer2 + cf delete-route -f eu-gb.mybluemix.net --hostname puppeteer2 + release_job: name: Build binary - needs: [unit_test_job, int_test_job] + needs: [unit_test_job, int_test_job, int_var_test_job] runs-on: ubuntu-latest #if: github.ref == 'refs/heads/develop' steps: diff --git a/CHANGELOG.md b/CHANGELOG.md index 6cae859..d179f44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - check space quota before deployment (if user pass the option) - set timeout how long the deployment will wait for more / free space +## [1.2.1] - 2020-04-30 + +### Fixed +- find matching routes +- pss a vars file combined with 'legacy-push' + +### Changed +- add more trace logging +- make tests more stable + ## [1.2.0] - 2020-02-24 ### Added diff --git a/README.md b/README.md index a4f17f4..ed19522 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ To get an overview of the changes between versions, read the [changelog](CHANGEL ## Version -The latest version of *CF-Puppeteer* is *1.2.0*. It works with and is based on Cloud Foundry CLI version 6.43.0. +The latest version of *CF-Puppeteer* is *1.2.1*. It works with and is based on Cloud Foundry CLI version 6.43.0. For more details on the most recent release, check out the [changelog](CHANGELOG.md). diff --git a/cf/v2/domain.go b/cf/v2/domain.go index b70b8ef..cd7cf0b 100644 --- a/cf/v2/domain.go +++ b/cf/v2/domain.go @@ -5,6 +5,8 @@ import ( "fmt" "sort" "strings" + + "github.com/happytobi/cf-puppeteer/ui" ) type Routes struct { @@ -34,32 +36,34 @@ type DomainResponse struct { func (resource *LegacyResourcesData) GetDomain(domains []map[string]string) (*[]Routes, error) { //default order asc. + ui.DebugMessage("GetDomain called, try to find matching domains for all routes %v", domains) path := fmt.Sprintf(`/v2/domains`) - response, err := resource.getDomain(path) if err != nil { return nil, err } - + ui.DebugMessage("/v2/domain response was %v", path) domainGUID := make(map[string]Routes) + for _, domainRes := range response.Resources { for _, routes := range domains { - domain := routes["route"] - hostName := strings.ReplaceAll(domain, domainRes.Entity.Name, "") - - _, exists := domainGUID[domain] - if exists { - exists = len(domainGUID[domain].Host) < len(hostName) - } + for _, domain := range routes { + hostName := strings.ReplaceAll(domain, domainRes.Entity.Name, "") + _, exists := domainGUID[domain] + if exists { + exists = len(domainGUID[domain].Host) < len(hostName) + } - //question ist when route matches 2 time what kind of your we are using? - if strings.Contains(domain, domainRes.Entity.Name) && len(hostName) > 0 && !exists { - hostName = strings.TrimRight(hostName, ".") - newRoute := &Routes{ - Host: hostName, - Domain: domainRes.Entity.Name, + //question ist when route matches 2 time what kind of your we are using? + if strings.Contains(domain, domainRes.Entity.Name) && !exists { + hostName = strings.TrimRight(hostName, ".") + newRoute := &Routes{ + Host: hostName, + Domain: domainRes.Entity.Name, + } + ui.DebugMessage("add new route for later mapping %v", newRoute) + domainGUID[domain] = *newRoute } - domainGUID[domain] = *newRoute } } } @@ -74,14 +78,20 @@ func (resource *LegacyResourcesData) GetDomain(domains []map[string]string) (*[] for _, domainRes := range response.Resources { for _, routes := range domains { for _, domain := range routes { + hostName := strings.ReplaceAll(domain, domainRes.Entity.Name, "") _, exists := domainGUID[domain] + if exists { + exists = len(domainGUID[domain].Host) < len(hostName) + } + + //question ist when route matches 2 time what kind of your we are using? if strings.Contains(domain, domainRes.Entity.Name) && !exists { - hostName := strings.ReplaceAll(domain, domainRes.Entity.Name, "") hostName = strings.TrimRight(hostName, ".") newRoute := &Routes{ Host: hostName, Domain: domainRes.Entity.Name, } + ui.DebugMessage("add new route for later mapping (paged) %v", newRoute) domainGUID[domain] = *newRoute } } diff --git a/cf/v2/domain_test.go b/cf/v2/domain_test.go index 2d733d1..8158356 100644 --- a/cf/v2/domain_test.go +++ b/cf/v2/domain_test.go @@ -97,18 +97,65 @@ var _ = Describe("cf-domain test", func() { domainResponse, err := resourcesData.GetDomain(routes) Expect(cliConn.CliCommandWithoutTerminalOutputCallCount()).To(Equal(1)) + Expect(4).To(Equal(len(*domainResponse))) - checkMap := make(map[string]string,len(*domainResponse)) - for _, value := range (*domainResponse) { + checkMap := make(map[string]string, len(*domainResponse)) + for _, value := range *domainResponse { checkMap[value.Host] = value.Domain } - - Expect(checkMap["foo"]).To(Equal("example.com")) Expect(checkMap["my"]).To(Equal("foo.example.com")) Expect(checkMap["puppeteer"]).To(Equal("internal.emea.github.com")) Expect(checkMap["url"]).To(Equal("test-domain.com")) + Expect(err).ToNot(HaveOccurred()) + }) + + It("use v2 domain api with multiple subdomains ", func() { + response := []string{`{ + "total_results": 18, + "total_pages": 2, + "prev_url": null, + "next_url": "https://api.example.org/v2/domains?page=1&per_page=2", + "resources": [ + { + "metadata": { + "guid": "aa23b15e-dc54-437e-a651-a29415b66d9m", + "url": "/v2/shared_domains/aa23b15e-dc54-437e-a651-a29415b66d9m", + "created_at": "2016-10-20T07:40:24Z", + "updated_at": "2018-02-09T06:19:46Z" + }, + "entity": { + "name": "staging.product.com", + "internal": false, + "router_group_guid": null, + "router_group_type": null + } + }, + { + "metadata": { + "guid": "aa23b15e-dc54-437e-a651-5673241243", + "url": "/v2/shared_domains/aa23b15e-dc54-437e-a651-5673241243", + "created_at": "2016-10-20T07:40:24Z", + "updated_at": "2018-02-09T06:19:46Z" + }, + "entity": { + "name": "cfapp.io", + "internal": false, + "router_group_guid": null, + "router_group_type": null + } + } + ]} + `} + + cliConn.CliCommandWithoutTerminalOutputReturns(response, nil) + + var routes = []map[string]string{0: {"route": " staging-p.cfapp.io"}, 1: {"route": "staging-product.cfapp.io"}, 2: {"route": "staging.product.com"}} + domainResponse, err := resourcesData.GetDomain(routes) + + Expect(cliConn.CliCommandWithoutTerminalOutputCallCount()).To(Equal(1)) + Expect(3).To(Equal(len(*domainResponse))) Expect(err).ToNot(HaveOccurred()) }) diff --git a/cf/v2/push_application.go b/cf/v2/push_application.go index 4b715ec..36ad878 100644 --- a/cf/v2/push_application.go +++ b/cf/v2/push_application.go @@ -1,13 +1,14 @@ package v2 import ( - "code.cloudfoundry.org/cli/plugin" "fmt" + "strconv" + + "code.cloudfoundry.org/cli/plugin" "github.com/happytobi/cf-puppeteer/arguments" "github.com/happytobi/cf-puppeteer/cf/cli" "github.com/happytobi/cf-puppeteer/ui" "github.com/pkg/errors" - "strconv" ) //Push interface with all v3 actions @@ -51,6 +52,10 @@ func (resource *LegacyResourcesData) PushApplication(parsedArguments *arguments. args = append(args, "--no-start") } + if parsedArguments.VarsFile != "" { + args = append(args, "--vars-file", parsedArguments.VarsFile) + } + ui.Say("start pushing application with arguments %s", args) err := resource.Executor.Execute(args) if err != nil { diff --git a/cf/v3/domain_test.go b/cf/v3/domain_test.go index c9973ef..e58b328 100644 --- a/cf/v3/domain_test.go +++ b/cf/v3/domain_test.go @@ -1,10 +1,11 @@ package v3_test import ( + "testing" + "code.cloudfoundry.org/cli/plugin/pluginfakes" "github.com/happytobi/cf-puppeteer/cf/cli" v3 "github.com/happytobi/cf-puppeteer/cf/v3" - "testing" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" @@ -103,13 +104,15 @@ var _ = Describe("cf-domain test", func() { Expect(cliConn.CliCommandWithoutTerminalOutputCallCount()).To(Equal(1)) - Expect((*domainResponse)[0].Host).To(Equal("foo")) - Expect((*domainResponse)[0].Domain).To(Equal("example.com")) + checkMap := make(map[string]string, len(*domainResponse)) + for _, value := range *domainResponse { + checkMap[value.Host] = value.Domain + } - Expect((*domainResponse)[1].Host).To(Equal("url")) - Expect((*domainResponse)[1].Domain).To(Equal("test-domain.com")) + Expect(checkMap["foo"]).To(Equal("example.com")) + Expect(checkMap["url"]).To(Equal("test-domain.com")) Expect(err).ToNot(HaveOccurred()) }) }) -}) \ No newline at end of file +}) diff --git a/puppeteer.go b/puppeteer.go index 9ec4daf..b78fcc7 100644 --- a/puppeteer.go +++ b/puppeteer.go @@ -217,7 +217,7 @@ func (CfPuppeteerPlugin) GetMetadata() plugin.PluginMetadata { Version: plugin.VersionType{ Major: 1, Minor: 2, - Build: 0, + Build: 1, }, Commands: []plugin.Command{ { diff --git a/test/integration/application/manifest-vars.yml b/test/integration/application/manifest-vars.yml new file mode 100644 index 0000000..06fea17 --- /dev/null +++ b/test/integration/application/manifest-vars.yml @@ -0,0 +1,15 @@ +--- +applications: + - name: ((appname)) + memory: ((memory)) + buildpacks: + - nginx_buildpack + instances: 1 + health-check-type: http + health-check-http-endpoint: /health + routes: + - route: ((route)).apps.internal + - route: ((route)).eu-gb.mybluemix.net + - route: ((route)).apic.eu-gb.mybluemix.net + env: + GITHUB: https://github.com/HappyTobi/cf-puppeteer \ No newline at end of file diff --git a/test/integration/application/vars.yml b/test/integration/application/vars.yml new file mode 100644 index 0000000..1c70633 --- /dev/null +++ b/test/integration/application/vars.yml @@ -0,0 +1,3 @@ +appname: puppeteer2 +memory: 64mb +route: puppeteer2 \ No newline at end of file