8000 core: multiple updates by abiosoft · Pull Request #1073 · abiosoft/colima · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

core: multiple updates #1073

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Jul 23, 2024
Merged
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
45 changes: 45 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,48 @@ jobs:

- name: Teardown
run: colima delete -f

incus:
runs-on: macos-13
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.21"

- name: Install CLI deps
env:
HOMEBREW_NO_AUTO_UPDATE: "1"
HOMEBREW_NO_INSTALLED_DEPENDENTS_CHECK: "1"
run: |
brew install --overwrite python@3.12 kubectl docker coreutils lima incus

- name: Build and Install
run: make && sudo make install

- name: tmate debugging session
uses: mxschmitt/action-tmate@v3
with:
limit-access-to-actor: true
github-token: ${{ secrets.GITHUB_TOKEN }}
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled }}

- name: Start Colima
run: colima start --runtime incus

- name: Delay
run: sleep 10

- name: Validate Incus
run: incus version && incus list

- name: Validate DNS
run: colima ssh -- sh -c "sudo apt-get update -y -qq && sudo apt-get install -qq dnsutils && nslookup host.docker.internal"

- name: Stop
run: colima stop

- name: Teardown
run: colima delete -f
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,7 @@ nix-derivation-shell:
.PHONY: integration
integration: build
GOARCH=$(GOARCH) COLIMA_BINARY=$(OUTPUT_DIR)/$(OUTPUT_BIN) scripts/integration.sh

.PHONY: images-sha
images-sha:
bash embedded/images/images_sha.sh
49 changes: 40 additions & 9 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/abiosoft/colima/config"
"github.com/abiosoft/colima/config/configmanager"
"github.com/abiosoft/colima/environment"
"github.com/abiosoft/colima/environment/container/containerd"
"github.com/abiosoft/colima/environment/container/docker"
"github.com/abiosoft/colima/environment/container/kubernetes"
"github.com/abiosoft/colima/environment/host"
Expand Down Expand Up @@ -53,35 +54,61 @@ type colimaApp struct {
guest environment.VM
}

