Skip to content

Commit 43d9e11

Browse files
committed
chore: add redeploy:az and redeploy:gcp commands
1 parent 5ce68aa commit 43d9e11

File tree

4 files changed

+148
-65
lines changed

4 files changed

+148
-65
lines changed

packages/images/.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,6 @@ cli.bundle.js
3232
.dynv6_api_key
3333
.dynv6_azure_name
3434
.dynv6_gcp_name
35-
.dynv6_gcp_zone
35+
.dynv6_gcp_zone
36+
.vm_name_gcp
37+
.vm_name_azure

packages/images/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
"deploy:az:devtools": "bash scripts/deploy_azure.sh build/kettle-vm-devtools.vhd",
2525
"deploy:gcp": "bash scripts/deploy_gcp.sh build/kettle-vm.tar.gz",
2626
"deploy:gcp:devtools": "bash scripts/deploy_gcp.sh build/kettle-vm-devtools.tar.gz",
27+
"redeploy:az": "bash scripts/redeploy_azure.sh build/kettle-vm-azure.vhd",
28+
"redeploy:az:devtools": "bash scripts/redeploy_azure.sh build/kettle-vm-devtools.vhd",
29+
"redeploy:gcp": "bash scripts/redeploy_gcp.sh build/kettle-vm.tar.gz",
30+
"redeploy:gcp:devtools": "bash scripts/redeploy_gcp.sh build/kettle-vm-devtools.tar.gz",
2731
"ls:az": "bash scripts/ls_azure.sh",
2832
"ls:gcp": "bash scripts/ls_gcp.sh",
2933
"config:az": "bash scripts/config_azure.sh",

packages/images/scripts/redeploy_azure.sh

Lines changed: 58 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/bin/bash
22
#
33
# Redeploys an existing Azure VM with a new image while preserving its IP address and metadata.
4-
# Usage: ./redeploy_azure.sh <vm-name> <vhd-file>
4+
#
5+
# Usage: ./redeploy_azure.sh <vhd-file> [vm-name] [--dry-run]
56
#
67
# The script will:
78
# 1. Capture the existing VM's configuration (IP, NIC, NSG, tags, size, etc.)
@@ -14,11 +15,16 @@
1415
# - Resource group 'tdx-group' exists
1516
# - The VM to redeploy exists
1617
#
18+
# Arguments:
19+
# vhd-file Path to the VHD file (or .vhd.tar.gz) to deploy (required)
20+
# vm-name Name of the existing VM to redeploy (optional, uses cache or prompts)
21+
# --dry-run Show what would be done without making changes
22+
#
1723
# Examples:
18-
# ./redeploy_azure.sh my-vm build/kettle-vm-azure.vhd
19-
# ./redeploy_azure.sh my-vm build/kettle-vm-azure.vhd.tar.gz
20-
# ./redeploy_azure.sh my-vm build/kettle-vm-azure.vhd --dry-run
21-
# ./redeploy_azure.sh my-vm build/kettle-vm-azure.vhd --yes
24+
# ./redeploy_azure.sh build/kettle-vm-azure.vhd # Prompts for VM name
25+
# ./redeploy_azure.sh build/kettle-vm-azure.vhd my-vm
26+
# ./redeploy_azure.sh build/kettle-vm-azure.vhd.tar.gz my-vm
27+
# ./redeploy_azure.sh build/kettle-vm-azure.vhd --dry-run # Uses cached VM name
2228
#
2329

2430
set -euo pipefail
@@ -29,6 +35,7 @@ GALLERY_NAME="tdxGallery"
2935
IMAGE_DEFINITION="kettle-vm-azure"
3036
CONTAINER_NAME="vhds"
3137
VM_SIZE="Standard_DC2es_v5"
38+
VM_NAME_CACHE_FILE=".vm_name_azure"
3239

3340
# Generate a random integer for image version patch number (1 to 2,000,000,000)
3441
IMAGE_PATCH_VERSION=$((1 + RANDOM * RANDOM % 2000000000))
@@ -85,35 +92,48 @@ cleanup_on_failure() {
8592
exit 1
8693
}
8794

