mirror of
https://github.com/docker/compose.git
synced 2025-07-31 01:24:15 +02:00
implements helm install cmd
Signed-off-by: aiordache <anca.iordache@docker.com>
This commit is contained in:
parent
ce3e4d7717
commit
898b7d4666
@ -1,32 +1,20 @@
|
|||||||
package compose
|
package compose
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
|
|
||||||
|
chartloader "helm.sh/helm/v3/pkg/chart/loader"
|
||||||
|
|
||||||
"github.com/compose-spec/compose-go/loader"
|
"github.com/compose-spec/compose-go/loader"
|
||||||
"github.com/compose-spec/compose-go/types"
|
"github.com/compose-spec/compose-go/types"
|
||||||
"github.com/docker/cli/cli/command"
|
|
||||||
"github.com/docker/cli/cli/config/configfile"
|
|
||||||
registry "github.com/docker/cli/cli/registry/client"
|
|
||||||
"github.com/docker/cli/cli/streams"
|
|
||||||
"github.com/docker/docker/client"
|
|
||||||
"github.com/docker/helm-prototype/pkg/compose/internal/convert"
|
"github.com/docker/helm-prototype/pkg/compose/internal/convert"
|
||||||
"github.com/docker/helm-prototype/pkg/compose/internal/helm"
|
"github.com/docker/helm-prototype/pkg/compose/internal/helm"
|
||||||
utils "github.com/docker/helm-prototype/pkg/compose/internal/utils"
|
utils "github.com/docker/helm-prototype/pkg/compose/internal/utils"
|
||||||
|
"helm.sh/helm/v3/pkg/action"
|
||||||
|
env "helm.sh/helm/v3/pkg/cli"
|
||||||
|
k "helm.sh/helm/v3/pkg/kube"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
Client client.APIClient
|
|
||||||
RegistryClient registry.RegistryClient
|
|
||||||
ConfigFile *configfile.ConfigFile
|
|
||||||
Stdout *streams.Out
|
|
||||||
)
|
|
||||||
|
|
||||||
func WithDockerCli(cli command.Cli) {
|
|
||||||
Client = cli.Client()
|
|
||||||
RegistryClient = cli.RegistryClient(false)
|
|
||||||
ConfigFile = cli.ConfigFile()
|
|
||||||
Stdout = cli.Out()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Orchestrator is "kubernetes" or "swarm"
|
// Orchestrator is "kubernetes" or "swarm"
|
||||||
type Orchestrator string
|
type Orchestrator string
|
||||||
|
|
||||||
@ -65,6 +53,10 @@ func NewProject(config types.ConfigDetails, name string) (*Project, error) {
|
|||||||
|
|
||||||
// projectFromOptions load a compose project based on command line options
|
// projectFromOptions load a compose project based on command line options
|
||||||
func ProjectFromOptions(options *ProjectOptions) (*Project, error) {
|
func ProjectFromOptions(options *ProjectOptions) (*Project, error) {
|
||||||
|
if options.Name == "" {
|
||||||
|
options.Name = "docker-compose"
|
||||||
|
}
|
||||||
|
|
||||||
workingDir, configs, err := utils.GetConfigs(
|
workingDir, configs, err := utils.GetConfigs(
|
||||||
options.Name,
|
options.Name,
|
||||||
options.ConfigPaths,
|
options.ConfigPaths,
|
||||||
@ -80,7 +72,7 @@ func ProjectFromOptions(options *ProjectOptions) (*Project, error) {
|
|||||||
}, options.Name)
|
}, options.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Project) GenerateCharts(path string) error {
|
func (p *Project) GenerateChart(path string) error {
|
||||||
objects, err := convert.MapToKubernetesObjects(p.Config, p.Name)
|
objects, err := convert.MapToKubernetesObjects(p.Config, p.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -91,6 +83,54 @@ func (p *Project) GenerateCharts(path string) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
func (p *Project) InstallCommand(options *ProjectOptions) error {
|
|
||||||
return nil
|
func (p *Project) InstallChart(n, path string) error {
|
||||||
|
|
||||||
|
if path == "" {
|
||||||
|
err := p.GenerateChart(path)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
settings := env.New()
|
||||||
|
actionConfig := new(action.Configuration)
|
||||||
|
println(".......... here ............")
|
||||||
|
if err := actionConfig.Init(settings.RESTClientGetter(), settings.Namespace(), "memory", nil); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
println(settings.EnvVars())
|
||||||
|
client := action.NewInstall(actionConfig)
|
||||||
|
println("Original chart version:", client.Version)
|
||||||
|
client.Version = ">0.0.0-0"
|
||||||
|
|
||||||
|
name, chart, err := client.NameAndChart([]string{n, path})
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
client.ReleaseName = name
|
||||||
|
client.Namespace = settings.Namespace()
|
||||||
|
cp, err := client.ChartPathOptions.LocateChart(chart, settings)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
println("CHART PATH: ", cp)
|
||||||
|
|
||||||
|
chartRequested, err := chartloader.Load(cp)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
kclient := k.New(settings.RESTClientGetter())
|
||||||
|
println(kclient.Namespace)
|
||||||
|
if err = actionConfig.KubeClient.IsReachable(); err != nil {
|
||||||
|
println("Kube API is not reachable")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
println("....Running.....")
|
||||||
|
println("Chart description: ", chartRequested.Metadata.Description)
|
||||||
|
release, err := client.Run(chartRequested, map[string]interface{}{})
|
||||||
|
|
||||||
|
println(release.Name)
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
@ -1,34 +0,0 @@
|
|||||||
package helm
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"sync"
|
|
||||||
|
|
||||||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
|
||||||
)
|
|
||||||
|
|
||||||
type KubeConfig struct {
|
|
||||||
namespace string
|
|
||||||
config genericclioptions.RESTClientGetter
|
|
||||||
configOnce sync.Once
|
|
||||||
|
|
||||||
// KubeConfig is the path to the kubeconfig file
|
|
||||||
KubeConfig string
|
|
||||||
// KubeContext is the name of the kubeconfig context.
|
|
||||||
KubeContext string
|
|
||||||
// Bearer KubeToken used for authentication
|
|
||||||
KubeToken string
|
|
||||||
// Kubernetes API Server Endpoint for authentication
|
|
||||||
KubeAPIServer string
|
|
||||||
}
|
|
||||||
|
|
||||||
func New() *KubeConfig {
|
|
||||||
|
|
||||||
env := KubeConfig{
|
|
||||||
namespace: "",
|
|
||||||
KubeContext: os.Getenv("COMPOSE_KUBECONTEXT"),
|
|
||||||
KubeToken: os.Getenv("COMPOSE_KUBETOKEN"),
|
|
||||||
KubeAPIServer: os.Getenv("COMPOSE_KUBEAPISERVER"),
|
|
||||||
}
|
|
||||||
return &env
|
|
||||||
}
|
|
@ -37,7 +37,7 @@ home:
|
|||||||
Name string
|
Name string
|
||||||
}
|
}
|
||||||
var chartData bytes.Buffer
|
var chartData bytes.Buffer
|
||||||
_ = t.Execute(&chartData, ChartDetails{project})
|
_ = t.Execute(&chartData, ChartDetails{Name: project})
|
||||||
|
|
||||||
if err := out.Write("Chart.yaml", chartData.Bytes()); err != nil {
|
if err := out.Write("Chart.yaml", chartData.Bytes()); err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user