From 670d8423e5bfe64236f2894cf74cd9817f7254bf Mon Sep 17 00:00:00 2001 From: Tuna Date: Fri, 21 Oct 2016 01:35:19 +0200 Subject: [PATCH] remove tag experimental --- README.md | 6 ++-- pkg/loader/bundle/bundle.go | 62 ++++++++++++++++++++++++++++++++++--- script/.build | 2 +- 3 files changed, 60 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 95c0f343..0bd6196d 100644 --- a/README.md +++ b/README.md @@ -64,15 +64,13 @@ $ make binary Or `go build`: ```console -$ go build -tags experimental -o kompose ./cli/main +$ go build -o kompose ./cli/main ``` -You need `-tags experimental` because the current `bundlefile` package of docker/libcompose is still experimental. - If you have `go` v1.5, it's still good to build `kompose` with the following settings: ```console -$ CGO_ENABLED=0 GO15VENDOREXPERIMENT=1 go build -o kompose -tags experimental ./cli/main +$ CGO_ENABLED=0 GO15VENDOREXPERIMENT=1 go build -o kompose ./cli/main ``` To create a multi-platform binary, use the `binary-cross` command via `make`: diff --git a/pkg/loader/bundle/bundle.go b/pkg/loader/bundle/bundle.go index 6cc70d40..7acec22d 100644 --- a/pkg/loader/bundle/bundle.go +++ b/pkg/loader/bundle/bundle.go @@ -17,21 +17,48 @@ limitations under the License. package bundle import ( + "encoding/json" + "fmt" + "io" "io/ioutil" "strings" "k8s.io/kubernetes/pkg/api" "github.com/Sirupsen/logrus" - "github.com/docker/docker/cli/command/bundlefile" "github.com/kubernetes-incubator/kompose/pkg/kobject" ) type Bundle struct { } +// Bundlefile stores the contents of a bundlefile +type Bundlefile struct { + Version string + Services map[string]Service +} + +// Service is a service from a bundlefile +type Service struct { + Image string + Command []string `json:",omitempty"` + Args []string `json:",omitempty"` + Env []string `json:",omitempty"` + Labels map[string]string `json:",omitempty"` + Ports []Port `json:",omitempty"` + WorkingDir *string `json:",omitempty"` + User *string `json:",omitempty"` + Networks []string `json:",omitempty"` +} + +// Port is a port as defined in a bundlefile +type Port struct { + Protocol string + Port uint32 +} + // load image from dab file -func loadImage(service bundlefile.Service) (string, string) { +func loadImage(service Service) (string, string) { character := "@" if strings.Contains(service.Image, character) { return service.Image[0:strings.Index(service.Image, character)], "" @@ -40,7 +67,7 @@ func loadImage(service bundlefile.Service) (string, string) { } // load environment variables from dab file -func loadEnvVars(service bundlefile.Service) ([]kobject.EnvVar, string) { +func loadEnvVars(service Service) ([]kobject.EnvVar, string) { envs := []kobject.EnvVar{} for _, env := range service.Env { character := "=" @@ -77,7 +104,7 @@ func loadEnvVars(service bundlefile.Service) ([]kobject.EnvVar, string) { } // load ports from dab file -func loadPorts(service bundlefile.Service) ([]kobject.Ports, string) { +func loadPorts(service Service) ([]kobject.Ports, string) { ports := []kobject.Ports{} for _, port := range service.Ports { var p api.Protocol @@ -109,7 +136,7 @@ func (b *Bundle) LoadFile(file string) kobject.KomposeObject { logrus.Fatalf("Failed to read bundles file: ", err) } reader := strings.NewReader(string(buf)) - bundle, err := bundlefile.LoadFile(reader) + bundle, err := loadFile(reader) if err != nil { logrus.Fatalf("Failed to parse bundles file: ", err) } @@ -150,3 +177,28 @@ func (b *Bundle) LoadFile(file string) kobject.KomposeObject { return komposeObject } + +// LoadFile loads a bundlefile from a path to the file +func loadFile(reader io.Reader) (*Bundlefile, error) { + bundlefile := &Bundlefile{} + + decoder := json.NewDecoder(reader) + if err := decoder.Decode(bundlefile); err != nil { + switch jsonErr := err.(type) { + case *json.SyntaxError: + return nil, fmt.Errorf( + "JSON syntax error at byte %v: %s", + jsonErr.Offset, + jsonErr.Error()) + case *json.UnmarshalTypeError: + return nil, fmt.Errorf( + "Unexpected type at byte %v. Expected %s but received %s.", + jsonErr.Offset, + jsonErr.Type, + jsonErr.Value) + } + return nil, err + } + + return bundlefile, nil +} diff --git a/script/.build b/script/.build index d55c7737..ca655a6e 100644 --- a/script/.build +++ b/script/.build @@ -2,4 +2,4 @@ GITCOMMIT=$(git rev-parse --short HEAD) -BUILD_FLAGS=(-tags experimental -ldflags="-w -X github.com/kubernetes-incubator/kompose/version.GITCOMMIT=${GITCOMMIT}") +BUILD_FLAGS=(-ldflags="-w -X github.com/kubernetes-incubator/kompose/version.GITCOMMIT=${GITCOMMIT}")