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

Commit

Permalink
Merge pull request #42 from ibuildthecloud/fix-parsing
Browse files Browse the repository at this point in the history
Fix parsing
  • Loading branch information
ibuildthecloud committed Jul 16, 2015
2 parents 4f2dab2 + 6c22a43 commit 993a0bf
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 10 deletions.
5 changes: 2 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@ import (
cliApp "github.com/docker/libcompose/app"
"github.com/docker/libcompose/command"
"github.com/rancherio/rancher-compose/app"
"github.com/rancherio/rancher-compose/version"
)

var VERSION = "0.0.0-dev"

func main() {
factory := &app.ProjectFactory{}

app := cli.NewApp()
app.Name = "rancher-compose"
app.Usage = "Docker-compose to Rancher"
app.Version = VERSION
app.Version = version.VERSION
app.Author = "Rancher Labs, Inc."
app.Email = ""
app.Before = cliApp.BeforeApp
Expand Down
15 changes: 12 additions & 3 deletions rancher/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,19 +364,19 @@ func (r *RancherService) getLbLinks() ([]interface{}, error) {
func (r *RancherService) getLbLinkPorts(name string) ([]string, error) {
labelName := "io.rancher.loadbalancer.target." + name
v := r.serviceConfig.Labels.MapParts()[labelName]
if len(v) == 0 {
if v == "" {
if len(r.serviceConfig.Ports) != 1 {
return nil, fmt.Errorf("Failed to find target ports for %s, add label %s", name, labelName)
}
parts := strings.SplitN(r.serviceConfig.Ports[0], ",", 2)
parts := TrimSplit(TrimSplit(r.serviceConfig.Ports[0], "/", 2)[0], ":", 2)
if len(parts) == 2 {
return []string{parts[1]}, nil
} else {
return []string{parts[0]}, nil
}
}

return strings.Split(v, ","), nil
return TrimSplit(v, ",", -1), nil
}

func (r *RancherService) getServiceLinks() ([]interface{}, error) {
Expand Down Expand Up @@ -710,3 +710,12 @@ func (r *RancherService) DependentServices() []project.ServiceRelationship {
func (r *RancherService) Pull() error {
return nil
}

func TrimSplit(str, sep string, count int) []string {
result := []string{}
for _, i := range strings.SplitN(strings.TrimSpace(str), sep, count) {
result = append(result, strings.TrimSpace(i))
}

return result
}
4 changes: 2 additions & 2 deletions scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ get_version
echo export GOPATH=$GOPATH
echo VERSION=$VERSION

go build -ldflags="-w -X github.com/docker/libcompose.VERSION $VERSION" -o bin/${PROJECT}
go build -ldflags="-w -X github.com/rancherio/rancher-compose/version.VERSION $VERSION" -o bin/${PROJECT}

if [ -n "$BUILD_CROSS" ]; then
rm -rf build/bin
mkdir -p build/bin
gox -os="darwin linux windows" -arch="386 amd64 arm" -output="build/bin/rancher-compose_{{.OS}}-{{.Arch}}" -ldflags="-w -X github.com/docker/libcompose.VERSION $VERSION"
gox -os="darwin linux windows" -arch="386 amd64 arm" -output="build/bin/rancher-compose_{{.OS}}-{{.Arch}}" -ldflags="-w -X github.com/rancherio/rancher-compose/version.VERSION $VERSION"
fi
125 changes: 123 additions & 2 deletions tests/integration/cattletest/core/test_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,129 @@ def test_lb(client, compose):
project = find_one(client.list_environment, name=project_name)
assert len(project.services()) == 3
lb = _get_service(project.services(), 'lb')
_get_service(project.services(), 'web')
_get_service(project.services(), 'web2')
web = _get_service(project.services(), 'web')
web2 = _get_service(project.services(), 'web2')

maps = client.list_service_consume_map(serviceId=lb.id)
assert len(maps) == 2

for map in maps:
if map.consumedServiceId == web.id:
assert map.ports == ['80']
elif map.consumedServiceId == web2.id:
assert map.ports == ['80']
else:
assert False

assert lb.type == 'loadBalancerService'


def test_lb_default_port_http(client, compose):
template = '''
lb:
image: rancher/load-balancer-service
ports:
- 7900:80/tcp
links:
- web
web:
image: nginx
'''

project_name = create_project(compose, input=template)

project = find_one(client.list_environment, name=project_name)
assert len(project.services()) == 2
lb = _get_service(project.services(), 'lb')
web = _get_service(project.services(), 'web')
assert lb.launchConfig.ports == ['7900:80/tcp']

map = find_one(client.list_service_consume_map, serviceId=lb.id)
assert map.consumedServiceId == web.id
assert map.ports == ['80']


def test_lb_default_port_with_mapped_tcp(client, compose):
template = '''
lb:
image: rancher/load-balancer-service
ports:
- 80:8080/tcp
links:
- web
web:
image: nginx
'''

project_name = create_project(compose, input=template)

project = find_one(client.list_environment, name=project_name)
assert len(project.services()) == 2
lb = _get_service(project.services(), 'lb')
assert lb.launchConfig.ports == ['80:8080/tcp']

web = _get_service(project.services(), 'web')

map = find_one(client.list_service_consume_map, serviceId=lb.id)
assert map.consumedServiceId == web.id
assert map.ports == ['8080']


def test_lb_default_port_with_tcp(client, compose):
template = '''
lb:
image: rancher/load-balancer-service
ports:
- 80/tcp
links:
- web
web:
image: nginx
'''

project_name = create_project(compose, input=template)

project = find_one(client.list_environment, name=project_name)
assert len(project.services()) == 2
lb = _get_service(project.services(), 'lb')
web = _get_service(project.services(), 'web')

map = find_one(client.list_service_consume_map, serviceId=lb.id)
assert map.consumedServiceId == web.id
assert map.ports == ['80']


def test_lb_path_space_target(client, compose):
template = '''
lb:
image: rancher/load-balancer-service
ports:
- 80:8080
labels:
io.rancher.loadbalancer.target.web: "6000:hostname/path,
7000"
links:
- web
web:
image: nginx
'''

project_name = create_project(compose, input=template)

project = find_one(client.list_environment, name=project_name)
assert len(project.services()) == 2
lb = _get_service(project.services(), 'lb')
web = _get_service(project.services(), 'web')

maps = client.list_service_consume_map(serviceId=lb.id)
assert len(maps) == 1

for map in maps:
if map.consumedServiceId == web.id:
assert map.ports == ['6000:hostname/path',
'7000']
else:
assert False

assert lb.type == 'loadBalancerService'

Expand Down
3 changes: 3 additions & 0 deletions version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package version

var VERSION = "0.0.0-dev"

0 comments on commit 993a0bf

Please sign in to comment.