add support for using xorriso to create the cdrom iso (#9919)

This commit is contained in:
Rui Lopes 2020-09-11 19:11:19 +01:00 committed by GitHub
parent bcd3c33e49
commit 53331644a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 89 additions and 32 deletions

View File

@ -57,12 +57,13 @@ type CDConfig struct {
// directory itself or its contents will be at the CD root.
//
// Use of this option assumes that you have a command line tool installed
// that can handle the iso creation. If you are running Packer from an OSX host,
// the required tool is hdiutil which comes preinstalled.
// On linux hosts, you need to have mkisofs.
// On Windows, you must have oscdimg.exe. oscdimg.exe is part of the
// Windows ADK tooks, downloadable from
// https://docs.microsoft.com/en-us/windows-hardware/get-started/adk-install#winADK
// that can handle the iso creation. Packer will use one of the following
// tools:
//
// * xorriso
// * mkisofs
// * hdiutil (normally found in macOS)
// * oscdimg (normally found in Windows as part of the Windows ADK)
CDFiles []string `mapstructure:"cd_files"`
CDLabel string `mapstructure:"cd_label"`
}

View File

@ -8,7 +8,7 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"github.com/hashicorp/packer/helper/builder/localexec"
"github.com/hashicorp/packer/helper/multistep"
@ -80,7 +80,12 @@ func (s *StepCreateCD) Run(ctx context.Context, state multistep.StateBag) multis
}
}
cmd := retrieveCommandForOS(s.Label, rootFolder, CDPath)
cmd, err := retrieveCDISOCreationCommand(s.Label, rootFolder, CDPath)
if err != nil {
state.Put("error", err)
return multistep.ActionHalt
}
err = localexec.RunAndStream(cmd, ui, []string{})
if err != nil {
state.Put("error", err)
@ -107,25 +112,75 @@ func (s *StepCreateCD) Cleanup(multistep.StateBag) {
}
}
func retrieveCommandForOS(label string, source string, dest string) *exec.Cmd {
switch runtime.GOOS {
case "windows":
cmd := exec.Command("oscdimg")
args := []string{"-j1", "-o", "-m", "-l" + label, source, dest}
cmd.Args = append(cmd.Args, args...)
return cmd
case "darwin":
cmd := exec.Command("hdiutil")
args := []string{"makehybrid", "-o", dest, "-hfs",
"-joliet", "-iso", "-default-volume-name", label, source}
cmd.Args = append(cmd.Args, args...)
return cmd
default:
cmd := exec.Command("mkisofs")
args := []string{"-joliet", "-volid", label, "-o", dest, source}
cmd.Args = append(cmd.Args, args...)
return cmd
type cdISOCreationCommand struct {
Name string
Command func(path string, label string, source string, dest string) *exec.Cmd
}
var supportedCDISOCreationCommands []cdISOCreationCommand = []cdISOCreationCommand{
{
"xorriso", func(path string, label string, source string, dest string) *exec.Cmd {
return exec.Command(
path,
"-as", "genisoimage",
"-rock",
"-joliet",
"-volid", label,
"-output", dest,
source)
},
},
{
"mkisofs", func(path string, label string, source string, dest string) *exec.Cmd {
return exec.Command(
path,
"-joliet",
"-volid", label,
"-o", dest,
source)
},
},
{
"hdiutil", func(path string, label string, source string, dest string) *exec.Cmd {
return exec.Command(
path,
"-o", dest,
"-hfs",
"-joliet",
"-iso",
"-default-volume-name", label,
source)
},
},
{
"oscdimg", func(path string, label string, source string, dest string) *exec.Cmd {
return exec.Command(
path,
"-j1",
"-o",
"-m",
"-l"+label,
source,
dest)
},
},
}
func retrieveCDISOCreationCommand(label string, source string, dest string) (*exec.Cmd, error) {
for _, c := range supportedCDISOCreationCommands {
path, err := exec.LookPath(c.Name)
if err != nil {
continue
}
return c.Command(path, label, source, dest), nil
}
var commands = make([]string, 0, len(supportedCDISOCreationCommands))
for _, c := range supportedCDISOCreationCommands {
commands = append(commands, c.Name)
}
return nil, fmt.Errorf(
"could not find a supported CD ISO creation command (the supported commands are: %s)",
strings.Join(commands, ", "))
}
func (s *StepCreateCD) AddFile(dst, src string) error {

View File

@ -36,11 +36,12 @@
directory itself or its contents will be at the CD root.
Use of this option assumes that you have a command line tool installed
that can handle the iso creation. If you are running Packer from an OSX host,
the required tool is hdiutil which comes preinstalled.
On linux hosts, you need to have mkisofs.
On Windows, you must have oscdimg.exe. oscdimg.exe is part of the
Windows ADK tooks, downloadable from
https://docs.microsoft.com/en-us/windows-hardware/get-started/adk-install#winADK
that can handle the iso creation. Packer will use one of the following
tools:
* xorriso
* mkisofs
* hdiutil (normally found in macOS)
* oscdimg (normally found in Windows as part of the Windows ADK)
- `cd_label` (string) - CD Label