Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve image_creation script #88

Merged
merged 2 commits into from
Jul 3, 2024

Conversation

dongsupark
Copy link
Collaborator

@dongsupark dongsupark commented Jun 20, 2024

Improve image_creation.sh script.

  • Make necessary variables configurable like resource group, storage account, location, vm_name, vm_size, etc.
  • Consolidate storage accounts creation into a single account, to avoid defining custom connection string env variables. Instead, generate connection string from the storage account directly to pass it to the subsequent commands.
  • Create storage account and container before getting SAS string.
  • Create SIG gallery before running az sig image-version create.
  • Convert variable names to capital letters.
  • Create image-definition before creating image-version in an automated way.
  • Explicitly set SecurityType=TrustedLaunch for vm create and sig image-definition create.
  • Address warnings and infos when running shellcheck, mainly by adding quotes around variables.
  • Add command line options -h for help and -v for verbose.

How to run with custom parameters.

RG="my-test-azinit" LOCATION="westeurope" VM_SIZE="Standard_D2ds_v5" BASE_IMAGE="Debian:debian-11:11-backports-gen2:latest" demo/image_creation.sh

Testing done

Done testing with a couple of possible variables.

Copy link
Member

@jeremycline jeremycline left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried this out with RG="jcline-azinit-test2" LOCATION="eastus2" BASE_IMAGE="Debian:debian-11:11-backports-gen2:latest" demo/image_creation.sh and the VM failed configuration with

[   33.134147] cloud-init[918]: /var/log/azure/image/setup.sh: line 14: /etc/netplan/eth0.yaml: No such file or directory

I assume /etc/netplan/ doesn't exist on that image.

Since you're not touching the customdata_template.yml this is just an existing issue from what I can tell. The changes themselves look good good to me. You might want to point ShellCheck at it, but all those were pre-existing so we can do that separately as well.

@dongsupark
Copy link
Collaborator Author

I tried this out with RG="jcline-azinit-test2" LOCATION="eastus2" BASE_IMAGE="Debian:debian-11:11-backports-gen2:latest" demo/image_creation.sh and the VM failed configuration with

[   33.134147] cloud-init[918]: /var/log/azure/image/setup.sh: line 14: /etc/netplan/eth0.yaml: No such file or directory

I assume /etc/netplan/ doesn't exist on that image.

I cannot reproduce it myself, but anyway pushed a fix for that in customdata_template.yml.

Since you're not touching the customdata_template.yml this is just an existing issue from what I can tell. The changes themselves look good good to me. You might want to point ShellCheck at it, but all those were pre-existing so we can do that separately as well.

@anhvoms
Copy link
Contributor

anhvoms commented Jun 25, 2024

The image creation script was used with Ubuntu 20.04/22.04. It assumed that netplan was used for networking and a lot of code written was based on that assumption. See issue #90

@dongsupark
Copy link
Collaborator Author

Added an automated creation of image definition before creating image version.
Addressed warnings and infos when running shellcheck.

@dongsupark dongsupark marked this pull request as ready for review June 27, 2024 14:54
demo/image_creation.sh Outdated Show resolved Hide resolved
demo/image_creation.sh Show resolved Hide resolved
demo/image_creation.sh Outdated Show resolved Hide resolved
demo/image_creation.sh Outdated Show resolved Hide resolved
* Make necessary variables configurable like resource group, storage
  account, location, vm_name, vm_size, etc.
* Consolidate storage accounts creation into a single account, to avoid
  defining custom connection string env variables. Instead, generate
  connection string from the storage account directly to pass it to the
  subsequent commands.
* Create storage account and container before getting SAS string.
* Create SIG gallery before running az sig image-version create.
* Convert variable names to capital letters.
* Create image-definition before creating image-version in an automated
  way.
* Explicitly set SecurityType=TrustedLaunch for vm create and sig
  image-definition create.
* Address warnings and infos when running shellcheck, mainly by adding
  quotes around variables.
* Add command line options -h for help and -v for verbose.
Create directory /etc/netplan before writing files into the directory.
Remove a garbage file with `rm -f` to prevent the machine to be stuck
before shutting down.
Copy link
Contributor

@anhvoms anhvoms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you.

@dongsupark dongsupark merged commit ddfae51 into Azure:main Jul 3, 2024
3 checks passed
@dongsupark dongsupark deleted the test-demo-image-creation branch July 3, 2024 08:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants