Skip to content
This repository has been archived by the owner on Jan 20, 2025. It is now read-only.

Commit

Permalink
Merge pull request #23 from HappyTobi/1.2.1
Browse files Browse the repository at this point in the history
New release 1.2.1
  • Loading branch information
HappyTobi authored Apr 30, 2020
2 parents 90ddef3 + fcc8aa5 commit def5200
Show file tree
Hide file tree
Showing 10 changed files with 194 additions and 32 deletions.
71 changes: 70 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down
44 changes: 27 additions & 17 deletions cf/v2/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"sort"
"strings"

"github.com/happytobi/cf-puppeteer/ui"
)

type Routes struct {
Expand Down Expand Up @@ -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
}
}
}
Expand All @@ -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
}
}
Expand Down
55 changes: 51 additions & 4 deletions cf/v2/domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
})
Expand Down
9 changes: 7 additions & 2 deletions cf/v2/push_application.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 {
Expand Down
15 changes: 9 additions & 6 deletions cf/v3/domain_test.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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())
})
})
})
})
2 changes: 1 addition & 1 deletion puppeteer.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func (CfPuppeteerPlugin) GetMetadata() plugin.PluginMetadata {
Version: plugin.VersionType{
Major: 1,
Minor: 2,
Build: 0,
Build: 1,
},
Commands: []plugin.Command{
{
Expand Down
15 changes: 15 additions & 0 deletions test/integration/application/manifest-vars.yml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions test/integration/application/vars.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
appname: puppeteer2
memory: 64mb
route: puppeteer2

0 comments on commit def5200

Please sign in to comment.