The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/distrobuilder/pull/127
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) === If image.release is empty or not set, the latest release will be used. This resolves #126. Signed-off-by: Thomas Hipp <[email protected]>
From c5c899607dbaf9445413e28c9f0741f8b7514ec9 Mon Sep 17 00:00:00 2001 From: Thomas Hipp <[email protected]> Date: Mon, 11 Feb 2019 14:26:13 +0100 Subject: [PATCH] sources: Get latest Arch Linux release by default If image.release is empty or not set, the latest release will be used. Signed-off-by: Thomas Hipp <[email protected]> --- sources/archlinux-http.go | 36 ++++++++++++++++++++++++++++++---- sources/archlinux-http_test.go | 16 +++++++++++++++ 2 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 sources/archlinux-http_test.go diff --git a/sources/archlinux-http.go b/sources/archlinux-http.go index 909f48e..f12ece2 100644 --- a/sources/archlinux-http.go +++ b/sources/archlinux-http.go @@ -7,10 +7,12 @@ import ( "os" "path" "path/filepath" - - lxd "github.com/lxc/lxd/shared" + "strings" "github.com/lxc/distrobuilder/shared" + + lxd "github.com/lxc/lxd/shared" + "gopkg.in/antchfx/htmlquery.v1" ) // ArchLinuxHTTP represents the Arch Linux downloader. @@ -23,10 +25,22 @@ func NewArchLinuxHTTP() *ArchLinuxHTTP { // Run downloads an Arch Linux tarball. func (s *ArchLinuxHTTP) Run(definition shared.Definition, rootfsDir string) error { + release := definition.Image.Release + + if release == "" { + var err error + + // Get latest release + release, err = s.getLatestRelease() + if err != nil { + return err + } + } + fname := fmt.Sprintf("archlinux-bootstrap-%s-%s.tar.gz", - definition.Image.Release, definition.Image.ArchitectureMapped) + release, definition.Image.ArchitectureMapped) tarball := fmt.Sprintf("%s/%s/%s", definition.Source.URL, - definition.Image.Release, fname) + release, fname) url, err := url.Parse(tarball) if err != nil { @@ -84,3 +98,17 @@ func (s *ArchLinuxHTTP) Run(definition shared.Definition, rootfsDir string) erro return os.RemoveAll(filepath.Join(rootfsDir, "root."+ definition.Image.ArchitectureMapped)) } + +func (s *ArchLinuxHTTP) getLatestRelease() (string, error) { + doc, err := htmlquery.LoadURL("https://www.archlinux.org/download/") + if err != nil { + return "", err + } + + node := htmlquery.FindOne(doc, `//*[@id="arch-downloads"]/ul[1]/li[1]/text()`) + if node == nil { + return "", fmt.Errorf("Failed to determine latest release") + } + + return strings.TrimSpace(node.Data), nil +} diff --git a/sources/archlinux-http_test.go b/sources/archlinux-http_test.go new file mode 100644 index 0000000..6f9c3cb --- /dev/null +++ b/sources/archlinux-http_test.go @@ -0,0 +1,16 @@ +package sources + +import ( + "regexp" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestArchLinuxGetLatestRelease(t *testing.T) { + var src ArchLinuxHTTP + + release, err := src.getLatestRelease() + require.NoError(t, err) + require.Regexp(t, regexp.MustCompile(`^\d{4}\.\d{2}\.\d{2}$`), release) +}
_______________________________________________ lxc-devel mailing list [email protected] http://lists.linuxcontainers.org/listinfo/lxc-devel
