Skip to content

Commit

Permalink
Add --name flag to image build
Browse files Browse the repository at this point in the history
This lets the user set the name of the provisioning VM. This is useful
in case the image name would create an invalid DNS label for the VM.
  • Loading branch information
WanzenBug committed Jul 20, 2021
1 parent 28ac9ca commit 5ef47e5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
9 changes: 8 additions & 1 deletion cmd/image_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

func imageBuildCommand() *cobra.Command {
var vmID uint
var vmName string
var provisionFile string
var provisionOverrides []string

Expand Down Expand Up @@ -57,6 +58,10 @@ func imageBuildCommand() *cobra.Command {
baseImageName := args[0]
newImageName := LocalImageName(args[1])

if vmName == "" {
vmName = newImageName
}

ctx, cancel := onInterruptWrap(context.Background())
defer cancel()

Expand Down Expand Up @@ -152,7 +157,7 @@ func imageBuildCommand() *cobra.Command {

vmConfig := virter.VMConfig{
Image: baseImage,
Name: newImageName,
Name: vmName,
MemoryKiB: memKiB,
BootCapacityKiB: bootCapacityKiB,
VCPUs: vcpus,
Expand All @@ -179,6 +184,7 @@ func imageBuildCommand() *cobra.Command {
}

buildConfig := virter.ImageBuildConfig{
ImageName: newImageName,
ContainerName: containerName,
ShutdownTimeout: shutdownTimeout,
ProvisionConfig: provisionConfig,
Expand Down Expand Up @@ -224,6 +230,7 @@ func imageBuildCommand() *cobra.Command {
buildCmd.Flags().StringVarP(&provisionFile, "provision", "p", "", "name of toml file containing provisioning steps")
buildCmd.Flags().StringArrayVarP(&provisionOverrides, "set", "s", []string{}, "set/override provisioning steps")
buildCmd.Flags().UintVarP(&vmID, "id", "", 0, "ID for VM which determines the IP address")
buildCmd.Flags().StringVarP(&vmName, "name", "", "", "Name to use for provisioning VM")
buildCmd.Flags().UintVar(&vcpus, "vcpus", 1, "Number of virtual CPUs to allocate for the VM")
u := unit.MustNewUnit(sizeUnits)
mem = u.MustNewValue(1*sizeUnits["G"], unit.None)
Expand Down
3 changes: 2 additions & 1 deletion internal/virter/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ type ImageBuildTools struct {

// ImageBuildConfig contains the configuration for building an image
type ImageBuildConfig struct {
ImageName string
ContainerName string
ShutdownTimeout time.Duration
ProvisionConfig ProvisionConfig
Expand Down Expand Up @@ -578,7 +579,7 @@ func (v *Virter) imageBuildProvisionCommit(ctx context.Context, tools ImageBuild
}
}

err = v.VMCommit(ctx, tools.AfterNotifier, vmConfig.Name, vmConfig.Name, true, buildConfig.ShutdownTimeout, vmConfig.StaticDHCP, opts...)
err = v.VMCommit(ctx, tools.AfterNotifier, vmConfig.Name, buildConfig.ImageName, true, buildConfig.ShutdownTimeout, vmConfig.StaticDHCP, opts...)
if err != nil {
return err
}
Expand Down

0 comments on commit 5ef47e5

Please sign in to comment.