Skip to content

Commit

Permalink
integrate buildah
Browse files Browse the repository at this point in the history
Signed-off-by: david.bao <[email protected]>

Signed-off-by: david.bao <[email protected]>

Signed-off-by: david.bao <[email protected]>

Signed-off-by: david.bao <[email protected]>

Signed-off-by: david.bao <[email protected]>

Signed-off-by: david.bao <[email protected]>
  • Loading branch information
justadogistaken committed Aug 10, 2022
1 parent 25b39ce commit 34a7eee
Show file tree
Hide file tree
Showing 2,614 changed files with 342,449 additions and 18,672 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/e2e-test-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ jobs:
repository: ${{fromJson(steps.request.outputs.data).head.repo.full_name}}
ref: ${{fromJson(steps.request.outputs.data).head.ref}}
path: src/github.com/sealerio/sealer

- name: Install deps
run: |
sudo apt-get install -y libgpgme-dev libbtrfs-dev libdevmapper-dev
- name: Set up Go 1.16
uses: actions/setup-go@v1
with:
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ on:
branches: "*"
paths-ignore:
- 'docs/**'
- 'vendor/**'
- '*.md'
- '*.yml'
jobs:
Expand All @@ -17,7 +16,9 @@ jobs:
runs-on: ubuntu-latest

steps:

- name: Install deps
run: |
sudo apt-get install -y libgpgme-dev libbtrfs-dev libdevmapper-dev
- name: Set up Go
uses: actions/setup-go@v2
with:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ jobs:
- uses: actions/checkout@v2
with:
fetch-depth: 2
- name: Install deps
run: |
sudo apt-get install -y libgpgme-dev libbtrfs-dev libdevmapper-dev
- uses: actions/setup-go@v2
with:
go-version: '1.16'
Expand Down
29 changes: 10 additions & 19 deletions apply/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ package apply

import (
"fmt"
"github.com/sealerio/sealer/pkg/imageengine"
common2 "github.com/sealerio/sealer/pkg/imageengine/common"
"os"
"path/filepath"

"github.com/sealerio/sealer/apply/driver"
"github.com/sealerio/sealer/common"
"github.com/sealerio/sealer/pkg/clusterfile"
"github.com/sealerio/sealer/pkg/filesystem"
"github.com/sealerio/sealer/pkg/image"
"github.com/sealerio/sealer/pkg/image/store"
v2 "github.com/sealerio/sealer/types/api/v2"
)

Expand Down Expand Up @@ -57,24 +57,22 @@ func NewApplierFromFile(path string) (driver.Interface, error) {
}
path = filepath.Join(pa, path)
}

Clusterfile, err := clusterfile.NewClusterFile(path)
if err != nil {
return nil, err
}
imgSvc, err := image.NewImageService()
if err != nil {
return nil, err
}

mounter, err := filesystem.NewClusterImageMounter()
imageEngine, err := imageengine.NewImageEngine(common2.EngineGlobalConfigurations{})
if err != nil {
return nil, err
}

is, err := store.NewDefaultImageStore()
mounter, err := filesystem.NewClusterImageMounter(imageEngine)
if err != nil {
return nil, err
}

