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

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) ===
In order to create a usable image, we would also need to add a `post-unpack` action to the definition:
```yaml
actions:
  - trigger: post-unpack
    action: |-
      #!/bin/sh
      cd /mnt/cdrom/Packages
      rpm -ivh --nodeps rpm-4.11.3-25.el7.x86_64.rpm
      rpm -ivh --nodeps yum-3.4.3-154.el7.centos.noarch.rpm

      # add cdrom repo
      mkdir -p /etc/yum.repos.d
      cat <<- EOF > /etc/yum.repos.d/cdrom.repo
      [cdrom]
      name=Install CD-ROM
      baseurl=file:///mnt/cdrom
      enabled=0
      gpgcheck=1
      gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-CentOS-7
      EOF

      yum --disablerepo=\* --enablerepo=cdrom -y reinstall yum
      yum --disablerepo=\* --enablerepo=cdrom -y groupinstall "Minimal Install"

      rm -rf /mnt/cdrom /etc/yum.repos.d/cdrom.repo
    releases:
      - 7
```
From c057ba649f7f70c3fd10a627c2369f79d53e5f06 Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.h...@canonical.com>
Date: Wed, 28 Mar 2018 11:00:55 +0200
Subject: [PATCH 1/2] sources: Fix CentOS

Signed-off-by: Thomas Hipp <thomas.h...@canonical.com>
---
 sources/centos-http.go | 43 ++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 38 insertions(+), 5 deletions(-)

diff --git a/sources/centos-http.go b/sources/centos-http.go
index 43779ef..f94f28e 100644
--- a/sources/centos-http.go
+++ b/sources/centos-http.go
@@ -32,7 +32,7 @@ func (s *CentOSHTTP) Run(definition shared.Definition, 
rootfsDir string) error {
                strings.Split(definition.Image.Release, ".")[0],
                definition.Image.ArchitectureMapped)
 
-       s.fname = getRelease(definition.Source.URL, definition.Image.Release,
+       s.fname = s.getRelease(definition.Source.URL, definition.Image.Release,
                definition.Source.Variant, definition.Image.ArchitectureMapped)
        if s.fname == "" {
                return fmt.Errorf("Couldn't get name of iso")
@@ -76,6 +76,7 @@ func (s CentOSHTTP) unpack(filePath, rootfsDir string) error {
        tempRootDir := filepath.Join(os.TempDir(), "distrobuilder", "rootfs")
 
        os.MkdirAll(isoDir, 0755)
+       os.MkdirAll(squashfsDir, 0755)
        os.MkdirAll(tempRootDir, 0755)
        defer os.RemoveAll(filepath.Join(os.TempDir(), "distrobuilder"))
 
@@ -86,13 +87,15 @@ func (s CentOSHTTP) unpack(filePath, rootfsDir string) 
error {
        }
        defer syscall.Unmount(isoDir, 0)
 
-       err = shared.RunCommand("unsquashfs", "-d", squashfsDir,
-               filepath.Join(isoDir, "LiveOS/squashfs.img"))
+       err = shared.RunCommand("mount", filepath.Join(isoDir, "LiveOS",
+               "squashfs.img"), squashfsDir)
        if err != nil {
                return err
        }
+       defer syscall.Unmount(squashfsDir, 0)
 
-       err = shared.RunCommand("mount", filepath.Join(squashfsDir, "LiveOS", 
"rootfs.img"), tempRootDir)
+       err = shared.RunCommand("mount", filepath.Join(squashfsDir, "LiveOS",
+               "rootfs.img"), tempRootDir)
        if err != nil {
                return err
        }
@@ -110,10 +113,40 @@ func (s CentOSHTTP) unpack(filePath, rootfsDir string) 
error {
                return err
        }
 
+       // Create cdrom repo for yum
+       err = os.MkdirAll(filepath.Join(rootfsDir, "mnt", "cdrom"), 0755)
+       if err != nil {
+               return err
+       }
+
+       // Copy repo relevant files to the cdrom
+       err = shared.RunCommand("rsync", "-qa",
+               filepath.Join(isoDir, "Packages"),
+               filepath.Join(isoDir, "repodata"),
+               filepath.Join(rootfsDir, "mnt", "cdrom"))
+       if err != nil {
+               return err
+       }
+
+       // Find all relevant GPG keys
+       gpgKeys, err := filepath.Glob(filepath.Join(isoDir, "RPM-GPG-KEY-*"))
+       if err != nil {
+               return err
+       }
+
+       // Copy the keys to the cdrom
+       for _, key := range gpgKeys {
+               err = shared.RunCommand("rsync", "-qa", key,
+                       filepath.Join(rootfsDir, "mnt", "cdrom"))
+               if err != nil {
+                       return err
+               }
+       }
+
        return nil
 }
 
-func getRelease(URL, release, variant, arch string) string {
+func (s CentOSHTTP) getRelease(URL, release, variant, arch string) string {
        resp, err := http.Get(URL + path.Join("/", strings.Split(release, 
".")[0], "isos", arch))
        if err != nil {
                fmt.Fprintln(os.Stderr, err)

From 5555dd7c6e16ebec1491c0ea50054c6f1245bcae Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.h...@canonical.com>
Date: Wed, 28 Mar 2018 11:02:57 +0200
Subject: [PATCH 2/2] managers: Fix yum commands

Signed-off-by: Thomas Hipp <thomas.h...@canonical.com>
---
 managers/yum.go | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/managers/yum.go b/managers/yum.go
index 7ba2ced..0016107 100644
--- a/managers/yum.go
+++ b/managers/yum.go
@@ -6,7 +6,7 @@ func NewYum() *Manager {
                command: "yum",
                flags: ManagerFlags{
                        clean: []string{
-                               "clean",
+                               "clean", "all",
                        },
                        global: []string{
                                "-y",
@@ -18,10 +18,10 @@ func NewYum() *Manager {
                                "remove",
                        },
                        refresh: []string{
-                               "update",
+                               "makecache",
                        },
                        update: []string{
-                               "upgrade",
+                               "update",
                        },
                },
        }
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to