[lxc-devel] [distrobuilder/master] Wip/d4s/apertis

d4s on Github lxc-bot at linuxcontainers.org
Sat Aug 31 02:03:45 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 418 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190830/6c7aa0e9/attachment.bin>
-------------- next part --------------
From 44317dd2c18ae10be28b3d51156719186123393c Mon Sep 17 00:00:00 2001
From: Denis Pynkin <denis.pynkin at collabora.com>
Date: Sat, 31 Aug 2019 03:21:53 +0300
Subject: [PATCH 1/2] Add Apertis OS downloader

Simple downloader which relies to "https" URL schema.

Signed-off-by: Denis Pynkin <denis.pynkin at collabora.com>
---
 doc/source.md           |  1 +
 shared/definition.go    |  1 +
 sources/apertis-http.go | 59 +++++++++++++++++++++++++++++++++++++++++
 sources/source.go       |  2 ++
 4 files changed, 63 insertions(+)
 create mode 100644 sources/apertis-http.go

diff --git a/doc/source.md b/doc/source.md
index de68a6c..e9af1ae 100644
--- a/doc/source.md
+++ b/doc/source.md
@@ -22,6 +22,7 @@ It needs to be one of
 
 * alpinelinux-http
 * alt-http
+* apertis-http
 * archlinux-http
 * centos-http
 * debootstrap
diff --git a/shared/definition.go b/shared/definition.go
index ceae83e..5699c20 100644
--- a/shared/definition.go
+++ b/shared/definition.go
@@ -255,6 +255,7 @@ func (d *Definition) Validate() error {
 	validDownloaders := []string{
 		"alpinelinux-http",
 		"alt-http",
+		"apertis-http",
 		"archlinux-http",
 		"centos-http",
 		"debootstrap",
diff --git a/sources/apertis-http.go b/sources/apertis-http.go
new file mode 100644
index 0000000..0bd8ef1
--- /dev/null
+++ b/sources/apertis-http.go
@@ -0,0 +1,59 @@
+package sources
+
+import (
+	"errors"
+	"fmt"
+	"net/url"
+	"path/filepath"
+
+	lxd "github.com/lxc/lxd/shared"
+
+	"github.com/lxc/distrobuilder/shared"
+)
+
+// ApertisHTTP represents the Apertis downloader.
+type ApertisHTTP struct{}
+
+// NewApertisHTTP creates a new ApertisHTTP instance.
+func NewApertisHTTP() *ApertisHTTP {
+	return &ApertisHTTP{}
+}
+
+// Run downloads the tarball and unpacks it.
+func (s *ApertisHTTP) Run(definition shared.Definition, rootfsDir string) error {
+	architecture := definition.Image.Architecture
+	release := definition.Image.Release
+	variant := definition.Image.Variant
+	serial := definition.Image.Serial
+
+	// https://images.apertis.org/daily/v2020dev0/20190830.0/amd64/minimal/ospack_v2020dev0-amd64-minimal_20190830.0.tar.gz
+	baseURL := fmt.Sprintf("%s/%s",
+		definition.Source.URL, definition.Source.Variant)
+	baseURL = fmt.Sprintf("%s/%s/%s/%s/%s/",
+		baseURL, release, serial, architecture, variant)
+	fname := fmt.Sprintf("ospack_%s-%s-%s_%s.tar.gz",
+		release, architecture, variant, serial)
+
+	url, err := url.Parse(baseURL)
+	if err != nil {
+		return err
+	}
+
+	// Force gpg checks when using http
+	if url.Scheme != "https" {
+		return errors.New("Only HTTPS server is supported")
+	}
+
+	fpath, err := shared.DownloadHash(definition.Image, baseURL+fname, "", nil)
+	if err != nil {
+		return err
+	}
+
+	// Unpack
+	err = lxd.Unpack(filepath.Join(fpath, fname), rootfsDir, false, false, nil)
+	if err != nil {
+		return err
+	}
+
+	return nil
+}
diff --git a/sources/source.go b/sources/source.go
index b2ea519..fce32c5 100644
--- a/sources/source.go
+++ b/sources/source.go
@@ -14,6 +14,8 @@ func Get(name string) Downloader {
 		return NewAlpineLinuxHTTP()
 	case "alt-http":
 		return NewALTHTTP()
+	case "apertis-http":
+		return NewApertisHTTP()
 	case "archlinux-http":
 		return NewArchLinuxHTTP()
 	case "centos-http":

From 827d4cc842839c83d0fdcf2720528504de8e73d9 Mon Sep 17 00:00:00 2001
From: Denis Pynkin <denis.pynkin at collabora.com>
Date: Sat, 31 Aug 2019 04:59:03 +0300
Subject: [PATCH 2/2] Add Apertis example

Config allows to download and start all Apertis variants,
however for proper work need to start container in privileged mode.

Signed-off-by: Denis Pynkin <denis.pynkin at collabora.com>
---
 doc/examples/apertis | 64 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 64 insertions(+)
 create mode 100644 doc/examples/apertis

diff --git a/doc/examples/apertis b/doc/examples/apertis
new file mode 100644
index 0000000..d8ae95e
--- /dev/null
+++ b/doc/examples/apertis
@@ -0,0 +1,64 @@
+image:
+  distribution: Apertis
+  description: Apertis {{ image.architecture }} {{ image.variant }} {{ image.release }} {{ image.serial }}
+  release: 18.12
+  variant: minimal
+  serial: 18.12.0
+  expiry: 30d
+  architecture: amd64
+
+source:
+  downloader: apertis-http
+  url: https://images.apertis.org
+  variant: release
+
+targets:
+  lxc:
+    create-message: |
+      You just created an {{ image.distribution }} container (release={{ image.release }}, arch={{ image.architecture }})
+
+    config:
+      - type: all
+        before: 5
+        content: |-
+          lxc.include = LXC_TEMPLATE_CONFIG/debian.common.conf
+
+      - type: user
+        before: 5
+        content: |-
+          lxc.include = LXC_TEMPLATE_CONFIG/debian.userns.conf
+
+      - type: all
+        after: 4
+        content: |-
+          lxc.include = LXC_TEMPLATE_CONFIG/common.conf
+
+      - type: user
+        after: 4
+        content: |-
+          lxc.include = LXC_TEMPLATE_CONFIG/userns.conf
+
+      - type: all
+        content: |-
+          lxc.arch = {{ image.architecture_personality }}
+
+files:
+ - path: /etc/hostname
+   generator: hostname
+
+ - path: /etc/hosts
+   generator: hosts
+
+ - path: /etc/machine-id
+   generator: remove
+
+
+packages:
+  manager: apt
+  update: false
+  cleanup: false
+
+environment:
+  variables:
+    - key: TMPDIR
+      set: false


More information about the lxc-devel mailing list