88-
# Validate arguments
89-
if [ $# -lt 2 ]; then
90-
echo "Usage: $0 <vm-name> <vhd-file>"
95+
# Validate arguments - need at least the VHD file
96+
if [ $# -lt 1 ]; then
97+
echo "Usage: $0 <vhd-file> [vm-name] [--dry-run]"
9198
echo ""
9299
echo "Arguments:"
93-
echo " vm-name Name of the existing VM to redeploy"
94-
echo " vhd-file Path to the VHD file (or .vhd.tar.gz) to deploy"
100+
echo " vhd-file Path to the VHD file (or .vhd.tar.gz) to deploy (required)"
101+
echo " vm-name Name of the existing VM to redeploy (optional, uses cache or prompts)"
95102
echo ""
96103
echo "Options:"
97104
echo " --dry-run Show what would be done without making changes"
98105
echo ""
99106
echo "Examples:"
100-
echo " $0 my-vm build/kettle-vm-azure.vhd"
101-
echo " $0 my-vm build/kettle-vm-azure.vhd.tar.gz"
102-
echo " $0 my-vm build/kettle-vm-azure.vhd --dry-run"
107+
echo " $0 build/kettle-vm-azure.vhd # Prompts for VM name"
108+
echo " $0 build/kettle-vm-azure.vhd my-vm"
109+
echo " $0 build/kettle-vm-azure.vhd.tar.gz my-vm"
110+
echo " $0 build/kettle-vm-azure.vhd --dry-run # Uses cached VM name"
103111
exit 1
104112
fi
105113

106-
VM_NAME="$1"
107-
VHD_INPUT="$2"
114+
# First argument must be the VHD file
115+
VHD_INPUT="$1"
116+
shift
108117

109-
# Parse optional arguments
118+
# Initialize defaults
119+
VM_NAME=""
110120
DRY_RUN=false
111-
shift 2
121+
122+
# Parse remaining arguments
112123
for arg in "$@"; do
113124
case "$arg" in
114125
--dry-run)
115126
DRY_RUN=true
116127
;;
128+
*)
129+
# Assume it's the VM name if not recognized as an option
130+
if [ -z "$VM_NAME" ]; then
131+
VM_NAME="$arg"
132+
else
133+
log_error "Unknown argument: $arg"
134+
exit 1
135+
fi
136+
;;
117137
esac
118138
done
119139

@@ -147,6 +167,23 @@ if [ ! -f "$VHD_FILE" ]; then
147167
exit 1
148168
fi
149169

170+
# Handle VM name: use provided, cached, or prompt
171+
if [ -z "$VM_NAME" ]; then
172+
# Try to read from cache
173+
if [ -f "$VM_NAME_CACHE_FILE" ]; then
174+
VM_NAME=$(cat "$VM_NAME_CACHE_FILE")
175+
log_info "Using cached VM name: $VM_NAME"
176+
else
177+
# No cache, prompt for VM name
178+
echo -n "Enter the VM name to redeploy: "
179+
read -r VM_NAME
180+
if [ -z "$VM_NAME" ]; then
181+
log_error "VM name is required"
182+
exit 1
183+
fi
184+
fi
185+
fi
186+
150187
# Generate unique identifiers for this deployment
151188
DEPLOY_HASH=$(openssl rand -hex 4)
152189
VHD_BASENAME=$(basename "$VHD_FILE")
@@ -677,3 +714,7 @@ echo "Cleanup commands (for the new image resources, if needed):"
677714
echo " az sig image-version delete -g $RESOURCE_GROUP -r $GALLERY_NAME -i $IMAGE_DEFINITION -e $IMAGE_VERSION"
678715
echo " az storage blob delete -n $BLOB_NAME -c $CONTAINER_NAME --account-name $STORAGE_ACCT --auth-mode login"
679716
echo ""
717+
718+
# Cache the VM name for future redeployments
719+
echo "$VM_NAME" > "$VM_NAME_CACHE_FILE"
720+
log_info "Cached VM name '$VM_NAME' for future redeployments"

packages/images/scripts/redeploy_gcp.sh

