feat(devops): add package structure
Initial pkg/devops setup with DevOps type and path helpers. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
a30e101281
commit
cead09feb2
5 changed files with 102 additions and 0 deletions
1
go.work
1
go.work
|
|
@ -12,6 +12,7 @@ use (
|
|||
./pkg/cache
|
||||
./pkg/config
|
||||
./pkg/core
|
||||
./pkg/devops
|
||||
./pkg/display
|
||||
./pkg/docs
|
||||
./pkg/git
|
||||
|
|
|
|||
|
|
@ -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=
|
||||
|
|
|
|||
89
pkg/devops/devops.go
Normal file
89
pkg/devops/devops.go
Normal file
|
|
@ -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)
|
||||
}
|
||||
7
pkg/devops/go.mod
Normal file
7
pkg/devops/go.mod
Normal file
|
|
@ -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 => ../..
|
||||
4
pkg/devops/go.sum
Normal file
4
pkg/devops/go.sum
Normal file
|
|
@ -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=
|
||||
Loading…
Add table
Reference in a new issue