cluster := Clusterfile.GetCluster()
if cluster.Name == "" {
return nil, fmt.Errorf("cluster name cannot be empty, make sure %s file is correct", path)
Expand All @@ -85,9 +83,8 @@ func NewApplierFromFile(path string) (driver.Interface, error) {
return &driver.Applier{
ClusterDesired: &cluster,
ClusterFile: Clusterfile,
ImageManager: imgSvc,
ImageEngine: imageEngine,
ClusterImageMounter: mounter,
ImageStore: is,
}, nil
}

Expand All @@ -102,25 +99,19 @@ func NewDefaultApplier(cluster *v2.Cluster) (driver.Interface, error) {
if cluster.Name == "" {
return nil, fmt.Errorf("cluster name cannot be empty")
}
imgSvc, err := image.NewImageService()
if err != nil {
return nil, err
}

mounter, err := filesystem.NewClusterImageMounter()
imageEngine, err := imageengine.NewImageEngine(common2.EngineGlobalConfigurations{})
if err != nil {
return nil, err
}

is, err := store.NewDefaultImageStore()
mounter, err := filesystem.NewClusterImageMounter(imageEngine)
if err != nil {
return nil, err
}

return &driver.Applier{
ClusterDesired: cluster,
ImageManager: imgSvc,
ImageEngine: imageEngine,
ClusterImageMounter: mounter,
ImageStore: is,
}, nil
}
31 changes: 21 additions & 10 deletions apply/driver/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ package driver

import (
"fmt"
"github.com/containers/buildah/pkg/parse"
"github.com/sealerio/sealer/pkg/auth"
"github.com/sealerio/sealer/pkg/imageengine"
"net"

"github.com/sealerio/sealer/apply/processor"
"github.com/sealerio/sealer/common"
"github.com/sealerio/sealer/pkg/client/k8s"
"github.com/sealerio/sealer/pkg/clusterfile"
"github.com/sealerio/sealer/pkg/filesystem/clusterimage"
"github.com/sealerio/sealer/pkg/image"
"github.com/sealerio/sealer/pkg/image/store"
"github.com/sealerio/sealer/pkg/runtime"
"github.com/sealerio/sealer/pkg/runtime/kubernetes"
v1 "github.com/sealerio/sealer/types/api/v1"
Expand All @@ -36,6 +37,7 @@ import (
"github.com/sealerio/sealer/utils/strings"

"github.com/pkg/errors"
imagecommon "github.com/sealerio/sealer/pkg/imageengine/common"
"github.com/sirupsen/logrus"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/version"
Expand All @@ -46,10 +48,9 @@ type Applier struct {
ClusterDesired *v2.Cluster
ClusterCurrent *v2.Cluster
ClusterFile clusterfile.Interface
ImageManager image.Service
ImageEngine imageengine.Interface
ClusterImageMounter clusterimage.Interface
Client *k8s.Client
ImageStore store.ImageStore
CurrentClusterInfo *version.Info
}

Expand Down Expand Up @@ -104,10 +105,19 @@ func (c *Applier) mountClusterImage() error {
plat := v
plats = append(plats, &plat)
}
err = c.ImageManager.PullIfNotExist(imageName, plats)
// TODO optimize image engine caller.
err = c.ImageEngine.Pull(&imagecommon.PullOptions{
Authfile: auth.GetDefaultAuthFilePath(),
Quiet: false,
TLSVerify: true,
PullPolicy: "missing",
Image: imageName,
Platform: parse.DefaultPlatform(),
})
if err != nil {
return err
}

err = c.ClusterImageMounter.MountImage(c.ClusterDesired)
if err != nil {
return err
Expand Down Expand Up @@ -143,13 +153,14 @@ func (c *Applier) reconcileCluster() error {
logrus.Warnf("failed to umount image(%s): %v", c.ClusterDesired.ClusterName, err)
}
}()

baseImage, err := c.ImageStore.GetByName(c.ClusterDesired.Spec.Image, platform.GetDefaultPlatform())
image := c.ClusterDesired.Spec.Image
// TODO
imageExtension, err := c.ImageEngine.GetSealerImageExtension(&imagecommon.GetImageAnnoOptions{ImageNameOrID: image})
if err != nil {
return fmt.Errorf("failed to get base image(%s): %v", baseImage.Name, err)
return err
}
// if no rootfs ,try to install applications.
if baseImage.Spec.ImageConfig.ImageType == common.AppImage {

if imageExtension.ImageType == common.AppImage {
return c.installApp()
}

Expand Down
22 changes: 16 additions & 6 deletions apply/processor/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ package processor

import (
"fmt"
"github.com/containers/buildah/pkg/parse"
"github.com/sealerio/sealer/pkg/auth"
"github.com/sealerio/sealer/pkg/imageengine"
imagecommon "github.com/sealerio/sealer/pkg/imageengine/common"

"github.com/sealerio/sealer/pkg/clusterfile"
"github.com/sealerio/sealer/pkg/config"
"github.com/sealerio/sealer/pkg/filesystem"
"github.com/sealerio/sealer/pkg/filesystem/clusterimage"
"github.com/sealerio/sealer/pkg/guest"
"github.com/sealerio/sealer/pkg/image"
"github.com/sealerio/sealer/pkg/plugin"
"github.com/sealerio/sealer/pkg/runtime"
"github.com/sealerio/sealer/pkg/runtime/kubernetes"
Expand All @@ -35,12 +38,12 @@ import (

type CreateProcessor struct {
ClusterFile clusterfile.Interface
ImageManager image.Service
cloudImageMounter clusterimage.Interface
Runtime runtime.Interface
Guest guest.Interface
Config config.Interface
Plugins plugin.Plugins
ImageEngine imageengine.Interface
}

func (c *CreateProcessor) GetPipeLine() ([]func(cluster *v2.Cluster) error, error) {
Expand Down Expand Up @@ -85,7 +88,14 @@ func (c *CreateProcessor) MountImage(cluster *v2.Cluster) error {
plat := v
plats = append(plats, &plat)
}
if err = c.ImageManager.PullIfNotExist(cluster.Spec.Image, plats); err != nil {
if err = c.ImageEngine.Pull(&imagecommon.PullOptions{
Authfile: auth.GetDefaultAuthFilePath(),
Quiet: false,
TLSVerify: true,
PullPolicy: "missing",
Image: cluster.Spec.Image,
Platform: parse.DefaultPlatform(),
}); err != nil {
return err
}
if err = c.cloudImageMounter.MountImage(cluster); err != nil {
Expand Down Expand Up @@ -151,12 +161,12 @@ func (c *CreateProcessor) GetPhasePluginFunc(phase plugin.Phase) func(cluster *v
}

func NewCreateProcessor(clusterFile clusterfile.Interface) (Processor, error) {
imgSvc, err := image.NewImageService()
imageEngine, err := imageengine.NewImageEngine(imagecommon.EngineGlobalConfigurations{})
if err != nil {
return nil, err
}

mounter, err := filesystem.NewClusterImageMounter()
mounter, err := filesystem.NewClusterImageMounter(imageEngine)
if err != nil {
return nil, err
}
Expand All @@ -168,7 +178,7 @@ func NewCreateProcessor(clusterFile clusterfile.Interface) (Processor, error) {

return &CreateProcessor{
ClusterFile: clusterFile,
ImageManager: imgSvc,
ImageEngine: imageEngine,
cloudImageMounter: mounter,
Guest: gs,
}, nil
Expand Down
9 changes: 8 additions & 1 deletion apply/processor/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ package processor

import (
"fmt"
"github.com/sealerio/sealer/pkg/imageengine"
common2 "github.com/sealerio/sealer/pkg/imageengine/common"

"github.com/sealerio/sealer/common"
"github.com/sealerio/sealer/pkg/clusterfile"
Expand Down Expand Up @@ -91,7 +93,12 @@ func (d *DeleteProcessor) CleanFS(cluster *v2.Cluster) error {
}

func NewDeleteProcessor(clusterFile clusterfile.Interface) (Processor, error) {
mounter, err := filesystem.NewClusterImageMounter()
imageEngine, err := imageengine.NewImageEngine(common2.EngineGlobalConfigurations{})
if err != nil {
return nil, err
}

mounter, err := filesystem.NewClusterImageMounter(imageEngine)
if err != nil {
return nil, err
}
Expand Down
11 changes: 8 additions & 3 deletions apply/processor/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package processor

import (
"fmt"
"github.com/sealerio/sealer/pkg/imageengine"
common2 "github.com/sealerio/sealer/pkg/imageengine/common"
"net"
"strconv"

Expand Down Expand Up @@ -53,20 +55,23 @@ type ParserArg struct {
type GenerateProcessor struct {
Runtime *kubernetes.KubeadmRuntime
ImageManager image.Service
ImageEngine imageengine.Interface
ImageMounter clusterimage.Interface
}

func NewGenerateProcessor() (Processor, error) {
imageMounter, err := filesystem.NewClusterImageMounter()
imageEngine, err := imageengine.NewImageEngine(common2.EngineGlobalConfigurations{})
if err != nil {
return nil, err
}
imgSvc, err := image.NewImageService()

imageMounter, err := filesystem.NewClusterImageMounter(imageEngine)
if err != nil {
return nil, err
}

return &GenerateProcessor{
ImageManager: imgSvc,
ImageEngine: imageEngine,
ImageMounter: imageMounter,
}, nil
}
Expand Down
Loading

0 comments on commit 34a7eee

Please sign in to comment.