sources: Simplify Run command signature
Signed-off-by: Thomas Hipp <thomas.hipp@canonical.com>
This commit is contained in:
parent
0612992b66
commit
dd35a5830b
@ -188,8 +188,7 @@ func (c *cmdGlobal) preRunBuild(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
// Download the root filesystem
|
||||
err = downloader.Run(*c.definition, c.definition.Image.Release,
|
||||
c.definition.Image.MappedArchitecture, c.sourceDir)
|
||||
err = downloader.Run(*c.definition, c.sourceDir)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error while downloading source: %s", err)
|
||||
}
|
||||
|
@ -22,10 +22,12 @@ func NewAlpineLinuxHTTP() *AlpineLinuxHTTP {
|
||||
}
|
||||
|
||||
// Run downloads an Alpine Linux mini root filesystem.
|
||||
func (s *AlpineLinuxHTTP) Run(definition shared.Definition, release, arch, rootfsDir string) error {
|
||||
fname := fmt.Sprintf("alpine-minirootfs-%s-%s.tar.gz", release, arch)
|
||||
func (s *AlpineLinuxHTTP) Run(definition shared.Definition, rootfsDir string) error {
|
||||
fname := fmt.Sprintf("alpine-minirootfs-%s-%s.tar.gz", definition.Image.Release,
|
||||
definition.Image.MappedArchitecture)
|
||||
tarball := fmt.Sprintf("%s/v%s/releases/%s/%s", definition.Source.URL,
|
||||
strings.Join(strings.Split(release, ".")[0:2], "."), arch, fname)
|
||||
strings.Join(strings.Split(definition.Image.Release, ".")[0:2], "."),
|
||||
definition.Image.MappedArchitecture, fname)
|
||||
|
||||
url, err := url.Parse(tarball)
|
||||
if err != nil {
|
||||
|
@ -22,9 +22,11 @@ func NewArchLinuxHTTP() *ArchLinuxHTTP {
|
||||
}
|
||||
|
||||
// Run downloads an Arch Linux tarball.
|
||||
func (s *ArchLinuxHTTP) Run(definition shared.Definition, release, arch, rootfsDir string) error {
|
||||
fname := fmt.Sprintf("archlinux-bootstrap-%s-x86_64.tar.gz", release)
|
||||
tarball := fmt.Sprintf("%s/%s/%s", definition.Source.URL, release, fname)
|
||||
func (s *ArchLinuxHTTP) Run(definition shared.Definition, rootfsDir string) error {
|
||||
fname := fmt.Sprintf("archlinux-bootstrap-%s-%s.tar.gz",
|
||||
definition.Image.Release, definition.Image.MappedArchitecture)
|
||||
tarball := fmt.Sprintf("%s/%s/%s", definition.Source.URL,
|
||||
definition.Image.Release, fname)
|
||||
|
||||
url, err := url.Parse(tarball)
|
||||
if err != nil {
|
||||
@ -65,7 +67,8 @@ func (s *ArchLinuxHTTP) Run(definition shared.Definition, release, arch, rootfsD
|
||||
|
||||
// Move everything inside 'root.x86_64' (which was is the tarball) to its
|
||||
// parent directory
|
||||
files, err := filepath.Glob(fmt.Sprintf("%s/*", filepath.Join(rootfsDir, "root.x86_64")))
|
||||
files, err := filepath.Glob(fmt.Sprintf("%s/*", filepath.Join(rootfsDir,
|
||||
"root", definition.Image.MappedArchitecture)))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -77,5 +80,6 @@ func (s *ArchLinuxHTTP) Run(definition shared.Definition, release, arch, rootfsD
|
||||
}
|
||||
}
|
||||
|
||||
return os.RemoveAll(filepath.Join(rootfsDir, "root.x86_64"))
|
||||
return os.RemoveAll(filepath.Join(rootfsDir, "root",
|
||||
definition.Image.MappedArchitecture))
|
||||
}
|
||||
|
@ -27,10 +27,13 @@ func NewCentOSHTTP() *CentOSHTTP {
|
||||
}
|
||||
|
||||
// Run downloads the tarball and unpacks it.
|
||||
func (s *CentOSHTTP) Run(definition shared.Definition, release, arch, rootfsDir string) error {
|
||||
baseURL := fmt.Sprintf("%s/%s/isos/%s/", definition.Source.URL, strings.Split(release, ".")[0], arch)
|
||||
func (s *CentOSHTTP) Run(definition shared.Definition, rootfsDir string) error {
|
||||
baseURL := fmt.Sprintf("%s/%s/isos/%s/", definition.Source.URL,
|
||||
strings.Split(definition.Image.Release, ".")[0],
|
||||
definition.Image.MappedArchitecture)
|
||||
|
||||
s.fname = getRelease(definition.Source.URL, release, definition.Source.Variant, arch)
|
||||
s.fname = getRelease(definition.Source.URL, definition.Image.Release,
|
||||
definition.Source.Variant, definition.Image.MappedArchitecture)
|
||||
if s.fname == "" {
|
||||
return fmt.Errorf("Couldn't get name of iso")
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ func NewDebootstrap() *Debootstrap {
|
||||
}
|
||||
|
||||
// Run runs debootstrap.
|
||||
func (s *Debootstrap) Run(definition shared.Definition, release, arch, rootfsDir string) error {
|
||||
func (s *Debootstrap) Run(definition shared.Definition, rootfsDir string) error {
|
||||
var args []string
|
||||
|
||||
os.RemoveAll(rootfsDir)
|
||||
@ -27,8 +27,8 @@ func (s *Debootstrap) Run(definition shared.Definition, release, arch, rootfsDir
|
||||
args = append(args, "--variant", definition.Source.Variant)
|
||||
}
|
||||
|
||||
if arch != "" {
|
||||
args = append(args, "--arch", arch)
|
||||
if definition.Image.MappedArchitecture != "" {
|
||||
args = append(args, "--arch", definition.Image.MappedArchitecture)
|
||||
}
|
||||
|
||||
if len(definition.Source.Keys) > 0 {
|
||||
@ -41,7 +41,7 @@ func (s *Debootstrap) Run(definition shared.Definition, release, arch, rootfsDir
|
||||
args = append(args, "--keyring", keyring)
|
||||
}
|
||||
|
||||
args = append(args, release, rootfsDir)
|
||||
args = append(args, definition.Image.Release, rootfsDir)
|
||||
|
||||
if definition.Source.URL != "" {
|
||||
args = append(args, definition.Source.URL)
|
||||
@ -50,7 +50,8 @@ func (s *Debootstrap) Run(definition shared.Definition, release, arch, rootfsDir
|
||||
// If definition.Source.Suite is set, create a symlink in /usr/share/debootstrap/scripts
|
||||
// pointing release to definition.Source.Suite.
|
||||
if definition.Source.Suite != "" {
|
||||
link := filepath.Join("/usr/share/debootstrap/scripts", release)
|
||||
link := filepath.Join("/usr/share/debootstrap/scripts",
|
||||
definition.Image.Release)
|
||||
err := os.Symlink(definition.Source.Suite, link)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -4,7 +4,7 @@ import "github.com/lxc/distrobuilder/shared"
|
||||
|
||||
// A Downloader represents a source downloader.
|
||||
type Downloader interface {
|
||||
Run(shared.Definition, string, string, string) error
|
||||
Run(shared.Definition, string) error
|
||||
}
|
||||
|
||||
// Get returns a Downloader.
|
||||
|
@ -28,14 +28,17 @@ func NewUbuntuHTTP() *UbuntuHTTP {
|
||||
}
|
||||
|
||||
// Run downloads the tarball and unpacks it.
|
||||
func (s *UbuntuHTTP) Run(definition shared.Definition, release, arch, rootfsDir string) error {
|
||||
baseURL := fmt.Sprintf("%s/releases/%s/release/", definition.Source.URL, release)
|
||||
func (s *UbuntuHTTP) Run(definition shared.Definition, rootfsDir string) error {
|
||||
baseURL := fmt.Sprintf("%s/releases/%s/release/", definition.Source.URL,
|
||||
definition.Image.Release)
|
||||
|
||||
if strings.ContainsAny(release, "0123456789") {
|
||||
s.fname = fmt.Sprintf("ubuntu-base-%s-base-%s.tar.gz", release, arch)
|
||||
if strings.ContainsAny(definition.Image.Release, "0123456789") {
|
||||
s.fname = fmt.Sprintf("ubuntu-base-%s-base-%s.tar.gz",
|
||||
definition.Image.Release, definition.Image.MappedArchitecture)
|
||||
} else {
|
||||
// if release is non-numerical, find the latest release
|
||||
s.fname = getLatestRelease(definition.Source.URL, release, arch)
|
||||
s.fname = getLatestRelease(definition.Source.URL,
|
||||
definition.Image.Release, definition.Image.MappedArchitecture)
|
||||
if s.fname == "" {
|
||||
return fmt.Errorf("Couldn't find latest release")
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user