make loader, transformer as interfaces

This commit is contained in:
Tuna
2016-08-11 23:33:45 +07:00
parent d532b29d95
commit f10d6afecf
10 changed files with 548 additions and 320 deletions
@@ -14,16 +14,20 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package loader
package bundle
import (
"io/ioutil"
"strings"
"github.com/Sirupsen/logrus"
"github.com/docker/docker/api/client/bundlefile"
"github.com/skippbox/kompose/pkg/kobject"
"io/ioutil"
"strings"
)
type Bundle struct {
}
// load Image from bundles file
func loadImage(service bundlefile.Service) (string, string) {
character := "@"
@@ -93,7 +97,7 @@ func loadPortsfromBundle(service bundlefile.Service) ([]kobject.Ports, string) {
}
// load Bundlefile into KomposeObject
func LoadBundle(file string) kobject.KomposeObject {
func (b *Bundle) LoadFile(file string) kobject.KomposeObject {
komposeObject := kobject.KomposeObject{
ServiceConfigs: make(map[string]kobject.ServiceConfig),
}
@@ -14,21 +14,25 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package loader
package compose
import (
"github.com/Sirupsen/logrus"
"github.com/docker/libcompose/docker"
"github.com/docker/libcompose/project"
"github.com/skippbox/kompose/pkg/kobject"
"os"
"path/filepath"
"strconv"
"strings"
"github.com/docker/libcompose/lookup"
"os"
"github.com/Sirupsen/logrus"
"github.com/docker/libcompose/config"
"path/filepath"
"github.com/docker/libcompose/docker"
"github.com/docker/libcompose/lookup"
"github.com/docker/libcompose/project"
"github.com/skippbox/kompose/pkg/kobject"
)
type Compose struct {
}
// load Environment Variable from compose file
func loadEnvVarsfromCompose(e map[string]string) []kobject.EnvVar {
envs := []kobject.EnvVar{}
@@ -81,7 +85,7 @@ func loadPortsFromCompose(composePorts []string) ([]kobject.Ports, string) {
}
// load Docker Compose file into KomposeObject
func LoadCompose(file string) kobject.KomposeObject {
func (c *Compose) LoadFile(file string) kobject.KomposeObject {
komposeObject := kobject.KomposeObject{
ServiceConfigs: make(map[string]kobject.ServiceConfig),
}
@@ -92,23 +96,23 @@ func LoadCompose(file string) kobject.KomposeObject {
context.ComposeFiles = []string{file}
if context.ResourceLookup == nil {
context.ResourceLookup = &lookup.FileResourceLookup{}
}
context.ResourceLookup = &lookup.FileResourceLookup{}
}
if context.EnvironmentLookup == nil {
cwd, err := os.Getwd()
if err != nil {
return kobject.KomposeObject{}
}
context.EnvironmentLookup = &lookup.ComposableEnvLookup{
Lookups: []config.EnvironmentLookup{
&lookup.EnvfileLookup{
Path: filepath.Join(cwd, ".env"),
},
&lookup.OsEnvLookup{},
},
}
if context.EnvironmentLookup == nil {
cwd, err := os.Getwd()
if err != nil {
return kobject.KomposeObject{}
}
context.EnvironmentLookup = &lookup.ComposableEnvLookup{
Lookups: []config.EnvironmentLookup{
&lookup.EnvfileLookup{
Path: filepath.Join(cwd, ".env"),
},
&lookup.OsEnvLookup{},
},
}
}
// load compose file into composeObject
composeObject := project.NewProject(&context.Context, nil, nil)
+23
View File
@@ -0,0 +1,23 @@
/*
Copyright 2016 Skippbox, Ltd All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package loader
import "github.com/skippbox/kompose/pkg/kobject"
type Loader interface {
LoadFile(file string) kobject.KomposeObject
}