mirror of
https://github.com/mudler/luet.git
synced 2025-09-16 23:31:08 +00:00
Return client from repository and install packages in the workers
This commit is contained in:
20
pkg/installer/client/interface.go
Normal file
20
pkg/installer/client/interface.go
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
// Copyright © 2019 Ettore Di Giacinto <mudler@gentoo.org>
|
||||||
|
//
|
||||||
|
// This program is free software; you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation; either version 2 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License along
|
||||||
|
// with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
package client
|
||||||
|
|
||||||
|
type RepoData struct {
|
||||||
|
Uri string
|
||||||
|
}
|
@@ -22,33 +22,25 @@ import (
|
|||||||
|
|
||||||
"github.com/mudler/luet/pkg/compiler"
|
"github.com/mudler/luet/pkg/compiler"
|
||||||
"github.com/mudler/luet/pkg/helpers"
|
"github.com/mudler/luet/pkg/helpers"
|
||||||
"github.com/mudler/luet/pkg/installer"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type LocalClient struct {
|
type LocalClient struct {
|
||||||
Repository installer.Repository
|
RepoData RepoData
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewLocalClient(r installer.Repository) installer.Client {
|
func NewLocalClient(r RepoData) *LocalClient {
|
||||||
return &LocalClient{Repository: r}
|
return &LocalClient{RepoData: r}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *LocalClient) GetRepository() installer.Repository {
|
|
||||||
return c.Repository
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *LocalClient) SetRepository(r installer.Repository) {
|
|
||||||
c.Repository = r
|
|
||||||
}
|
|
||||||
func (c *LocalClient) DownloadArtifact(artifact compiler.Artifact) (compiler.Artifact, error) {
|
func (c *LocalClient) DownloadArtifact(artifact compiler.Artifact) (compiler.Artifact, error) {
|
||||||
|
|
||||||
file, err := ioutil.TempFile(os.TempDir(), "localclient")
|
file, err := ioutil.TempFile(os.TempDir(), "localclient")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return nil, err
|
||||||
}
|
}
|
||||||
//defer os.Remove(file.Name())
|
//defer os.Remove(file.Name())
|
||||||
|
|
||||||
err = helpers.CopyFile(filepath.Join(repo.GetUri(), artifact.GetPath()), file.Name())
|
err = helpers.CopyFile(filepath.Join(c.RepoData.Uri, artifact.GetPath()), file.Name())
|
||||||
|
|
||||||
return compiler.NewPackageArtifact(file.Name()), nil
|
return compiler.NewPackageArtifact(file.Name()), nil
|
||||||
}
|
}
|
||||||
@@ -60,7 +52,7 @@ func (c *LocalClient) DownloadFile(name string) (string, error) {
|
|||||||
}
|
}
|
||||||
//defer os.Remove(file.Name())
|
//defer os.Remove(file.Name())
|
||||||
|
|
||||||
err = helpers.CopyFile(filepath.Join(r.GetUri(), name), file.Name())
|
err = helpers.CopyFile(filepath.Join(c.RepoData.Uri, name), file.Name())
|
||||||
|
|
||||||
return file.Name(), err
|
return file.Name(), err
|
||||||
}
|
}
|
||||||
|
@@ -17,12 +17,14 @@ package installer
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"sort"
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/ghodss/yaml"
|
"github.com/ghodss/yaml"
|
||||||
compiler "github.com/mudler/luet/pkg/compiler"
|
compiler "github.com/mudler/luet/pkg/compiler"
|
||||||
|
"github.com/mudler/luet/pkg/helpers"
|
||||||
. "github.com/mudler/luet/pkg/logger"
|
. "github.com/mudler/luet/pkg/logger"
|
||||||
pkg "github.com/mudler/luet/pkg/package"
|
pkg "github.com/mudler/luet/pkg/package"
|
||||||
"github.com/mudler/luet/pkg/solver"
|
"github.com/mudler/luet/pkg/solver"
|
||||||
@@ -31,7 +33,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type LuetInstaller struct {
|
type LuetInstaller struct {
|
||||||
PackageClient Client
|
|
||||||
PackageRepositories Repositories
|
PackageRepositories Repositories
|
||||||
Concurrency int
|
Concurrency int
|
||||||
}
|
}
|
||||||
@@ -94,7 +95,7 @@ func (l *LuetInstaller) Install(p []pkg.Package, s *System) error {
|
|||||||
defer SpinnerStop()
|
defer SpinnerStop()
|
||||||
syncedRepos := Repositories{}
|
syncedRepos := Repositories{}
|
||||||
for _, r := range l.PackageRepositories {
|
for _, r := range l.PackageRepositories {
|
||||||
repo, err := r.Sync(l.PackageClient)
|
repo, err := r.Sync()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "Failed syncing repository"+r.GetName())
|
return errors.Wrap(err, "Failed syncing repository"+r.GetName())
|
||||||
}
|
}
|
||||||
@@ -245,6 +246,14 @@ func (l *LuetInstaller) Install(p []pkg.Package, s *System) error {
|
|||||||
func (l *LuetInstaller) installPackage(a ArtifactMatch, s *System) error {
|
func (l *LuetInstaller) installPackage(a ArtifactMatch, s *System) error {
|
||||||
|
|
||||||
// FIXME: Implement
|
// FIXME: Implement
|
||||||
|
artifact, err := a.Repository.Client().DownloadArtifact(a.Artifact)
|
||||||
|
defer os.Remove(artifact.GetPath())
|
||||||
|
err = helpers.Untar(artifact.GetPath(), s.Target, true)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "Error met while unpacking rootfs")
|
||||||
|
}
|
||||||
|
// First create client and download
|
||||||
|
// Then unpack to system
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,5 +277,4 @@ func (l *LuetInstaller) Uninstall(p []pkg.Package, s *System) error {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *LuetInstaller) Client(c Client) { l.PackageClient = c }
|
|
||||||
func (l *LuetInstaller) Repositories(r []Repository) { l.PackageRepositories = r }
|
func (l *LuetInstaller) Repositories(r []Repository) { l.PackageRepositories = r }
|
||||||
|
87
pkg/installer/installer_test.go
Normal file
87
pkg/installer/installer_test.go
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
// Copyright © 2019 Ettore Di Giacinto <mudler@gentoo.org>
|
||||||
|
//
|
||||||
|
// This program is free software; you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU General Public License as published by
|
||||||
|
// the Free Software Foundation; either version 2 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// This program is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU General Public License along
|
||||||
|
// with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
package installer_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
// . "github.com/mudler/luet/pkg/installer"
|
||||||
|
backend "github.com/mudler/luet/pkg/compiler/backend"
|
||||||
|
|
||||||
|
compiler "github.com/mudler/luet/pkg/compiler"
|
||||||
|
"github.com/mudler/luet/pkg/helpers"
|
||||||
|
pkg "github.com/mudler/luet/pkg/package"
|
||||||
|
"github.com/mudler/luet/pkg/tree"
|
||||||
|
. "github.com/onsi/ginkgo"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ = Describe("Installer", func() {
|
||||||
|
Context("Writes a repository definition", func() {
|
||||||
|
It("Writes a repo", func() {
|
||||||
|
//repo:=NewLuetRepository()
|
||||||
|
|
||||||
|
tmpdir, err := ioutil.TempDir("", "tree")
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
defer os.RemoveAll(tmpdir) // clean up
|
||||||
|
|
||||||
|
generalRecipe := tree.NewCompilerRecipe(pkg.NewInMemoryDatabase(false))
|
||||||
|
|
||||||
|
err = generalRecipe.Load("../../tests/fixtures/buildable")
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
Expect(generalRecipe.Tree()).ToNot(BeNil()) // It should be populated back at this point
|
||||||
|
|
||||||
|
Expect(len(generalRecipe.Tree().GetPackageSet().GetPackages())).To(Equal(3))
|
||||||
|
|
||||||
|
compiler := compiler.NewLuetCompiler(backend.NewSimpleDockerBackend(), generalRecipe.Tree(), generalRecipe.Tree().GetPackageSet())
|
||||||
|
err = compiler.Prepare(1)
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
|
spec, err := compiler.FromPackage(&pkg.DefaultPackage{Name: "b", Category: "test", Version: "1.0"})
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
|
Expect(spec.GetPackage().GetPath()).ToNot(Equal(""))
|
||||||
|
|
||||||
|
tmpdir, err = ioutil.TempDir("", "tree")
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
defer os.RemoveAll(tmpdir) // clean up
|
||||||
|
|
||||||
|
Expect(spec.BuildSteps()).To(Equal([]string{"echo artifact5 > /test5", "echo artifact6 > /test6", "./generate.sh"}))
|
||||||
|
Expect(spec.GetPreBuildSteps()).To(Equal([]string{"echo foo > /test", "echo bar > /test2", "chmod +x generate.sh"}))
|
||||||
|
|
||||||
|
spec.SetOutputPath(tmpdir)
|
||||||
|
artifact, err := compiler.Compile(2, false, spec)
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
Expect(helpers.Exists(artifact.GetPath())).To(BeTrue())
|
||||||
|
Expect(helpers.Untar(artifact.GetPath(), tmpdir, false)).ToNot(HaveOccurred())
|
||||||
|
|
||||||
|
Expect(helpers.Exists(spec.Rel("test5"))).To(BeTrue())
|
||||||
|
Expect(helpers.Exists(spec.Rel("test6"))).To(BeTrue())
|
||||||
|
|
||||||
|
content1, err := helpers.Read(spec.Rel("test5"))
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
content2, err := helpers.Read(spec.Rel("test6"))
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
Expect(content1).To(Equal("artifact5\n"))
|
||||||
|
Expect(content2).To(Equal("artifact6\n"))
|
||||||
|
|
||||||
|
Expect(helpers.Exists(spec.Rel("b-test-1.0.package.tar"))).To(BeTrue())
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
})
|
@@ -25,16 +25,12 @@ import (
|
|||||||
type Installer interface {
|
type Installer interface {
|
||||||
Install([]pkg.Package, *System) error
|
Install([]pkg.Package, *System) error
|
||||||
Uninstall([]pkg.Package, *System) error
|
Uninstall([]pkg.Package, *System) error
|
||||||
Client(Client)
|
|
||||||
Repositories([]Repository)
|
Repositories([]Repository)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Client interface {
|
type Client interface {
|
||||||
DownloadArtifact(compiler.Artifact) (compiler.Artifact, error)
|
DownloadArtifact(compiler.Artifact) (compiler.Artifact, error)
|
||||||
DownloadFile(string) (string, error)
|
DownloadFile(string) (string, error)
|
||||||
|
|
||||||
GetRepository() Repository
|
|
||||||
SetRepository(Repository)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Repositories []Repository
|
type Repositories []Repository
|
||||||
@@ -46,9 +42,10 @@ type Repository interface {
|
|||||||
GetIndex() compiler.ArtifactIndex
|
GetIndex() compiler.ArtifactIndex
|
||||||
GetTree() tree.Builder
|
GetTree() tree.Builder
|
||||||
Write(path string) error
|
Write(path string) error
|
||||||
Sync(Client) (Repository, error)
|
Sync() (Repository, error)
|
||||||
GetTreePath() string
|
GetTreePath() string
|
||||||
SetTreePath(string)
|
SetTreePath(string)
|
||||||
GetType() string
|
GetType() string
|
||||||
SetType(string)
|
SetType(string)
|
||||||
|
Client() Client
|
||||||
}
|
}
|
||||||
|
@@ -22,6 +22,7 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/mudler/luet/pkg/installer/client"
|
||||||
. "github.com/mudler/luet/pkg/logger"
|
. "github.com/mudler/luet/pkg/logger"
|
||||||
|
|
||||||
"github.com/ghodss/yaml"
|
"github.com/ghodss/yaml"
|
||||||
@@ -153,8 +154,16 @@ func (r *LuetRepository) Write(dst string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *LuetRepository) Sync(c Client) (Repository, error) {
|
func (r *LuetRepository) Client() Client {
|
||||||
c.SetRepository(r)
|
switch r.GetType() {
|
||||||
|
case "local":
|
||||||
|
return client.NewLocalClient(client.RepoData{Uri: r.GetUri()})
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (r *LuetRepository) Sync() (Repository, error) {
|
||||||
|
c := r.Client()
|
||||||
|
|
||||||
file, err := c.DownloadFile("repository.yaml")
|
file, err := c.DownloadFile("repository.yaml")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -206,8 +215,6 @@ func (r *LuetRepository) Sync(c Client) (Repository, error) {
|
|||||||
return repo, nil
|
return repo, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO:
|
|
||||||
|
|
||||||
func (r Repositories) Len() int { return len(r) }
|
func (r Repositories) Len() int { return len(r) }
|
||||||
func (r Repositories) Swap(i, j int) { r[i], r[j] = r[j], r[i] }
|
func (r Repositories) Swap(i, j int) { r[i], r[j] = r[j], r[i] }
|
||||||
func (r Repositories) Less(i, j int) bool {
|
func (r Repositories) Less(i, j int) bool {
|
||||||
|
Reference in New Issue
Block a user