Lines changed: 83 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/bin/bash
22
#
33
# Redeploys an existing GCP VM with a new image while preserving its IP address and metadata.
4-
# Usage: ./redeploy_gcp.sh --tdx|--sev-snp <vm-name> <tar.gz-file>
4+
#
5+
# Usage: ./redeploy_gcp.sh <tar.gz-file> [--tdx|--sev-snp] [vm-name] [--zone=ZONE] [--dry-run]
56
#
67
# The script will:
78
# 1. Capture the existing VM's configuration (IP, metadata, machine type, etc.)
@@ -14,11 +15,20 @@
1415
# - A GCP project selected (gcloud config set project <project>)
1516
# - The VM to redeploy exists
1617
#
18+
# Arguments:
19+
# tar.gz-file Path to the tar.gz file to deploy (required)
20+
# --tdx Deploy to Intel TDX machine (default)
21+
# --sev-snp Deploy to AMD SEV-SNP machine
22+
# vm-name Name of the VM to redeploy (optional, uses cache or prompts)
23+
# --zone=ZONE Zone where the VM is located (default: us-central1-a)
24+
# --dry-run Show what would be done without making changes
25+
#
1726
# Examples:
18-
# ./redeploy_gcp.sh --tdx gcp-tdx-demo build/kettle-vm.tar.gz
19-
# ./redeploy_gcp.sh --tdx gcp-tdx-demo build/kettle-vm-devtools.tar.gz
20-
# ./redeploy_gcp.sh --sev-snp gcp-sev-demo build/kettle-vm.tar.gz
21-
# ./redeploy_gcp.sh --tdx gcp-tdx-demo build/kettle-vm.tar.gz --dry-run
27+
# ./redeploy_gcp.sh build/kettle-vm.tar.gz # Prompts for VM name
28+
# ./redeploy_gcp.sh build/kettle-vm.tar.gz my-vm # TDX by default
29+
# ./redeploy_gcp.sh build/kettle-vm.tar.gz --tdx my-vm
30+
# ./redeploy_gcp.sh build/kettle-vm.tar.gz --sev-snp my-vm
31+
# ./redeploy_gcp.sh build/kettle-vm.tar.gz --dry-run # Uses cached VM name
2232
#
2333

2434
set -euo pipefail
@@ -27,6 +37,7 @@ set -euo pipefail
2737
BUCKET_NAME="" # Will be set based on project ID
2838
REGION="us-central1"
2939
DEFAULT_ZONE="us-central1-a"
40+
VM_NAME_CACHE_FILE=".vm_name_gcp"
3041

3142
# Colors for logging
3243
RED='\033[0;31m'
@@ -88,71 +99,75 @@ cleanup_on_failure() {
8899
exit 1
89100
}
90101

91-
# Validate arguments
92-
if [ $# -lt 3 ]; then
93-
echo "Usage: $0 --tdx|--sev-snp <vm-name> <tar.gz-file> [--zone=ZONE]"
94-
echo ""
95-
echo "Required first argument (TEE type):"
96-
echo " --tdx Deploy to Intel TDX machine (c3-standard-4)"
97-
echo " --sev-snp Deploy to AMD SEV-SNP machine (n2d-standard-2)"
102+
# Validate arguments - need at least the tar.gz file
103+
if [ $# -lt 1 ]; then
104+
echo "Usage: $0 <tar.gz-file> [--tdx|--sev-snp] [vm-name] [--zone=ZONE] [--dry-run]"
98105
echo ""
99106
echo "Arguments:"
100-
echo " vm-name Name of the existing VM to redeploy"
101-
echo " tar.gz-file Path to the tar.gz file to deploy"
107+
echo " tar.gz-file Path to the tar.gz file to deploy (required)"
102108
echo ""
103109
echo "Options:"
110+
echo " --tdx Deploy to Intel TDX machine (default)"
111+
echo " --sev-snp Deploy to AMD SEV-SNP machine"
112+
echo " vm-name Name of the existing VM to redeploy (uses cache or prompts if omitted)"
104113
echo " --zone=ZONE Zone where the VM is located (default: $DEFAULT_ZONE)"
105114
echo " --dry-run Show what would be done without making changes"
106115
echo ""
107116
echo "Examples:"
108-
echo " $0 --tdx gcp-tdx-demo build/kettle-vm.tar.gz"
109-
echo " $0 --tdx gcp-tdx-demo build/kettle-vm.tar.gz --zone=us-central1-b"
110-
echo " $0 --sev-snp gcp-sev-demo build/kettle-vm.tar.gz"
111-
echo " $0 --sev-snp gcp-sev-demo build/kettle-vm.tar.gz --dry-run"
117+
echo " $0 build/kettle-vm.tar.gz # Prompts for VM name"
118+
echo " $0 build/kettle-vm.tar.gz my-vm # TDX by default"
119+
echo " $0 build/kettle-vm.tar.gz --tdx my-vm"
120+
echo " $0 build/kettle-vm.tar.gz --sev-snp my-vm"
121+
echo " $0 build/kettle-vm.tar.gz --dry-run # Uses cached VM name"
112122
exit 1
113123
fi
114124

115-
# Parse required TEE type argument
116-
TEE_TYPE=""
117-
case "$1" in
118-
--tdx)
119-
TEE_TYPE="tdx"
120-
CONFIDENTIAL_TYPE="TDX"
121-
NEW_MACHINE_TYPE="c3-standard-4"
122-
IMAGE_OS_FEATURES="UEFI_COMPATIBLE,VIRTIO_SCSI_MULTIQUEUE,GVNIC,TDX_CAPABLE"
123-
VM_TAG="tdx-vm"
124-
;;
125-
--sev-snp)
126-
TEE_TYPE="sev-snp"
127-
CONFIDENTIAL_TYPE="SEV_SNP"
128-
NEW_MACHINE_TYPE="n2d-standard-2"
129-
IMAGE_OS_FEATURES="UEFI_COMPATIBLE,VIRTIO_SCSI_MULTIQUEUE,GVNIC,SEV_SNP_CAPABLE"
130-
VM_TAG="sev-snp-vm"
131-
;;
132-
*)
133-
echo "Error: First argument must be --tdx or --sev-snp"
134-
echo ""
135-
echo "Usage: $0 --tdx|--sev-snp <vm-name> <tar.gz-file> [options]"
136-
exit 1
137-
;;
138-
esac
125+
# First argument must be the tar.gz file
126+
TAR_FILE="$1"
139127
shift
140128

