Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ else
endif
GOOS ?= ${uname_s}
BUILDER_IMAGE = launchpad-builder
GO = docker run --rm -v "$(CURDIR)":/go/src/github.com/Mirantis/mcc \
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this rewires the GO flag so that you can use a local GOLANG and avoid some of the poor impacts of building in a docker image locally.

GO ?= docker run --rm -v "$(CURDIR)":/go/src/github.com/Mirantis/mcc \
-w "/go/src/github.com/Mirantis/mcc" \
-e GOPATH\
-e GOOS \
-e GOARCH \
-e GOEXE \
$(BUILDER_IMAGE)
$(BUILDER_IMAGE) go
gosrc = $(wildcard *.go */*.go */*/*.go */*/*/*.go)

VOLUME_MOUNTS=-v "$(CURDIR):/v"
Expand All @@ -42,16 +42,16 @@ unit-test: builder

$(TARGET): $(gosrc)
docker build -t $(BUILDER_IMAGE) -f Dockerfile.builder .
GOOS=${GOOS} $(GO) go build $(BUILD_FLAGS) -o $(TARGET) main.go
GOOS=${GOOS} $(GO) build $(BUILD_FLAGS) -o $(TARGET) main.go

build: $(TARGET)

build-all: builder
GOOS=linux GOARCH=amd64 $(GO) go build $(BUILD_FLAGS) -o bin/launchpad-linux-x64 main.go
GOOS=linux GOARCH=arm64 $(GO) go build $(BUILD_FLAGS) -o bin/launchpad-linux-arm64 main.go
GOOS=windows GOARCH=amd64 $(GO) go build $(BUILD_FLAGS) -o bin/launchpad-win-x64.exe main.go
GOOS=darwin GOARCH=amd64 $(GO) go build $(BUILD_FLAGS) -o bin/launchpad-darwin-x64 main.go
GOOS=darwin GOARCH=arm64 $(GO) go build $(BUILD_FLAGS) -o bin/launchpad-darwin-arm64 main.go
build-all:
GOOS=linux GOARCH=amd64 $(GO) build $(BUILD_FLAGS) -o bin/launchpad-linux-x64 main.go
GOOS=linux GOARCH=arm64 $(GO) build $(BUILD_FLAGS) -o bin/launchpad-linux-arm64 main.go
GOOS=windows GOARCH=amd64 $(GO) build $(BUILD_FLAGS) -o bin/launchpad-win-x64.exe main.go
GOOS=darwin GOARCH=amd64 $(GO) build $(BUILD_FLAGS) -o bin/launchpad-darwin-x64 main.go
GOOS=darwin GOARCH=arm64 $(GO) build $(BUILD_FLAGS) -o bin/launchpad-darwin-arm64 main.go

release: build-all sign-win
./release.sh
Expand Down
5 changes: 5 additions & 0 deletions pkg/configurer/enterpriselinux/el.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,17 @@ func (c Configurer) UninstallMCR(h os.Host, scriptPath string, engineConfig comm
if err != nil {
return err
}

if err := c.StopService(h, "docker"); err != nil {
return err
}

if err := c.StopService(h, "containerd"); err != nil {
return err
}

defer c.RemoveDockerFolders(h)

return h.Exec("sudo yum remove -y docker-ee docker-ee-cli")
}

Expand Down
46 changes: 43 additions & 3 deletions pkg/configurer/linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@ import (
"strconv"
"strings"

"github.com/Mirantis/mcc/pkg/util"
escape "github.com/alessio/shellescape"
log "github.com/sirupsen/logrus"

"github.com/k0sproject/rig/exec"
"github.com/k0sproject/rig/os"

"github.com/Mirantis/mcc/pkg/docker"
common "github.com/Mirantis/mcc/pkg/product/common/api"
log "github.com/sirupsen/logrus"
"github.com/Mirantis/mcc/pkg/util"
)

escape "github.com/alessio/shellescape"
const (
LINUX_DOCKER_PATH_LIB_DEFAULT = "/var/lib/docker"
LINUX_DOCKER_PATH_RUN_DEFAULT = "/var/run/docker"
)

// LinuxConfigurer is a generic linux host configurer.
Expand Down Expand Up @@ -57,6 +63,40 @@ func (c LinuxConfigurer) InstallMCR(h os.Host, scriptPath string, engineConfig c
return c.riglinux.StartService(h, "docker")
}

// RemoveDockerFolders Remove the docker run and lib folders IF THEY CAN BE FOUND
// - if docker is still running, then `docker info` is checked for run/lib paths
// - default docker run/lib paths are checked
func (c LinuxConfigurer) RemoveDockerFolders(h os.Host) error {
rmps := []string{}

if di, err := docker.Info(h); err != nil {
log.Warnf("%h: RM Docker paths: could not discover docker paths from info, docker daemon is likely not running. Falling back to default path [%s]: %s", h, LINUX_DOCKER_PATH_LIB_DEFAULT, err.Error())
rmps = append(rmps, LINUX_DOCKER_PATH_LIB_DEFAULT)
} else if di.DockerRootDir != "" {
log.Warnf("%s: RM Docker Paths: no lib path in docker info, falling back to default path [%s]", h, LINUX_DOCKER_PATH_LIB_DEFAULT)
rmps = append(rmps, LINUX_DOCKER_PATH_LIB_DEFAULT)
} else {
rmps = append(rmps, di.DockerRootDir)
}

// command to a delete a path
rmc := "rm -rf %s"
// Can we sudo the rm command
if sc, err := h.Sudo(rmc); err == nil {
rmc = sc
}

for _, p := range rmps {
if err := h.Execf(rmc, p); err != nil {
log.Warnf("%s: RM Docker Paths: Failed to delete path [%s]: %s", h, p, err.Error())
} else {
log.Infof("%s: RM Docker Paths: deleted path [%s]", h, p)
}
}

return nil
}

// RestartMCR restarts Docker EE engine.
func (c LinuxConfigurer) RestartMCR(h os.Host) error {
return c.riglinux.RestartService(h, "docker")
Expand Down
2 changes: 2 additions & 0 deletions pkg/configurer/sles/sles.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ func (c Configurer) UninstallMCR(h os.Host, scriptPath string, engineConfig comm
return err
}

defer c.RemoveDockerFolders(h)

return h.Exec("sudo zypper -n remove -y --clean-deps docker-ee docker-ee-cli")
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/configurer/ubuntu/ubuntu.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,8 @@ func (c Configurer) UninstallMCR(h os.Host, scriptPath string, engineConfig comm
if err := c.StopService(h, "containerd"); err != nil {
return err
}

defer c.RemoveDockerFolders(h)

return h.Exec("sudo apt-get remove -y docker-ee docker-ee-cli && sudo apt autoremove -y")
}
31 changes: 31 additions & 0 deletions pkg/docker/info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package docker

import (
"encoding/json"
"fmt"

log "github.com/sirupsen/logrus"

"github.com/k0sproject/rig/os"
)

// DockerInfo structural data for information on a hosts docker implementation
type DockerInfo struct {
DockerRootDir string `json:"DockerRootDir"`
}

// Info retrieve docker info data for a host
//
// @NOTE this function uses rig.os.Host instead of product.mke.api.Host
func Info(h os.Host) (DockerInfo, error) {
di := DockerInfo{}

log.Infof("%s: Retrieving docker info", h)

if output, err := h.ExecOutput("docker info --format=json"); err != nil {
return di, fmt.Errorf("%s: failed to retrieve docker info: %s", h, err.Error())
} else if err := json.Unmarshal([]byte(output), &di); err != nil {
return di, fmt.Errorf("%s: failed to unmarshall docker info: %s", h, err.Error())
}
return di, nil
}