-
-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docker: use docker-ce packages (#884)
- Loading branch information
Showing
6 changed files
with
224 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package deb | ||
|
||
import ( | ||
"github.com/abiosoft/colima/environment" | ||
) | ||
|
||
type ( | ||
hostActions = environment.HostActions | ||
guestActions = environment.GuestActions | ||
) | ||
|
||
// URISource is the source for fetching URI for deb packages. | ||
type URISource interface { | ||
// Name is the name for the URISource. | ||
Name() string | ||
// Packages is the list of package names. | ||
Packages() []string | ||
// URIs return the list of URIs to download the deb files. | ||
URIs(arch environment.Arch) ([]string, error) | ||
// PreInstall is done before the deb package are installed. | ||
PreInstall() error | ||
// Install installs the packages directly using the internet. | ||
Install() error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package deb | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/abiosoft/colima/environment" | ||
) | ||
|
||
var dockerPackages = []string{ | ||
"docker-ce", | ||
"docker-ce-cli", | ||
"containerd.io", | ||
"docker-buildx-plugin", | ||
"docker-compose-plugin", | ||
} | ||
|
||
var _ URISource = (*Docker)(nil) | ||
|
||
// Docker is the URISource for Docker CE packages. | ||
type Docker struct { | ||
Host hostActions | ||
Guest guestActions | ||
} | ||
|
||
// PreInstall implements URISource. | ||
func (d *Docker) PreInstall() error { | ||
return d.Guest.RunQuiet("sh", "-c", "sudo apt remove -y docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc") | ||
} | ||
|
||
// Install implements URISource. | ||
func (d *Docker) Install() error { | ||
return d.Guest.Run("sh", "-c", | ||
`curl -fsSL https://get.docker.com -o /tmp/get-docker.sh && sudo sh /tmp/get-docker.sh`, | ||
) | ||
} | ||
|
||
// Name implements URISource. | ||
func (*Docker) Name() string { | ||
return "docker-ce" | ||
} | ||
|
||
// Packages implements URISource. | ||
func (*Docker) Packages() []string { | ||
return dockerPackages | ||
} | ||
|
||
// URIs implements URISource. | ||
func (d *Docker) URIs(arch environment.Arch) ([]string, error) { | ||
var uris []string | ||
|
||
pkgFiles, err := d.pkgFiles(arch) | ||
if err != nil { | ||
return nil, fmt.Errorf("error getting package names and version: %w", err) | ||
} | ||
|
||
for _, file := range pkgFiles { | ||
uri := d.debPackageBaseURI(arch) + file | ||
uris = append(uris, uri) | ||
} | ||
|
||
return uris, nil | ||
} | ||
|
||
func (d Docker) pkgFiles(arch environment.Arch) ([]string, error) { | ||
script := fmt.Sprintf(`curl -sL https://download.docker.com/linux/ubuntu/dists/mantic/stable/binary-%s/Packages | grep '^Filename: ' | awk -F'/' '{print $NF}'`, arch.Value().GoArch()) | ||
filenames, err := d.Host.RunOutput("sh", "-c", script) | ||
if err != nil { | ||
return nil, fmt.Errorf("error retrieving deb package filenames: %w", err) | ||
} | ||
|
||
return strings.Fields(filenames), nil | ||
} | ||
|
||
func (d Docker) debPackageBaseURI(arch environment.Arch) string { | ||
return fmt.Sprintf("https://download.docker.com/linux/ubuntu/dists/mantic/pool/stable/%s/", arch.GoArch()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package deb | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/abiosoft/colima/environment" | ||
) | ||
|
||
var manticPackages = []string{ | ||
// docker | ||
"iptables", | ||
// k8s | ||
"socat", | ||
// utilities | ||
"htop", "vim", "inetutils-ping", "dnsutils", | ||
} | ||
|
||
var _ URISource = (*Mantic)(nil) | ||
|
||
// Mantic is the URISource for Ubuntu Mantic packages. | ||
type Mantic struct { | ||
Guest guestActions | ||
} | ||
|
||
// PreInstall implements URISource. | ||
func (*Mantic) PreInstall() error { | ||
return nil | ||
} | ||
|
||
// Packages implements URISource. | ||
func (*Mantic) Packages() []string { | ||
return manticPackages | ||
} | ||
|
||
// Name implements URISource. | ||
func (*Mantic) Name() string { | ||
return "mantic-debs" | ||
} | ||
|
||
// URIs implements URISource. | ||
func (m *Mantic) URIs(_ environment.Arch) ([]string, error) { | ||
_ = m.Guest.RunQuiet("sudo apt update -y") | ||
|
||
output := "" | ||
for _, p := range manticPackages { | ||
line := fmt.Sprintf(`sudo apt-get install --reinstall --print-uris -qq "%s" | cut -d"'" -f2`, p) | ||
out, err := m.Guest.RunOutput("sh", "-c", line) | ||
if err != nil { | ||
return nil, fmt.Errorf("error fetching dependencies list: %w", err) | ||
} | ||
output += out + " " | ||
} | ||
|
||
return strings.Fields(output), nil | ||
} | ||
|
||
// Install implements URISource. | ||
func (m *Mantic) Install() error { | ||
return m.Guest.Run("sh", "-c", "sudo apt update && sudo apt install -f -y "+strings.Join(manticPackages, " ")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters