Skip to content

Commit e75c6ee

Browse files
Merge pull request #103 from IBM/skipReboot
Skip Reboot Development
2 parents 3dc67d4 + e427e9f commit e75c6ee

File tree

6 files changed

+109
-27
lines changed

6 files changed

+109
-27
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ resource_group_name | string | Optional | The resource group name to use. If not
191191
| |
192192
ssh_key_type | string | Optional | The type of ssh key to use(`rsa`/`ed25519`). If not specified, IBM packer plugin uses `rsa` type as default.
193193
| |
194+
skip_reboot | bool | Optional | Skip reboot instance step. If not specified, IBM packer plugin uses `false` as default.
195+
| |
194196
vsi_base_image_id | string | Required | The base image identifier used to created the VSI. Use `ibmcloud is images` for available options.
195197
| OR |
196198
vsi_base_image_name | string | Required | The base image name used to created the VSI. Use `ibmcloud is images` for available options.

builder/ibmcloud/vpc/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ type Config struct {
6363
StorageBucketName string `mapstructure:"storage_bucket_name"`
6464
StorageBucketCRN string `mapstructure:"storage_bucket_crn"`
6565
//The format to use for the exported image. If the image is encrypted, only qcow2 is supported.
66-
Format string `mapstructure:"format"`
66+
Format string `mapstructure:"format"`
67+
SkipReboot bool `mapstructure:"skip_reboot"`
6768
}
6869

6970
// Prepare processes the build configuration parameters.

builder/ibmcloud/vpc/config.hcl2spec.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

builder/ibmcloud/vpc/step_reboot_instance.go

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,42 +16,45 @@ func (s *stepRebootInstance) Run(_ context.Context, state multistep.StateBag) mu
1616
config := state.Get("config").(Config)
1717
ui := state.Get("ui").(packer.Ui)
1818

19-
ui.Say("Rebooting instance to cleanly complete any installed software components...")
20-
21-
instanceData := state.Get("instance_data").(*vpcv1.Instance)
22-
instanceID := *instanceData.ID
23-
24-
status, err := client.manageInstance(instanceID, "reboot", state)
25-
if err != nil {
26-
err := fmt.Errorf("[ERROR] Error rebooting the instance: %s", err)
27-
state.Put("error", err)
28-
ui.Error(err.Error())
29-
// log.Fatalf(err.Error())
30-
return multistep.ActionHalt
31-
}
19+
if config.SkipReboot {
20+
ui.Say("Rebooting instance to cleanly complete any installed software components...")
21+
22+
instanceData := state.Get("instance_data").(*vpcv1.Instance)
23+
instanceID := *instanceData.ID
3224

33-
if status != "running" {
34-
err := client.waitForResourceReady(instanceID, "instances", config.StateTimeout, state)
25+
status, err := client.manageInstance(instanceID, "reboot", state)
3526
if err != nil {
3627
err := fmt.Errorf("[ERROR] Error rebooting the instance: %s", err)
3728
state.Put("error", err)
3829
ui.Error(err.Error())
3930
// log.Fatalf(err.Error())
4031
return multistep.ActionHalt
4132
}
42-
}
4333

44-
newInstanceData, err := client.retrieveResource(instanceID, state)
45-
if err != nil {
46-
err := fmt.Errorf("[ERROR] Error updating the instance: %s", err)
47-
state.Put("error", err)
48-
ui.Error(err.Error())
49-
// log.Fatalf(err.Error())
50-
return multistep.ActionHalt
51-
}
52-
state.Put("instance_data", newInstanceData)
34+
if status != "running" {
35+
err := client.waitForResourceReady(instanceID, "instances", config.StateTimeout, state)
36+
if err != nil {
37+
err := fmt.Errorf("[ERROR] Error rebooting the instance: %s", err)
38+
state.Put("error", err)
39+
ui.Error(err.Error())
40+
// log.Fatalf(err.Error())
41+
return multistep.ActionHalt
42+
}
43+
}
5344

54-
ui.Say("Instance is ACTIVE!")
45+
newInstanceData, err := client.retrieveResource(instanceID, state)
46+
if err != nil {
47+
err := fmt.Errorf("[ERROR] Error updating the instance: %s", err)
48+
state.Put("error", err)
49+
ui.Error(err.Error())
50+
// log.Fatalf(err.Error())
51+
return multistep.ActionHalt
52+
}
53+
state.Put("instance_data", newInstanceData)
54+
55+
ui.Say("Instance is ACTIVE!")
56+
return multistep.ActionContinue
57+
}
5558
return multistep.ActionContinue
5659
}
5760

developer/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,7 @@ run-zprofile:
9090
run-rhel-post-processor:
9191
cd ..; packer validate -var-file="developer/variables.pkrvars.hcl" developer/examples/postprocessor.vpc.rhel.pkr.hcl
9292
cd ..; packer build -var-file="developer/variables.pkrvars.hcl" developer/examples/postprocessor.vpc.rhel.pkr.hcl
93+
94+
run-rhel-skip-reboot:
95+
cd ..; packer validate -var-file="developer/variables.pkrvars.hcl" developer/examples/build.vpc.rhel.pkr.hcl
96+
cd ..; packer build -var-file="developer/variables.pkrvars.hcl" developer/examples/build.vpc.rhel.skip.reboot.pkr.hcl
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// packer {
2+
// required_plugins {
3+
// ibmcloud = {
4+
// version = ">=v3.0.0"
5+
// source = "github.com/IBM/ibmcloud"
6+
// }
7+
// }
8+
// }
9+
10+
variable "IBM_API_KEY" {
11+
type = string
12+
}
13+
14+
variable "SUBNET_ID" {
15+
type = string
16+
}
17+
18+
variable "REGION" {
19+
type = string
20+
}
21+
22+
variable "RESOURCE_GROUP_ID" {
23+
type = string
24+
}
25+
26+
variable "SECURITY_GROUP_ID" {
27+
type = string
28+
}
29+
30+
31+
locals {
32+
timestamp = regex_replace(timestamp(), "[- TZ:]", "")
33+
}
34+
35+
source "ibmcloud-vpc" "rhel" {
36+
api_key = var.IBM_API_KEY
37+
region = var.REGION
38+
39+
subnet_id = var.SUBNET_ID
40+
resource_group_id = var.RESOURCE_GROUP_ID
41+
security_group_id = var.SECURITY_GROUP_ID
42+
43+
vsi_base_image_name = "ibm-redhat-8-4-minimal-amd64-3"
44+
vsi_profile = "bx2-4x16"
45+
vsi_interface = "public"
46+
vsi_user_data_file = ""
47+
48+
image_name = "packer-${local.timestamp}"
49+
50+
communicator = "ssh"
51+
ssh_username = "root"
52+
ssh_port = 22
53+
ssh_timeout = "15m"
54+
skip_reboot = true
55+
timeout = "30m"
56+
}
57+
58+
build {
59+
sources = [
60+
"source.ibmcloud-vpc.rhel"
61+
]
62+
63+
provisioner "shell" {
64+
execute_command = "{{.Vars}} bash '{{.Path}}'"
65+
inline = [
66+
"echo 'Hello from IBM Cloud Packer Plugin - VPC Infrastructure'",
67+
"echo 'Hello from IBM Cloud Packer Plugin - VPC Infrastructure' >> /hello.txt"
68+
]
69+
}
70+
}

0 commit comments

Comments
 (0)