From cead09feb29ed9edc88461f40421bf5d5e344337 Mon Sep 17 00:00:00 2001 From: Snider Date: Thu, 29 Jan 2026 02:02:46 +0000 Subject: [PATCH] feat(devops): add package structure Initial pkg/devops setup with DevOps type and path helpers. Co-Authored-By: Claude Opus 4.5 --- go.work | 1 + go.work.sum | 1 + pkg/devops/devops.go | 89 ++++++++++++++++++++++++++++++++++++++++++++ pkg/devops/go.mod | 7 ++++ pkg/devops/go.sum | 4 ++ 5 files changed, 102 insertions(+) create mode 100644 pkg/devops/devops.go create mode 100644 pkg/devops/go.mod create mode 100644 pkg/devops/go.sum diff --git a/go.work b/go.work index 969e917f..70ea7168 100644 --- a/go.work +++ b/go.work @@ -12,6 +12,7 @@ use ( ./pkg/cache ./pkg/config ./pkg/core + ./pkg/devops ./pkg/display ./pkg/docs ./pkg/git diff --git a/go.work.sum b/go.work.sum index 21c3e31a..7e496e57 100644 --- a/go.work.sum +++ b/go.work.sum @@ -172,6 +172,7 @@ github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= github.com/go-openapi/swag v0.19.15/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ= github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE= +github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ= github.com/go-quicktest/qt v1.101.0 h1:O1K29Txy5P2OK0dGo59b7b0LR6wKfIhttaAhHUyn7eI= github.com/go-quicktest/qt v1.101.0/go.mod h1:14Bz/f7NwaXPtdYEgzsx46kqSxVwTbzVZsDC26tQJow= github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI= diff --git a/pkg/devops/devops.go b/pkg/devops/devops.go new file mode 100644 index 00000000..6c8d826f --- /dev/null +++ b/pkg/devops/devops.go @@ -0,0 +1,89 @@ +// Package devops provides a portable development environment using LinuxKit images. +package devops + +import ( + "context" + "fmt" + "os" + "path/filepath" + "runtime" + + "github.com/host-uk/core/pkg/container" +) + +// DevOps manages the portable development environment. +type DevOps struct { + config *Config + images *ImageManager + container *container.LinuxKitManager +} + +// New creates a new DevOps instance. +func New() (*DevOps, error) { + cfg, err := LoadConfig() + if err != nil { + return nil, fmt.Errorf("devops.New: failed to load config: %w", err) + } + + images, err := NewImageManager(cfg) + if err != nil { + return nil, fmt.Errorf("devops.New: failed to create image manager: %w", err) + } + + mgr, err := container.NewLinuxKitManager() + if err != nil { + return nil, fmt.Errorf("devops.New: failed to create container manager: %w", err) + } + + return &DevOps{ + config: cfg, + images: images, + container: mgr, + }, nil +} + +// ImageName returns the platform-specific image name. +func ImageName() string { + return fmt.Sprintf("core-devops-%s-%s.qcow2", runtime.GOOS, runtime.GOARCH) +} + +// ImagesDir returns the path to the images directory. +func ImagesDir() (string, error) { + if dir := os.Getenv("CORE_IMAGES_DIR"); dir != "" { + return dir, nil + } + home, err := os.UserHomeDir() + if err != nil { + return "", err + } + return filepath.Join(home, ".core", "images"), nil +} + +// ImagePath returns the full path to the platform-specific image. +func ImagePath() (string, error) { + dir, err := ImagesDir() + if err != nil { + return "", err + } + return filepath.Join(dir, ImageName()), nil +} + +// IsInstalled checks if the dev image is installed. +func (d *DevOps) IsInstalled() bool { + path, err := ImagePath() + if err != nil { + return false + } + _, err = os.Stat(path) + return err == nil +} + +// Install downloads and installs the dev image. +func (d *DevOps) Install(ctx context.Context, progress func(downloaded, total int64)) error { + return d.images.Install(ctx, progress) +} + +// CheckUpdate checks if an update is available. +func (d *DevOps) CheckUpdate(ctx context.Context) (current, latest string, hasUpdate bool, err error) { + return d.images.CheckUpdate(ctx) +} diff --git a/pkg/devops/go.mod b/pkg/devops/go.mod new file mode 100644 index 00000000..62022ff5 --- /dev/null +++ b/pkg/devops/go.mod @@ -0,0 +1,7 @@ +module github.com/host-uk/core/pkg/devops + +go 1.25 + +require github.com/host-uk/core v0.0.0 + +replace github.com/host-uk/core => ../.. diff --git a/pkg/devops/go.sum b/pkg/devops/go.sum new file mode 100644 index 00000000..b4dfe5ea --- /dev/null +++ b/pkg/devops/go.sum @@ -0,0 +1,4 @@ +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=