[lxc-devel] [distrobuilder/master] Add ALT Linux
Obirvalger on Github
lxc-bot at linuxcontainers.org
Sun Mar 24 16:18:46 UTC 2019
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 310 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190324/26344ca0/attachment.bin>
-------------- next part --------------
From 124e5983a4f3e55ea9c73789a4a48c4d7a76c3f3 Mon Sep 17 00:00:00 2001
From: Mikhail Gordeev <obirvalger at altlinux.org>
Date: Sun, 24 Mar 2019 18:53:49 +0300
Subject: [PATCH 1/4] chroot: Unset TMPDIR environment variable
Scripts running while package installation could use TMPDIR variable and
they break when working in chroot with system TMPDIR value.
Signed-off-by: Mikhail Gordeev <obirvalger at altlinux.org>
---
shared/chroot.go | 3 +++
1 file changed, 3 insertions(+)
diff --git a/shared/chroot.go b/shared/chroot.go
index 8f18fb7..27d5c61 100644
--- a/shared/chroot.go
+++ b/shared/chroot.go
@@ -221,6 +221,9 @@ func SetupChroot(rootfs string, envs DefinitionEnv) (func() error, error) {
Value: "noninteractive",
Set: true,
},
+ "TMPDIR": EnvVariable{
+ Set: false,
+ },
}
}
From f08282ba2c5f1aeb34b9d13c2c80dfcd1fd30812 Mon Sep 17 00:00:00 2001
From: Mikhail Gordeev <obirvalger at altlinux.org>
Date: Fri, 22 Mar 2019 20:00:14 +0300
Subject: [PATCH 2/4] source: Add ALT Linux downloader
Signed-off-by: Mikhail Gordeev <obirvalger at altlinux.org>
---
shared/definition.go | 1 +
sources/alt-http.go | 81 ++++++++++++++++++++++++++++++++++++++++++++
sources/source.go | 2 ++
3 files changed, 84 insertions(+)
create mode 100644 sources/alt-http.go
diff --git a/shared/definition.go b/shared/definition.go
index a7da81e..50c103b 100644
--- a/shared/definition.go
+++ b/shared/definition.go
@@ -248,6 +248,7 @@ func (d *Definition) Validate() error {
validDownloaders := []string{
"alpinelinux-http",
+ "alt-http",
"archlinux-http",
"centos-http",
"debootstrap",
diff --git a/sources/alt-http.go b/sources/alt-http.go
new file mode 100644
index 0000000..3cf4bd7
--- /dev/null
+++ b/sources/alt-http.go
@@ -0,0 +1,81 @@
+package sources
+
+import (
+ "crypto/sha256"
+ "errors"
+ "fmt"
+ "net/url"
+ "path/filepath"
+ "strings"
+
+ "github.com/lxc/distrobuilder/shared"
+ lxd "github.com/lxc/lxd/shared"
+)
+
+// ALTHTTP represents the ALT Linux downloader.
+type ALTHTTP struct{}
+
+// NewALTHTTP creates a new ALTHTTP instance.
+func NewALTHTTP() *ALTHTTP {
+ return &ALTHTTP{}
+}
+
+// Run downloads the tarball and unpacks it.
+func (s *ALTHTTP) Run(definition shared.Definition, rootfsDir string) error {
+ release := definition.Image.Release
+
+ baseURL := fmt.Sprintf("%s/%s/cloud/",
+ definition.Source.URL, release)
+
+ fname := fmt.Sprintf("alt-%s-rootfs-systemd-%s.tar.xz", strings.ToLower(release),
+ definition.Image.ArchitectureMapped)
+
+ url, err := url.Parse(baseURL)
+ if err != nil {
+ return err
+ }
+
+ checksumFile := ""
+ if !definition.Source.SkipVerification {
+ if len(definition.Source.Keys) != 0 {
+
+ checksumFile = baseURL + "SHA256SUM"
+ fpath, err := shared.DownloadHash(definition.Image, checksumFile+".asc", "", nil)
+ if err != nil {
+ return err
+ }
+
+ shared.DownloadHash(definition.Image, checksumFile, "", nil)
+
+ valid, err := shared.VerifyFile(
+ filepath.Join(fpath, "SHA256SUM"),
+ filepath.Join(fpath, "SHA256SUM.asc"),
+ definition.Source.Keys,
+ definition.Source.Keyserver)
+ if err != nil {
+ return err
+ }
+ if !valid {
+ return fmt.Errorf("Failed to validate tarball")
+ }
+ } else {
+ // Force gpg checks when using http
+ if url.Scheme != "https" {
+ return errors.New("GPG keys are required if downloading from HTTP")
+ }
+ }
+ }
+
+ fpath, err := shared.DownloadHash(definition.Image, baseURL+fname, checksumFile, sha256.New())
+ 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 2d4bc3b..657bc8a 100644
--- a/sources/source.go
+++ b/sources/source.go
@@ -12,6 +12,8 @@ func Get(name string) Downloader {
switch name {
case "alpinelinux-http":
return NewAlpineLinuxHTTP()
+ case "alt-http":
+ return NewALTHTTP()
case "archlinux-http":
return NewArchLinuxHTTP()
case "centos-http":
From 5ef26999c4d0b282b6ee17d369945f7948f6e5b8 Mon Sep 17 00:00:00 2001
From: Mikhail Gordeev <obirvalger at altlinux.org>
Date: Fri, 22 Mar 2019 20:01:18 +0300
Subject: [PATCH 3/4] manager: Add apt_rpm package manager
ALT Linux apt does not support --auto-remove flag with remove operation
Signed-off-by: Mikhail Gordeev <obirvalger at altlinux.org>
---
managers/apt_rpm.go | 34 ++++++++++++++++++++++++++++++++++
managers/manager.go | 2 ++
shared/definition.go | 1 +
3 files changed, 37 insertions(+)
create mode 100644 managers/apt_rpm.go
diff --git a/managers/apt_rpm.go b/managers/apt_rpm.go
new file mode 100644
index 0000000..7a7c283
--- /dev/null
+++ b/managers/apt_rpm.go
@@ -0,0 +1,34 @@
+package managers
+
+// NewAptRPM creates a new Manager instance.
+func NewAptRPM() *Manager {
+ return &Manager{
+ commands: ManagerCommands{
+ clean: "apt-get",
+ install: "apt-get",
+ refresh: "apt-get",
+ remove: "apt-get",
+ update: "apt-get",
+ },
+ flags: ManagerFlags{
+ clean: []string{
+ "clean",
+ },
+ global: []string{
+ "-y",
+ },
+ install: []string{
+ "install",
+ },
+ remove: []string{
+ "remove",
+ },
+ refresh: []string{
+ "update",
+ },
+ update: []string{
+ "dist-upgrade",
+ },
+ },
+ }
+}
diff --git a/managers/manager.go b/managers/manager.go
index 5823052..00c2ac1 100644
--- a/managers/manager.go
+++ b/managers/manager.go
@@ -41,6 +41,8 @@ func Get(name string) *Manager {
return NewApk()
case "apt":
return NewApt()
+ case "apt_rpm":
+ return NewAptRPM()
case "dnf":
return NewDnf()
case "pacman":
diff --git a/shared/definition.go b/shared/definition.go
index 50c103b..d824bfc 100644
--- a/shared/definition.go
+++ b/shared/definition.go
@@ -269,6 +269,7 @@ func (d *Definition) Validate() error {
validManagers := []string{
"apk",
"apt",
+ "apt_rpm",
"dnf",
"pacman",
"portage",
From 02912be0e648517878bdcef58619a7be49c3c58e Mon Sep 17 00:00:00 2001
From: Mikhail Gordeev <obirvalger at altlinux.org>
Date: Fri, 22 Mar 2019 20:25:33 +0300
Subject: [PATCH 4/4] doc: Add ALT Linux example
Signed-off-by: Mikhail Gordeev <obirvalger at altlinux.org>
---
doc/examples/alt | 75 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 75 insertions(+)
create mode 100644 doc/examples/alt
diff --git a/doc/examples/alt b/doc/examples/alt
new file mode 100644
index 0000000..4df73a7
--- /dev/null
+++ b/doc/examples/alt
@@ -0,0 +1,75 @@
+image:
+ distribution: ALT Linux
+ release: Sisyphus
+ description: ALT Linux {{ image.release }}
+ expiry: 30d
+ architecture: x86_64
+
+source:
+ downloader: alt-http
+ url: http://ftp.altlinux.org/pub/distributions/ALTLinux/images
+ keyserver: hkp://keys.gnupg.net
+ keys:
+ - 0x17F112840DE94827C9C109FD3E2B30EA57EF33CE
+
+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/alt.common.conf
+
+ - type: user
+ before: 5
+ content: |-
+ lxc.include = LXC_TEMPLATE_CONFIG/alt.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_kernel }}
+
+files:
+ - path: /etc/hostname
+ generator: hostname
+
+ - path: /etc/hosts
+ generator: hosts
+
+ - path: /etc/systemd/network/eth0.network
+ generator: dump
+ content: |-
+ [Match]
+ Name=eth0
+
+ [Network]
+ DHCP=ipv4
+
+packages:
+ manager: apt_rpm
+
+ update: true
+ cleanup: true
+
+ sets:
+ - packages:
+ - vim-console
+ action: install
+
+environment:
+ variables:
+ - key: HOME
+ value: /root
More information about the lxc-devel
mailing list