Add skip_create_image option to the openstack builder (#10496)

This commit is contained in:
fr123k 2021-01-19 10:43:18 +01:00 committed by GitHub
parent 490616a301
commit 056ac4a3ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 39 additions and 4 deletions

View File

@ -46,6 +46,7 @@ type FlatConfig struct {
ImageDiskFormat *string `mapstructure:"image_disk_format" required:"false" cty:"image_disk_format" hcl:"image_disk_format"` ImageDiskFormat *string `mapstructure:"image_disk_format" required:"false" cty:"image_disk_format" hcl:"image_disk_format"`
ImageTags []string `mapstructure:"image_tags" required:"false" cty:"image_tags" hcl:"image_tags"` ImageTags []string `mapstructure:"image_tags" required:"false" cty:"image_tags" hcl:"image_tags"`
ImageMinDisk *int `mapstructure:"image_min_disk" required:"false" cty:"image_min_disk" hcl:"image_min_disk"` ImageMinDisk *int `mapstructure:"image_min_disk" required:"false" cty:"image_min_disk" hcl:"image_min_disk"`
SkipCreateImage *bool `mapstructure:"skip_create_image" required:"false" cty:"skip_create_image" hcl:"skip_create_image"`
Type *string `mapstructure:"communicator" cty:"communicator" hcl:"communicator"` Type *string `mapstructure:"communicator" cty:"communicator" hcl:"communicator"`
PauseBeforeConnect *string `mapstructure:"pause_before_connecting" cty:"pause_before_connecting" hcl:"pause_before_connecting"` PauseBeforeConnect *string `mapstructure:"pause_before_connecting" cty:"pause_before_connecting" hcl:"pause_before_connecting"`
SSHHost *string `mapstructure:"ssh_host" cty:"ssh_host" hcl:"ssh_host"` SSHHost *string `mapstructure:"ssh_host" cty:"ssh_host" hcl:"ssh_host"`
@ -177,6 +178,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec {
"image_disk_format": &hcldec.AttrSpec{Name: "image_disk_format", Type: cty.String, Required: false}, "image_disk_format": &hcldec.AttrSpec{Name: "image_disk_format", Type: cty.String, Required: false},
"image_tags": &hcldec.AttrSpec{Name: "image_tags", Type: cty.List(cty.String), Required: false}, "image_tags": &hcldec.AttrSpec{Name: "image_tags", Type: cty.List(cty.String), Required: false},
"image_min_disk": &hcldec.AttrSpec{Name: "image_min_disk", Type: cty.Number, Required: false}, "image_min_disk": &hcldec.AttrSpec{Name: "image_min_disk", Type: cty.Number, Required: false},
"skip_create_image": &hcldec.AttrSpec{Name: "skip_create_image", Type: cty.Bool, Required: false},
"communicator": &hcldec.AttrSpec{Name: "communicator", Type: cty.String, Required: false}, "communicator": &hcldec.AttrSpec{Name: "communicator", Type: cty.String, Required: false},
"pause_before_connecting": &hcldec.AttrSpec{Name: "pause_before_connecting", Type: cty.String, Required: false}, "pause_before_connecting": &hcldec.AttrSpec{Name: "pause_before_connecting", Type: cty.String, Required: false},
"ssh_host": &hcldec.AttrSpec{Name: "ssh_host", Type: cty.String, Required: false}, "ssh_host": &hcldec.AttrSpec{Name: "ssh_host", Type: cty.String, Required: false},

View File

@ -33,6 +33,8 @@ type ImageConfig struct {
ImageTags []string `mapstructure:"image_tags" required:"false"` ImageTags []string `mapstructure:"image_tags" required:"false"`
// Minimum disk size needed to boot image, in gigabytes. // Minimum disk size needed to boot image, in gigabytes.
ImageMinDisk int `mapstructure:"image_min_disk" required:"false"` ImageMinDisk int `mapstructure:"image_min_disk" required:"false"`
// Skip creating the image. Useful for setting to `true` during a build test stage. Defaults to `false`.
SkipCreateImage bool `mapstructure:"skip_create_image" required:"false"`
} }
func (c *ImageConfig) Prepare(ctx *interpolate.Context) []error { func (c *ImageConfig) Prepare(ctx *interpolate.Context) []error {

View File

@ -12,10 +12,16 @@ import (
type stepAddImageMembers struct{} type stepAddImageMembers struct{}
func (s *stepAddImageMembers) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction { func (s *stepAddImageMembers) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
imageId := state.Get("image").(string)
ui := state.Get("ui").(packersdk.Ui) ui := state.Get("ui").(packersdk.Ui)
config := state.Get("config").(*Config) config := state.Get("config").(*Config)
if config.SkipCreateImage {
ui.Say("Skipping image add members...")
return multistep.ActionContinue
}
imageId := state.Get("image").(string)
if len(config.ImageMembers) == 0 { if len(config.ImageMembers) == 0 {
return multistep.ActionContinue return multistep.ActionContinue
} }

View File

@ -24,6 +24,11 @@ func (s *stepCreateImage) Run(ctx context.Context, state multistep.StateBag) mul
server := state.Get("server").(*servers.Server) server := state.Get("server").(*servers.Server)
ui := state.Get("ui").(packersdk.Ui) ui := state.Get("ui").(packersdk.Ui)
if config.SkipCreateImage {
ui.Say("Skipping image creation...")
return multistep.ActionContinue
}
// We need the v2 compute client // We need the v2 compute client
computeClient, err := config.computeV2Client() computeClient, err := config.computeV2Client()
if err != nil { if err != nil {

View File

@ -12,10 +12,16 @@ import (
type stepUpdateImageMinDisk struct{} type stepUpdateImageMinDisk struct{}
func (s *stepUpdateImageMinDisk) Run(_ context.Context, state multistep.StateBag) multistep.StepAction { func (s *stepUpdateImageMinDisk) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
imageId := state.Get("image").(string)
ui := state.Get("ui").(packersdk.Ui) ui := state.Get("ui").(packersdk.Ui)
config := state.Get("config").(*Config) config := state.Get("config").(*Config)
if config.SkipCreateImage {
ui.Say("Skipping image update mindisk...")
return multistep.ActionContinue
}
imageId := state.Get("image").(string)
if config.ImageMinDisk == 0 { if config.ImageMinDisk == 0 {
return multistep.ActionContinue return multistep.ActionContinue
} }

View File

@ -13,10 +13,16 @@ import (
type stepUpdateImageTags struct{} type stepUpdateImageTags struct{}
func (s *stepUpdateImageTags) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction { func (s *stepUpdateImageTags) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
imageId := state.Get("image").(string)
ui := state.Get("ui").(packersdk.Ui) ui := state.Get("ui").(packersdk.Ui)
config := state.Get("config").(*Config) config := state.Get("config").(*Config)
if config.SkipCreateImage {
ui.Say("Skipping image update tags...")
return multistep.ActionContinue
}
imageId := state.Get("image").(string)
if len(config.ImageTags) == 0 { if len(config.ImageTags) == 0 {
return multistep.ActionContinue return multistep.ActionContinue
} }

View File

@ -12,10 +12,16 @@ import (
type stepUpdateImageVisibility struct{} type stepUpdateImageVisibility struct{}
func (s *stepUpdateImageVisibility) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction { func (s *stepUpdateImageVisibility) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
imageId := state.Get("image").(string)
ui := state.Get("ui").(packersdk.Ui) ui := state.Get("ui").(packersdk.Ui)
config := state.Get("config").(*Config) config := state.Get("config").(*Config)
if config.SkipCreateImage {
ui.Say("Skipping image update visibility...")
return multistep.ActionContinue
}
imageId := state.Get("image").(string)
if config.ImageVisibility == "" { if config.ImageVisibility == "" {
return multistep.ActionContinue return multistep.ActionContinue
} }

View File

@ -18,3 +18,5 @@
- `image_tags` ([]string) - List of tags to add to the image after creation. - `image_tags` ([]string) - List of tags to add to the image after creation.
- `image_min_disk` (int) - Minimum disk size needed to boot image, in gigabytes. - `image_min_disk` (int) - Minimum disk size needed to boot image, in gigabytes.
- `skip_create_image` (bool) - Skip creating the image. Useful for setting to `true` during a build test stage. Defaults to `false`.