func (c colimaApp) Start(conf config.Config) error {
ctx := context.WithValue(context.Background(), config.CtxKey(), conf)
func (c colimaApp) startWithRuntime(conf config.Config) ([]environment.Container, error) {
kubernetesEnabled := conf.Kubernetes.Enabled

// Kubernetes can only be enabled for docker and containerd
switch conf.Runtime {
case docker.Name, containerd.Name:
default:
kubernetesEnabled = false
}

var containers []environment.Container

{
runtime := conf.Runtime
if conf.Kubernetes.Enabled {
if kubernetesEnabled {
runtime += "+k3s"
}
log.Println("starting", config.CurrentProfile().DisplayName)
log.Println("runtime:", runtime)
}
var containers []environment.Container

// runtime
{
env, err := c.containerEnvironment(conf.Runtime)
if err != nil {
return err
return nil, err
}
containers = append(containers, env)
}

// kubernetes should come after required runtime
if conf.Kubernetes.Enabled {
if kubernetesEnabled {
env, err := c.containerEnvironment(kubernetes.Name)
if err != nil {
return err
return nil, err
}
containers = append(containers, env)
}

return containers, nil
}

func (c colimaApp) Start(conf config.Config) error {
ctx := context.WithValue(context.Background(), config.CtxKey(), conf)

log.Println("starting", config.CurrentProfile().DisplayName)

var containers []environment.Container
if !environment.IsNoneRuntime(conf.Runtime) {
cs, err := c.startWithRuntime(conf)
if err != nil {
return err
}
containers = cs
}

// the order for start is:
// vm start -> container runtime provision -> container runtime start

Expand Down Expand Up @@ -377,13 +404,17 @@ func (c colimaApp) setKubernetes(conf config.Kubernetes) error {

func (c colimaApp) currentContainerEnvironments(ctx context.Context) ([]environment.Container, error) {
var containers []environment.Container

// runtime
{
runtime, err := c.currentRuntime(ctx)
if err != nil {
return nil, err
}

if environment.IsNoneRuntime(runtime) {
return nil, nil
}

env, err := c.containerEnvironment(runtime)
if err != nil {
return nil, err
Expand Down
10 changes: 5 additions & 5 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ func (c Config) AutoActivate() bool {
// Empty checks if the configuration is empty.
func (c Config) Empty() bool { return c.Runtime == "" } // this may be better but not really needed.

// CtxKey returns the context key for config.
func CtxKey() any {
return struct{ name string }{name: "colima_config"}
}

func (c Config) DriverLabel() string {
if util.MacOS13OrNewer() && c.VMType == "vz" {
return "macOS Virtualization.Framework"
}
return "QEMU"
}

// CtxKey returns the context key for config.
func CtxKey() any {
return struct{ name string }{name: "colima_config"}
}
File renamed without changes.
5 changes: 5 additions & 0 deletions config/files.go
F438
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ var (

limaDir = requiredDir{
dir: func() (string, error) {
// if LIMA_HOME env var is set, obey it.
if dir := os.Getenv("LIMA_HOME"); dir != "" {
return dir, nil
}

dir, err := configBaseDir.dir()
if err != nil {
return "", err
Expand Down
8 changes: 8 additions & 0 deletions config/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ func (p *Profile) File() string {
return filepath.Join(p.ConfigDir(), configFileName)
}

// LimaFile implements ProfileInfo.
func (p *Profile) LimaFile() string {
return filepath.Join(p.LimaInstanceDir(), "lima.yaml")
}

// StateFile implements ProfileInfo.
func (p *Profile) StateFile() string {
return filepath.Join(p.LimaInstanceDir(), configFileName)
Expand All @@ -89,6 +94,9 @@ type ProfileInfo interface {
// File returns the path to the config file.
File() string

// LimaFile returns the path to the lima config file.
LimaFile() string

// File returns the path to the state file.
StateFile() string
}
38 changes: 4 additions & 34 deletions core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/sirupsen/logrus"
"strings"

"github.com/sirupsen/logrus"

"github.com/abiosoft/colima/cli"
"github.com/abiosoft/colima/environment"
"github.com/abiosoft/colima/util/downloader"
Expand Down Expand Up @@ -53,11 +54,10 @@ func SetupBinfmt(host hostActions, guest guestActions, arch environment.Arch) er
// download
url := baseURL + "binfmt-" + arch.Value().GoArch() + ".tar.gz"
dest := "/tmp/binfmt.tar.gz"
if err := downloader.Download(host, guest, downloader.Request{
if err := downloader.DownloadToGuest(host, guest, downloader.Request{
URL: url,
SHA: downloadSha(url),
Filename: dest,
}); err != nil {
}, dest); err != nil {
return fmt.Errorf("error downloading binfmt: %w", err)
}

Expand All @@ -74,36 +74,6 @@ func SetupBinfmt(host hostActions, guest guestActions, arch environment.Arch) er
return install()
}

// SetupContainerdUtils downloads and install containerd utils.
func SetupContainerdUtils(host hostActions, guest guestActions, arch environment.Arch) error {
// ignore if already installed
if err := guest.RunQuiet("sh", "-c", "command -v nerdctl && stat /opt/cni/bin/flannel"); err == nil {
return nil
}

// download
url := baseURL + "containerd-utils-" + arch.Value().GoArch() + ".tar.gz"
dest := "/tmp/containerd-utils.tar.gz"
if err := downloader.Download(host, guest, downloader.Request{
URL: url,
SHA: downloadSha(url),
Filename: dest,
}); err != nil {
return fmt.Errorf("error downloading containerd-utils: %w", err)
}

// extract
if err := guest.Run("sh", "-c",
strings.NewReplacer(
"{archive}", dest,
).Replace(`cd /tmp && sudo tar Cxfz /usr/local {archive} && sudo mkdir -p /opt/cni && sudo mv /usr/local/libexec/cni /opt/cni/bin`),
); err != nil {
return fmt.Errorf("error extracting containerd utils: %w", err)
}

return nil
}

// LimaVersionSupported checks if the currently installed Lima version is supported.
func LimaVersionSupported() error {
var values struct {
Expand Down
2 changes: 1 addition & 1 deletion embedded/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"embed"
)

//go:embed network k3s defaults
//go:embed network k3s defaults images
var fs embed.FS

// FS returns the underlying embed.FS
Expand Down
8 changes: 8 additions & 0 deletions embedded/images/images.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
arm64 none https://github.com/abiosoft/colima-core/releases/download/v0.7.0-1/ubuntu-24.04-minimal-cloudimg-arm64-none.qcow2 e3f657f15e4a3bb1a0474326cb5be06313ec948fe47a8d54b0b698ff6920074fa73ebbcfae08b187bd4af32d1c4ba6d27333c0147eca4b582959c761ad8b29e3 ubuntu-24.04-minimal-cloudimg-arm64-none.qcow2
arm64 docker https://github.com/abiosoft/colima-core/releases/download/v0.7.0-1/ubuntu-24.04-minimal-cloudimg-arm64-docker.qcow2 b22832ee330ebd31efe3373900be95fdef53c0d6e465490299a34e34b5795c86d1a786115c15a3402228e8cc69187b6738b0b03673d6b8761825d48ea9a4e5c7 ubuntu-24.04-minimal-cloudimg-arm64-docker.qcow2
arm64 containerd https://github.com/abiosoft/colima-core/releases/download/v0.7.0-1/ubuntu-24.04-minimal-cloudimg-arm64-containerd.qcow2 9ebc37f114485a78747fd475ccd40207df848d4b256ece3b1718893eb6e7939d1d7df83de7aaeda80e401cf0d3da8dbb0cd1962ba76fa6f63fa861afeab07cc7 ubuntu-24.04-minimal-cloudimg-arm64-containerd.qcow2
arm64 incus https://github.com/abiosoft/colima-core/releases/download/v0.7.0-1/ubuntu-24.04-minimal-cloudimg-arm64-incus.qcow2 439237d1c1bc7c02a6758b7c2d49b1cda82d31fba75287ce9b9816ad1b90bd020b7a8e7fce28e9be66a7230fdc5d735aa057678e7d0b7af32a39c98458a48727 ubuntu-24.04-minimal-cloudimg-arm64-incus.qcow2
amd64 none https://github.com/abiosoft/colima-core/releases/download/v0.7.0-1/ubuntu-24.04-minimal-cloudimg-amd64-none.qcow2 30abe69df10bb5248efc80687af99629713f36d06f5cc1d5d440bf59d16b1652e50d746d0e4152d668ac67a03cb02dfcc0d41e240cfc5e7fb1e88917884378af ubuntu-24.04-minimal-cloudimg-amd64-none.qcow2
amd64 docker https://github.com/abiosoft/colima-core/releases/download/v0.7.0-1/ubuntu-24.04-minimal-cloudimg-amd64-docker.qcow2 0d016d931a2c2122dba7732831e5b9f41151a52b25e1d9de62100c34257b258d18b9b828e4f2d55a3bc77e59861574e64338fae90469451eb17f6c5b081ecfec ubuntu-24.04-minimal-cloudimg-amd64-docker.qcow2
amd64 containerd https://github.com/abiosoft/colima-core/releases/download/v0.7.0-1/ubuntu-24.04-minimal-cloudimg-amd64-containerd.qcow2 347b539a50a4cd6a0e7de13131321c3541446f44f63796be8caf7f02fe0a2b876999ce27b0ad7a93882f7b449b8fd2ba656952d0f6f42e8d2b624f528195af1f ubuntu-24.04-minimal-cloudimg-amd64-containerd.qcow2
amd64 incus https://github.com/abiosoft/colima-core/releases/download/v0.7.0-1/ubuntu-24.04-minimal-cloudimg-amd64-incus.qcow2 3fbd1d3d9bc74b1b1430738e3c042d1b9bb65bbeacaede500126a9435e27448d39ab4ee38a34394004f662de1ff4259cd2dbf543069cf90df88d8b2522613f89 ubuntu-24.04-minimal-cloudimg-amd64-incus.qcow2
23 changes: 23 additions & 0 deletions embedded/images/images_sha.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

set -eux

BASE_URL=https://github.com/abiosoft/colima-core/releases/download
BASE_FILENAME=ubuntu-24.04-minimal-cloudimg
VERSION=v0.7.0-1
RUNTIMES="none docker containerd incus"
ARCHS="arm64 amd64"

DIR="$(dirname $0)"
FILE="${DIR}/images.txt"

# reset output files
echo -n >$FILE

for arch in ${ARCHS}; do
for runtime in ${RUNTIMES}; do
URL="${BASE_URL}/${VERSION}/${BASE_FILENAME}-${arch}-${runtime}.qcow2"
SHA="$(curl -sL ${URL}.sha512sum)"
echo "$arch $runtime ${URL} ${SHA}" >>$FILE
done
done
3 changes: 3 additions & 0 deletions environment/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import (
"log"
)

// IsNoneRuntime returns if runtime is none.
func IsNoneRuntime(runtime string) bool { return runtime == "none" }

// Container is container environment.
type Container interface {
// Name is the name of the container runtime. e.g. docker, containerd
Expand Down
5 changes: 0 additions & 5 deletions environment/container/containerd/containerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ func (c containerdRuntime) Name() string {
}

func (c containerdRuntime) Provision(context.Context) error {
if err := c.guest.RunQuiet("sh", "-c",
`sudo sed -i '/disabled_plugins =/c\disabled_plugins = []' /etc/containerd/config.toml`,
); err != nil {
return err
}
return c.guest.Write(buildKitConfFile, buildKitConf)
}

Expand Down
31 changes: 31 additions & 0 deletions environment/container/incus/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
config:
core.https_address: '[::]:8443'
networks:
- config:
ipv4.address: auto
ipv6.address: auto
description: ""
name: {{.Interface}}
type: ""
project: default
storage_pools:
- config:
size: {{.Disk}}GiB
description: ""
name: default
driver: zfs
profiles:
- config: {}
description: ""
devices:
eth0:
name: eth0
network: {{.Interface}}
type: nic
root:
path: /
pool: default
type: disk
name: default
projects: []
cluster: null
Loading
Loading
0