141-
VM_NAME="$1"
142-
TAR_FILE="$2"
129+
# Initialize defaults
130+
TEE_TYPE="tdx"
131+
CONFIDENTIAL_TYPE="TDX"
132+
NEW_MACHINE_TYPE="c3-standard-4"
133+
IMAGE_OS_FEATURES="UEFI_COMPATIBLE,VIRTIO_SCSI_MULTIQUEUE,GVNIC,TDX_CAPABLE"
134+
VM_TAG="tdx-vm"
135+
VM_NAME=""
143136
VM_ZONE="$DEFAULT_ZONE"
144-
145-
# Parse optional arguments
146137
DRY_RUN=false
147-
shift 2
138+
139+
# Parse remaining arguments
148140
for arg in "$@"; do
149141
case "$arg" in
142+
--tdx)
143+
TEE_TYPE="tdx"
144+
CONFIDENTIAL_TYPE="TDX"
145+
NEW_MACHINE_TYPE="c3-standard-4"
146+
IMAGE_OS_FEATURES="UEFI_COMPATIBLE,VIRTIO_SCSI_MULTIQUEUE,GVNIC,TDX_CAPABLE"
147+
VM_TAG="tdx-vm"
148+
;;
149+
--sev-snp)
150+
TEE_TYPE="sev-snp"
151+
CONFIDENTIAL_TYPE="SEV_SNP"
152+
NEW_MACHINE_TYPE="n2d-standard-2"
153+
IMAGE_OS_FEATURES="UEFI_COMPATIBLE,VIRTIO_SCSI_MULTIQUEUE,GVNIC,SEV_SNP_CAPABLE"
154+
VM_TAG="sev-snp-vm"
155+
;;
150156
--zone=*)
151157
VM_ZONE="${arg#*=}"
152158
;;
153159
--dry-run)
154160
DRY_RUN=true
155161
;;
162+
*)
163+
# Assume it's the VM name if not recognized as an option
164+
if [ -z "$VM_NAME" ]; then
165+
VM_NAME="$arg"
166+
else
167+
log_error "Unknown argument: $arg"
168+
exit 1
169+
fi
170+
;;
156171
esac
157172
done
158173

@@ -166,6 +181,23 @@ if [ ! -f "$TAR_FILE" ]; then
166181
exit 1
167182
fi
168183

184+
# Handle VM name: use provided, cached, or prompt
185+
if [ -z "$VM_NAME" ]; then
186+
# Try to read from cache
187+
if [ -f "$VM_NAME_CACHE_FILE" ]; then
188+
VM_NAME=$(cat "$VM_NAME_CACHE_FILE")
189+
log_info "Using cached VM name: $VM_NAME"
190+
else
191+
# No cache, prompt for VM name
192+
echo -n "Enter the VM name to redeploy: "
193+
read -r VM_NAME
194+
if [ -z "$VM_NAME" ]; then
195+
log_error "VM name is required"
196+
exit 1
197+
fi
198+
fi
199+
fi
200+
169201
# Generate unique identifiers for this deployment
170202
DEPLOY_HASH=$(openssl rand -hex 4)
171203
TAR_BASENAME=$(basename "$TAR_FILE")
@@ -559,3 +591,7 @@ if [ "$PROMOTED_IP" = true ] && [ -n "$STATIC_IP_NAME" ]; then
559591
echo " gcloud compute addresses delete $STATIC_IP_NAME --region=$IP_REGION --quiet"
560592
fi
561593
echo ""
594+
595+
# Cache the VM name for future redeployments
596+
echo "$VM_NAME" > "$VM_NAME_CACHE_FILE"
597+
log_info "Cached VM name '$VM_NAME' for future redeployments"

0 commit comments

Comments
 (0)