Skip to content
This repository has been archived by the owner on Oct 11, 2023. It is now read-only.

Commit

Permalink
v2.0.2
Browse files Browse the repository at this point in the history
* Run "ros engine switch latest" before rc.local
* Use Docker CLI plugins from user-docker image
  • Loading branch information
olljanat committed Jan 14, 2025
1 parent ed36859 commit a9e651a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 47 deletions.
57 changes: 15 additions & 42 deletions cmd/control/console_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,13 @@ $(tput sgr0)
}
}

// create Docker CLI plugins folder
if _, err := os.Stat("/usr/libexec/docker/cli-plugins"); os.IsNotExist(err) {
if err = os.MkdirAll("/usr/libexec/docker/cli-plugins", 0755); err != nil {
log.Error(err)
}
}

baseSymlink := symLinkEngineBinary()

if _, err := os.Stat(dockerCompletionFile); err == nil {
Expand All @@ -211,40 +218,6 @@ $(tput sgr0)
})
}

// create placeholder for docker binary with "docker compose" support
const DockerPlaceholder = `#!/bin/bash
if [ "$1" == "compose" ]; then
/usr/local/bin/docker-compose "${@:2}"
elif [ "$1" == "build" ]; then
DOCKER_VERSION=$(sudo system-docker inspect --format "{{.Config.Image}}" docker | cut -d ":" -f 2)
docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock -w /build -v $PWD:/build docker:$DOCKER_VERSION-cli docker build "${@:2}"
elif [ "$1" == "builder" ]; then
DOCKER_VERSION=$(sudo system-docker inspect --format "{{.Config.Image}}" docker | cut -d ":" -f 2)
docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock -w /builder -v $PWD:/builder docker:$DOCKER_VERSION-cli docker builder "${@:2}"
elif [ "$1" == "buildx" ]; then
DOCKER_VERSION=$(sudo system-docker inspect --format "{{.Config.Image}}" docker | cut -d ":" -f 2)
docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock -w /buildx -v $PWD:/buildx docker:$DOCKER_VERSION-cli docker buildx "${@:2}"
else
/usr/bin/docker "$@"
fi
`
if _, err := os.Stat("/usr/local/bin/docker"); os.IsNotExist(err) {
if err := ioutil.WriteFile("/usr/local/bin/docker", []byte(DockerPlaceholder), 0755); err != nil {
log.Error(err)
}
}

// create placeholder for docker-compose binary
const ComposePlaceholder = `#!/bin/bash
DOCKER_VERSION=$(sudo system-docker inspect --format "{{.Config.Image}}" docker | cut -d ":" -f 2)
docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock -w /compose -v $PWD:/compose docker:$DOCKER_VERSION-cli docker compose "$@"
`
if _, err := os.Stat("/usr/local/bin/docker-compose"); os.IsNotExist(err) {
if err := ioutil.WriteFile("/usr/local/bin/docker-compose", []byte(ComposePlaceholder), 0755); err != nil {
log.Error(err)
}
}

for _, link := range baseSymlink {
syscall.Unlink(link.newname)
if err := os.Symlink(link.oldname, link.newname); err != nil {
Expand Down Expand Up @@ -317,14 +290,6 @@ docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock -w /compose -v
log.Error(err)
}

if err := util.RunScript("/etc/rc.local"); err != nil {
log.Error(err)
}

if err := util.RunScript("/etc/init.d/apparmor", "start"); err != nil {
log.Error(err)
}

// Check if user Docker has ever run in this installation yet and switch to latest version if not
if _, err := os.Stat("/var/lib/docker/engine-id"); os.IsNotExist(err) {
log.Warn("User Docker does not exist, switching to latest version")
Expand All @@ -336,6 +301,14 @@ docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock -w /compose -v
}
}

if err := util.RunScript("/etc/rc.local"); err != nil {
log.Error(err)
}

if err := util.RunScript("/etc/init.d/apparmor", "start"); err != nil {
log.Error(err)
}

// Enable Bash colors
enableBashRC("/root", 0, 0)
enableBashRC(rancherHome, 1100, 1100)
Expand Down
16 changes: 11 additions & 5 deletions cmd/control/user_docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ import (
)

const (
defaultStorageContext = "console"
dockerPidFile = "/var/run/docker.pid"
sourceDirectory = "/engine"
destDirectory = "/var/lib/rancher/engine"
dockerCompletionFName = "completion"
defaultStorageContext = "console"
dockerPidFile = "/var/run/docker.pid"
sourceDirectory = "/engine"
destDirectory = "/var/lib/rancher/engine"
pluginsSourceDirectory = "/engine-plugins"
pluginsDestDirectory = "/var/lib/rancher/engine-plugins"
dockerCompletionFName = "completion"
)

var (
Expand All @@ -41,6 +43,10 @@ func userDockerAction(c *cli.Context) error {
return err
}

if err := copyBinaries(pluginsSourceDirectory, pluginsDestDirectory); err != nil {
return err
}

if err := syscall.Mount("/host/sys", "/sys", "", syscall.MS_BIND|syscall.MS_REC, ""); err != nil {
return err
}
Expand Down
5 changes: 5 additions & 0 deletions cmd/control/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ func symLinkEngineBinary() []symlink {
{"/var/lib/rancher/engine/docker-containerd-ctr", "/usr/bin/docker-containerd-ctr"},
{"/var/lib/rancher/engine/docker-containerd-shim", "/usr/bin/docker-containerd-shim"},
{"/var/lib/rancher/engine/docker-runc", "/usr/bin/docker-runc"},

// Docker CLI plugins
{"/var/lib/rancher/engine-plugins/docker-compose", "/usr/bin/docker-compose"},
{"/var/lib/rancher/engine-plugins/docker-compose", "/usr/libexec/docker/cli-plugins/docker-compose"},
{"/var/lib/rancher/engine-plugins/docker-buildx", "/usr/libexec/docker/cli-plugins/docker-buildx"},
}
return baseSymlink
}
Expand Down

0 comments on commit a9e651a

Please sign in to comment.