mirror of https://github.com/docker/compose.git
remove unused utils pkg
Signed-off-by: aiordache <anca.iordache@docker.com>
This commit is contained in:
parent
1574ebdfff
commit
f09a57351f
1
go.mod
1
go.mod
|
@ -45,7 +45,6 @@ require (
|
||||||
github.com/opencontainers/go-digest v1.0.0
|
github.com/opencontainers/go-digest v1.0.0
|
||||||
github.com/opencontainers/image-spec v1.0.1
|
github.com/opencontainers/image-spec v1.0.1
|
||||||
github.com/pkg/errors v0.9.1
|
github.com/pkg/errors v0.9.1
|
||||||
github.com/prometheus/common v0.10.0
|
|
||||||
github.com/prometheus/tsdb v0.10.0
|
github.com/prometheus/tsdb v0.10.0
|
||||||
github.com/sanathkr/go-yaml v0.0.0-20170819195128-ed9d249f429b
|
github.com/sanathkr/go-yaml v0.0.0-20170819195128-ed9d249f429b
|
||||||
github.com/sirupsen/logrus v1.7.0
|
github.com/sirupsen/logrus v1.7.0
|
||||||
|
|
|
@ -20,6 +20,7 @@ package charts
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -28,7 +29,6 @@ import (
|
||||||
"github.com/docker/compose-cli/api/context/store"
|
"github.com/docker/compose-cli/api/context/store"
|
||||||
"github.com/docker/compose-cli/kube/charts/helm"
|
"github.com/docker/compose-cli/kube/charts/helm"
|
||||||
"github.com/docker/compose-cli/kube/charts/kubernetes"
|
"github.com/docker/compose-cli/kube/charts/kubernetes"
|
||||||
kubeutils "github.com/docker/compose-cli/kube/utils"
|
|
||||||
chart "helm.sh/helm/v3/pkg/chart"
|
chart "helm.sh/helm/v3/pkg/chart"
|
||||||
util "helm.sh/helm/v3/pkg/chartutil"
|
util "helm.sh/helm/v3/pkg/chartutil"
|
||||||
helmenv "helm.sh/helm/v3/pkg/cli"
|
helmenv "helm.sh/helm/v3/pkg/cli"
|
||||||
|
@ -57,7 +57,7 @@ var _ API = sdk{}
|
||||||
|
|
||||||
func NewSDK(ctx store.KubeContext) (sdk, error) {
|
func NewSDK(ctx store.KubeContext) (sdk, error) {
|
||||||
return sdk{
|
return sdk{
|
||||||
environment: kubeutils.Environment(),
|
environment: environment(),
|
||||||
h: helm.NewHelmActions(nil),
|
h: helm.NewHelmActions(nil),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
@ -124,3 +124,13 @@ func (s sdk) GenerateChart(project *types.Project, dirname string) error {
|
||||||
dirname = filepath.Dir(dirname)
|
dirname = filepath.Dir(dirname)
|
||||||
return s.SaveChart(project, dirname)
|
return s.SaveChart(project, dirname)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func environment() map[string]string {
|
||||||
|
vars := make(map[string]string)
|
||||||
|
env := os.Environ()
|
||||||
|
for _, v := range env {
|
||||||
|
k := strings.SplitN(v, "=", 2)
|
||||||
|
vars[k[0]] = k[1]
|
||||||
|
}
|
||||||
|
return vars
|
||||||
|
}
|
||||||
|
|
|
@ -1,142 +0,0 @@
|
||||||
// +build kube
|
|
||||||
|
|
||||||
/*
|
|
||||||
Copyright 2020 Docker Compose CLI authors
|
|
||||||
|
|
||||||
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 utils
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"regexp"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/compose-spec/compose-go/loader"
|
|
||||||
"github.com/compose-spec/compose-go/types"
|
|
||||||
"github.com/prometheus/common/log"
|
|
||||||
)
|
|
||||||
|
|
||||||
var SupportedFilenames = []string{"compose.yaml", "compose.yml", "docker-compose.yml", "docker-compose.yaml"}
|
|
||||||
|
|
||||||
func GetConfigs(name string, configPaths []string) (string, []types.ConfigFile, error) {
|
|
||||||
configPath, err := getConfigPaths(configPaths)
|
|
||||||
if err != nil {
|
|
||||||
return "", nil, err
|
|
||||||
}
|
|
||||||
if configPath == nil {
|
|
||||||
return "", nil, nil
|
|
||||||
}
|
|
||||||
workingDir := filepath.Dir(configPath[0])
|
|
||||||
|
|
||||||
if name == "" {
|
|
||||||
name = os.Getenv("COMPOSE_PROJECT_NAME")
|
|
||||||
}
|
|
||||||
if name == "" {
|
|
||||||
r := regexp.MustCompile(`[^a-z0-9\\-_]+`)
|
|
||||||
name = r.ReplaceAllString(strings.ToLower(filepath.Base(workingDir)), "")
|
|
||||||
}
|
|
||||||
|
|
||||||
configs, err := parseConfigs(configPath)
|
|
||||||
if err != nil {
|
|
||||||
return "", nil, err
|
|
||||||
}
|
|
||||||
return workingDir, configs, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func getConfigPaths(configPaths []string) ([]string, error) {
|
|
||||||
paths := []string{}
|
|
||||||
pwd, err := os.Getwd()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(configPaths) != 0 {
|
|
||||||
for _, f := range configPaths {
|
|
||||||
if f == "-" {
|
|
||||||
paths = append(paths, f)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if !filepath.IsAbs(f) {
|
|
||||||
f = filepath.Join(pwd, f)
|
|
||||||
}
|
|
||||||
if _, err := os.Stat(f); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
paths = append(paths, f)
|
|
||||||
}
|
|
||||||
return paths, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
sep := os.Getenv("COMPOSE_FILE_SEPARATOR")
|
|
||||||
if sep == "" {
|
|
||||||
sep = string(os.PathListSeparator)
|
|
||||||
}
|
|
||||||
f := os.Getenv("COMPOSE_FILE")
|
|
||||||
if f != "" {
|
|
||||||
return strings.Split(f, sep), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
for {
|
|
||||||
candidates := []string{}
|
|
||||||
for _, n := range SupportedFilenames {
|
|
||||||
f := filepath.Join(pwd, n)
|
|
||||||
if _, err := os.Stat(f); err == nil {
|
|
||||||
candidates = append(candidates, f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(candidates) > 0 {
|
|
||||||
winner := candidates[0]
|
|
||||||
if len(candidates) > 1 {
|
|
||||||
log.Warnf("Found multiple config files with supported names: %s", strings.Join(candidates, ", "))
|
|
||||||
log.Warnf("Using %s\n", winner)
|
|
||||||
}
|
|
||||||
return []string{winner}, nil
|
|
||||||
}
|
|
||||||
parent := filepath.Dir(pwd)
|
|
||||||
if parent == pwd {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
pwd = parent
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseConfigs(configPaths []string) ([]types.ConfigFile, error) {
|
|
||||||
files := []types.ConfigFile{}
|
|
||||||
for _, f := range configPaths {
|
|
||||||
var (
|
|
||||||
b []byte
|
|
||||||
err error
|
|
||||||
)
|
|
||||||
if f == "-" {
|
|
||||||
b, err = ioutil.ReadAll(os.Stdin)
|
|
||||||
} else {
|
|
||||||
if _, err := os.Stat(f); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
b, err = ioutil.ReadFile(f)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
config, err := loader.ParseYAML(b)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
files = append(files, types.ConfigFile{Filename: f, Config: config})
|
|
||||||
}
|
|
||||||
return files, nil
|
|
||||||
}
|
|
|
@ -1,56 +0,0 @@
|
||||||
// +build kube
|
|
||||||
|
|
||||||
/*
|
|
||||||
Copyright 2020 Docker Compose CLI authors
|
|
||||||
|
|
||||||
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 utils
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
func CombineErrors(errors []error) error {
|
|
||||||
if len(errors) == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
if len(errors) == 1 {
|
|
||||||
return errors[0]
|
|
||||||
}
|
|
||||||
err := combinedError{}
|
|
||||||
for _, e := range errors {
|
|
||||||
if c, ok := e.(combinedError); ok {
|
|
||||||
err.errors = append(err.errors, c.errors...)
|
|
||||||
} else {
|
|
||||||
err.errors = append(err.errors, e)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return combinedError{errors}
|
|
||||||
}
|
|
||||||
|
|
||||||
type combinedError struct {
|
|
||||||
errors []error
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c combinedError) Error() string {
|
|
||||||
points := make([]string, len(c.errors))
|
|
||||||
for i, err := range c.errors {
|
|
||||||
points[i] = fmt.Sprintf("* %s", err.Error())
|
|
||||||
}
|
|
||||||
return fmt.Sprintf(
|
|
||||||
"%d errors occurred:\n\t%s",
|
|
||||||
len(c.errors), strings.Join(points, "\n\t"))
|
|
||||||
}
|
|
|
@ -1,35 +0,0 @@
|
||||||
// +build kube
|
|
||||||
|
|
||||||
/*
|
|
||||||
Copyright 2020 Docker Compose CLI authors
|
|
||||||
|
|
||||||
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 utils
|
|
||||||
|
|
||||||
const (
|
|
||||||
LabelDockerComposePrefix = "com.docker.compose"
|
|
||||||
LabelService = LabelDockerComposePrefix + ".service"
|
|
||||||
LabelVersion = LabelDockerComposePrefix + ".version"
|
|
||||||
LabelContainerNumber = LabelDockerComposePrefix + ".container-number"
|
|
||||||
LabelOneOff = LabelDockerComposePrefix + ".oneoff"
|
|
||||||
LabelNetwork = LabelDockerComposePrefix + ".network"
|
|
||||||
LabelSlug = LabelDockerComposePrefix + ".slug"
|
|
||||||
LabelVolume = LabelDockerComposePrefix + ".volume"
|
|
||||||
LabelConfigHash = LabelDockerComposePrefix + ".config-hash"
|
|
||||||
LabelProject = LabelDockerComposePrefix + ".project"
|
|
||||||
LabelWorkingDir = LabelDockerComposePrefix + ".working_dir"
|
|
||||||
LabelConfigFiles = LabelDockerComposePrefix + ".config_files"
|
|
||||||
LabelEnvironmentFile = LabelDockerComposePrefix + ".environment_file"
|
|
||||||
)
|
|
|
@ -1,34 +0,0 @@
|
||||||
// +build kube
|
|
||||||
|
|
||||||
/*
|
|
||||||
Copyright 2020 Docker Compose CLI authors
|
|
||||||
|
|
||||||
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 utils
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
func Environment() map[string]string {
|
|
||||||
vars := make(map[string]string)
|
|
||||||
env := os.Environ()
|
|
||||||
for _, v := range env {
|
|
||||||
k := strings.SplitN(v, "=", 2)
|
|
||||||
vars[k[0]] = k[1]
|
|
||||||
}
|
|
||||||
return vars
|
|
||||||
}
|
|
Loading…
Reference in New Issue