The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/distrobuilder/pull/3

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
Since distributions don't have common names for some architectures, e.g. x86_64 vs. amd64, we need to handle this.
From 2424094b17fcc9854629b0b5635930cfbd0b643f Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.h...@canonical.com>
Date: Wed, 7 Feb 2018 11:35:29 +0100
Subject: [PATCH 1/2] *: get correct arch

Signed-off-by: Thomas Hipp <thomas.h...@canonical.com>
---
 distrobuilder/main.go  |  2 +-
 shared/distro.go       | 18 +++++++++++++
 shared/distro_test.go  | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++
 sources/alpine-http.go |  8 +-----
 sources/centos-http.go |  5 ----
 sources/ubuntu-http.go |  9 ++-----
 6 files changed, 95 insertions(+), 20 deletions(-)
 create mode 100644 shared/distro.go
 create mode 100644 shared/distro_test.go

diff --git a/distrobuilder/main.go b/distrobuilder/main.go
index c8187a4..c574b12 100644
--- a/distrobuilder/main.go
+++ b/distrobuilder/main.go
@@ -142,7 +142,7 @@ func run(c *cli.Context) error {
        }
 
        err = downloader.Run(def.Source.URL, def.Image.Release, 
def.Image.Variant,
-               def.Image.Arch, c.GlobalString("cache-dir"))
+               shared.GetArch(def.Image.Distribution, def.Image.Arch), 
c.GlobalString("cache-dir"))
        if err != nil {
                return fmt.Errorf("Error while downloading source: %s", err)
        }
diff --git a/shared/distro.go b/shared/distro.go
new file mode 100644
index 0000000..398b64e
--- /dev/null
+++ b/shared/distro.go
@@ -0,0 +1,18 @@
+package shared
+
+// GetArch returns the correct architecture name used by the specified
+// distribution.
+func GetArch(distro, arch string) string {
+       switch distro {
+       case "alpinelinux", "archlinux", "centos":
+               if arch == "amd64" {
+                       return "x86_64"
+               }
+       case "debian", "ubuntu":
+               if arch == "x86_64" {
+                       return "amd64"
+               }
+       }
+
+       return arch
+}
diff --git a/shared/distro_test.go b/shared/distro_test.go
new file mode 100644
index 0000000..d0ee7af
--- /dev/null
+++ b/shared/distro_test.go
@@ -0,0 +1,73 @@
+package shared
+
+import (
+       "log"
+       "testing"
+)
+
+func TestGetArch(t *testing.T) {
+       tests := []struct {
+               distro   string
+               arch     string
+               expected string
+       }{
+               {
+                       "alpinelinux",
+                       "amd64",
+                       "x86_64",
+               },
+               {
+                       "alpinelinux",
+                       "x86_64",
+                       "x86_64",
+               },
+               {
+                       "archlinux",
+                       "amd64",
+                       "x86_64",
+               },
+               {
+                       "archlinux",
+                       "x86_64",
+                       "x86_64",
+               },
+               {
+                       "centos",
+                       "amd64",
+                       "x86_64",
+               },
+               {
+                       "centos",
+                       "x86_64",
+                       "x86_64",
+               },
+               {
+                       "debian",
+                       "amd64",
+                       "amd64",
+               },
+               {
+                       "debian",
+                       "x86_64",
+                       "amd64",
+               },
+               {
+                       "ubuntu",
+                       "amd64",
+                       "amd64",
+               },
+               {
+                       "ubuntu",
+                       "x86_64",
+                       "amd64",
+               },
+       }
+
+       for i, tt := range tests {
+               log.Printf("Running test #%d: %s %s", i, tt.distro, tt.arch)
+               arch := GetArch(tt.distro, tt.arch)
+               if arch != tt.expected {
+                       t.Fatalf("Wrong arch: Expected '%s', got '%s'", 
tt.expected, arch)
+               }
+       }
+}
diff --git a/sources/alpine-http.go b/sources/alpine-http.go
index 487970c..f29c652 100644
--- a/sources/alpine-http.go
+++ b/sources/alpine-http.go
@@ -21,12 +21,6 @@ func NewAlpineLinuxHTTP() *AlpineLinuxHTTP {
 
 // Run runs debootstrap.
 func (s *AlpineLinuxHTTP) Run(URL, release, variant, arch, cacheDir string) 
error {
-       realArch := arch
-
-       if arch == "amd64" {
-               realArch = "x86_64"
-       }
-
        fname := fmt.Sprintf("alpine-minirootfs-%s-%s.tar.gz", release, arch)
 
        // Download
@@ -34,7 +28,7 @@ func (s *AlpineLinuxHTTP) Run(URL, release, variant, arch, 
cacheDir string) erro
        strings.Join(parts[0:2], ".")
        err := shared.Download(URL+path.Join("/",
                fmt.Sprintf("v%s", strings.Join(strings.Split(release, 
".")[0:2], ".")),
-               "releases", realArch, fname), "")
+               "releases", arch, fname), "")
        if err != nil {
                return err
        }
diff --git a/sources/centos-http.go b/sources/centos-http.go
index 23c8aca..48a42bb 100644
--- a/sources/centos-http.go
+++ b/sources/centos-http.go
@@ -29,11 +29,6 @@ func NewCentOSHTTP() *CentOSHTTP {
 func (s *CentOSHTTP) Run(URL, release, variant, arch, cacheDir string) error {
        s.cacheDir = cacheDir
 
-       realArch := arch
-       if realArch == "amd64" {
-               realArch = "x86_64"
-       }
-
        s.fname = getRelease(URL, release, variant, arch)
        if s.fname == "" {
                return fmt.Errorf("Couldn't get name of iso")
diff --git a/sources/ubuntu-http.go b/sources/ubuntu-http.go
index 0111227..479882b 100644
--- a/sources/ubuntu-http.go
+++ b/sources/ubuntu-http.go
@@ -26,16 +26,11 @@ func NewUbuntuHTTP() *UbuntuHTTP {
 
 // Run downloads the tarball and unpacks it.
 func (s *UbuntuHTTP) Run(URL, release, variant, arch, cacheDir string) error {
-       realArch := arch
-       if realArch == "x86_64" {
-               realArch = "amd64"
-       }
-
        if strings.ContainsAny(release, "0123456789") {
-               s.fname = fmt.Sprintf("ubuntu-base-%s-base-%s.tar.gz", release, 
realArch)
+               s.fname = fmt.Sprintf("ubuntu-base-%s-base-%s.tar.gz", release, 
arch)
        } else {
                // if release is non-numerical, find the latest release
-               s.fname = getLatestRelease(URL, release, realArch)
+               s.fname = getLatestRelease(URL, release, arch)
                if s.fname == "" {
                        return fmt.Errorf("Couldn't find latest release")
                }

From cb872c3637c4d147b74dafab155db28f3021aec1 Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.h...@canonical.com>
Date: Wed, 7 Feb 2018 11:16:09 +0100
Subject: [PATCH 2/2] sources: fix debootstrap condition

Signed-off-by: Thomas Hipp <thomas.h...@canonical.com>
---
 sources/debootstrap.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sources/debootstrap.go b/sources/debootstrap.go
index 6a398dc..1439ce3 100644
--- a/sources/debootstrap.go
+++ b/sources/debootstrap.go
@@ -25,7 +25,7 @@ func (s *Debootstrap) Run(URL, release, variant, arch, 
cacheDir string) error {
                args = append(args, "--variant", variant)
        }
 
-       if arch != arch {
+       if arch != "" {
                args = append(args, "--arch", arch)
        }
 
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to