1
0
mirror of https://github.com/rancher/os.git synced 2025-06-25 06:21:33 +00:00

Fix ros engine list too

Signed-off-by: Sven Dowideit <SvenDowideit@home.org.au>
This commit is contained in:
Sven Dowideit 2017-07-14 21:15:23 +10:00
parent 6fcc1e3967
commit a04c0f3740
2 changed files with 32 additions and 12 deletions

View File

@ -10,7 +10,6 @@ import (
"time" "time"
"github.com/codegangsta/cli" "github.com/codegangsta/cli"
"github.com/rancher/os/config"
"github.com/rancher/os/log" "github.com/rancher/os/log"
"github.com/rancher/os/util" "github.com/rancher/os/util"
) )
@ -70,9 +69,8 @@ func dockerInitAction(c *cli.Context) error {
fmt.Sprintf(`[ -e %s ] && source %s; exec /usr/bin/dockerlaunch %s %s $DOCKER_OPTS >> %s 2>&1`, dockerConf, dockerConf, dockerBin, strings.Join(c.Args(), " "), dockerLog), fmt.Sprintf(`[ -e %s ] && source %s; exec /usr/bin/dockerlaunch %s %s $DOCKER_OPTS >> %s 2>&1`, dockerConf, dockerConf, dockerBin, strings.Join(c.Args(), " "), dockerLog),
} }
cfg := config.LoadConfig() // TODO: this should be replaced by a "Docker ready event watcher"
if err := ioutil.WriteFile(dockerDone, []byte(CurrentEngine()), 0644); err != nil {
if err := ioutil.WriteFile(dockerDone, []byte(cfg.Rancher.Docker.Engine), 0644); err != nil {
log.Error(err) log.Error(err)
} }

View File

@ -2,17 +2,18 @@ package control
import ( import (
"fmt" "fmt"
"io/ioutil"
"sort" "sort"
"strings" "strings"
"golang.org/x/net/context" "golang.org/x/net/context"
"github.com/codegangsta/cli" "github.com/codegangsta/cli"
"github.com/docker/docker/reference"
"github.com/docker/libcompose/project/options" "github.com/docker/libcompose/project/options"
"github.com/rancher/os/cmd/control/service" "github.com/rancher/os/cmd/control/service"
"github.com/rancher/os/compose" "github.com/rancher/os/compose"
"github.com/rancher/os/config" "github.com/rancher/os/config"
"github.com/rancher/os/docker"
"github.com/rancher/os/log" "github.com/rancher/os/log"
"github.com/rancher/os/util" "github.com/rancher/os/util"
"github.com/rancher/os/util/network" "github.com/rancher/os/util/network"
@ -104,7 +105,7 @@ func engineEnable(c *cli.Context) error {
func engineList(c *cli.Context) error { func engineList(c *cli.Context) error {
cfg := config.LoadConfig() cfg := config.LoadConfig()
engines := availableEngines(cfg) engines := availableEngines(cfg)
currentEngine := currentEngine() currentEngine := CurrentEngine()
for _, engine := range engines { for _, engine := range engines {
if engine == currentEngine { if engine == currentEngine {
@ -135,12 +136,33 @@ func availableEngines(cfg *config.CloudConfig) []string {
return engines return engines
} }
func currentEngine() (engine string) { // CurrentEngine gets the name of the docker that's running
engineBytes, err := ioutil.ReadFile(dockerDone) func CurrentEngine() (engine string) {
if err == nil { // sudo system-docker inspect --format "{{.Config.Image}}" docker
engine = strings.TrimSpace(string(engineBytes)) client, err := docker.NewSystemClient()
} else { if err != nil {
log.Warnf("Failed to detect current Docker engine: %v", err) log.Warnf("Failed to detect current docker: %v", err)
return
} }
info, err := client.ContainerInspect(context.Background(), "docker")
if err != nil {
log.Warnf("Failed to detect current docker: %v", err)
return
}
// parse image name, then remove os- prefix and the engine suffix
image, err := reference.ParseNamed(info.Config.Image)
if err != nil {
log.Warnf("Failed to detect current docker(%s): %v", info.Config.Image, err)
return
}
if t, ok := image.(reference.NamedTagged); ok {
tag := t.Tag()
if !strings.HasPrefix(tag, "1.") {
// TODO: this assumes we only do Docker ce :/
tag = tag + "-ce"
}
return "docker-" + tag
}
return return
} }