/cloud-images

Packer templates and other tools for building AlmaLinux images for various cloud platforms.

Primary LanguageHCLMIT LicenseMIT

AlmaLinux OS Cloud Images

AlmaLinux OS Cloud Images is a project that contains Packer templates and other tools for building AlmaLinux OS images for various cloud platforms.

Download official images

Name Download URL
AWS Marketplace AMI https://aws.amazon.com/marketplace/pp/B094C8ZZ8J
AWS community AMIs https://wiki.almalinux.org/cloud/AWS.html
Docker Hub https://hub.docker.com/_/almalinux
Generic Cloud (cloud-init) https://wiki.almalinux.org/cloud/Generic-cloud.html
Google Cloud https://cloud.google.com/compute/docs/images#almalinux
LXC/LXD https://images.linuxcontainers.org
Quay.io https://quay.io/repository/almalinux/almalinux
Vagrant boxes app.vagrantup.com/almalinux
OpenNebula https://wiki.almalinux.org/cloud/OpenNebula.html

Roadmap

  • Add aarch64 architecture support
  • Vagrant + VirtualBox support
  • Vagrant + VMWare support
  • Vagrant + Parallels support (#3)
  • Vagrant + Microsoft Hyper-V support (#4)
  • Vagrant + Libvirt support
  • AWS AMI x86_64 and aarch64 support
  • Google Cloud support
  • Microsoft Azure support (#14)
  • DigitalOcean support
  • Generic Cloud / OpenStack x86_64 and aarch64 support (#12)
  • LXC/LXD support (#8)
  • OpenNebula x86_64 and aarch64 support

Usage

Initialize Packer plugins:

$ packer init .

Build a Vagrant Box

Build a VirtualBox box:

$ packer build -only=virtualbox-iso.almalinux-8 .

Build a VMWare box:

$ packer build -only=vmware-iso.almalinux-8 .

Build a Parallels box:

$ packer build -only=parallels-iso.almalinux-8 .

Build a Libvirt box:

$ packer build -only=qemu.almalinux-8 .

Build a Hyper-V box:

> packer build -only="hyperv-iso.almalinux-8" .

Build an Amazon AMI

x86_64

Before building AMI's you need to configure AWS credentials as described in the Packer documentation. Basically, you need to define the following environment variables:

export AWS_ACCESS_KEY_ID='ENTER_YOUR_ACCESS_KEY_HERE'
export AWS_SECRET_ACCESS_KEY='ENTER_YOUR_SECRET_KEY_HERE'
export AWS_DEFAULT_REGION='us-east-1'

Also, you need to create an S3 bucket that Packer will use for temporary image storing before importing it into EC2. It's strongly recommended creating the bucket in the us-east-1 region if you are going to submit your images to the Amazon Marketplace. Accordingly to Amazon's documentation, the self-service AMI scanner supports only that region.

After configuring the AWS credentials and creating the S3 bucket, run the following command to build an AMI and import it to EC2:

The Build process has two stages:

  • Stage 1: Build the first stage's AMI on your system and import it to the AWS.

  • Stage 2: Build the second stage's AMI on the EC2 Instance.

The First Stage:

QEMU:

$ packer build -var aws_s3_bucket_name="YOUR_S3_BUCKET_NAME" -only=qemu.almalinux-8-aws-stage1 .

VMware:

$ packer build -var aws_s3_bucket_name="YOUR_S3_BUCKET_NAME" -only=vmware-iso.almalinux-8-aws-stage1 .

If you are using a non-standard role name, it's possible to define it as a variable:

QEMU:

$ packer build -var aws_s3_bucket_name="YOUR_S3_BUCKET_NAME" \
               -var aws_role_name="YOUR_IAM_ROLE_NAME" -only=qemu.almalinux-8-aws-stage1 .

VMware:

$ packer build -var aws_s3_bucket_name="YOUR_S3_BUCKET_NAME" \
               -var aws_role_name="YOUR_IAM_ROLE_NAME" -only=vmware-iso.almalinux-8-aws-stage1 .

The Second Stage:

To finalize the AMI build process, you need to launch a minimum t2.micro EC2 instance from the first stage's AMI.

Launch an instance with the build-tools-on-ec2-userdata.yml Cloud-init User Data. It will install all needed packages - Packer, Ansible, Git and tmux (if your connection is not stable) and clone the repo automatically.

login as ec2-user:

$ cd cloud-images

Switch to the root user:

$ sudo su

Confugire the AWS credentials:

export AWS_ACCESS_KEY_ID='ENTER_YOUR_ACCESS_KEY_HERE'
export AWS_SECRET_ACCESS_KEY='ENTER_YOUR_SECRET_KEY_HERE'
export AWS_DEFAULT_REGION='us-east-1'

Install required Packer plugins:

packer.io init .

Start the Build:

packer.io build -only=amazon-chroot.almalinux-8-aws-stage2 .

You can remove the first stage's AMI after the build complete

aarch64

Confugire the AWS credentials:

export AWS_ACCESS_KEY_ID='ENTER_YOUR_ACCESS_KEY_HERE'
export AWS_SECRET_ACCESS_KEY='ENTER_YOUR_SECRET_KEY_HERE'
export AWS_DEFAULT_REGION='us-east-1'

Install required Packer plugins:

packer init .

Start the Build:

packer build -only=amazon-ebssurrogate.almalinux-8-aws-aarch64 .

Build a DigitalOcean image

You need to setup a key for packer to use. This is done by going to DigitalOcean's cloud console.

Make it available through an environment variable:

$ export DIGITALOCEAN_API_TOKEN="ENTER_YOUR_ACCESS_TOKEN_HERE"

A space needs to be created in order to import the image through it. Please, read the relevant documentation. Take note of the access and secret keys in order to use them later on.

There are a few environemnt variables you will need to make available.

  • The spaces bucket name through DIGITALOCEAN_SPACE_NAME.
  • The bucket's access key through DIGITALOCEAN_SPACES_ACCESS_KEY.
  • The bucket's secret key through DIGITALOCEAN_SPACES_SECRET_KEY.

You can do this by exporting them as well:

$ export DIGITALOCEAN_SPACE_NAME='YOUR_SPACES_BUCKET_NAME'
$ export DIGITALOCEAN_SPACES_ACCESS_KEY='YOUR_BUCKET_ACCESS_KEY'
$ export DIGITALOCEAN_SPACES_SECRET_KEY='YOUR_BUCKET_SECRET_KEY'

Now, you're all setup. You can try building the image with:

$ packer build -only qemu.almalinux-8-digitalocean-x86_64 .

Import the image to DigitalOcean

You can upload your image or Import it via URL from the GitHub release section.

In Images >> Custom Images section, click on Import via URL and enter the URL of image file : https://github.com/AlmaLinux/cloud-images/releases/download/digitalocean-20210810/almalinux-8-DigitalOcean-8.4.20210810.x86_64.qcow2

Build a Generic Cloud (OpenStack compatible) image

x86_64

$ packer build -only=qemu.almalinux-8-gencloud-x86_64 .

aarch64

$ packer build -only=qemu.almalinux-8-gencloud-aarch64 .

Build a OpenNebula image

x86_64

$ packer build -only=qemu.almalinux-8-opennebula-x86_64 .

aarch64

$ packer build -only=qemu.almalinux-8-opennebula-aarch64 .

Requirements

References

FAQ:

Issue: build stuck after running the packer command.

Solution: Use packer.io instead of the packer. See: https://learn.hashicorp.com/tutorials/packer/get-started-install-cli#troubleshooting

example:

ln -s /usr/bin/packer /usr/bin/packer.io

Issue: Failed creating Qemu driver: exec: "qemu-system-x86_64": executable file not found in $PATH

Solution: By default, Packer looks for QEMU binary as qemu-system-x86_64. If it is different in your system, You can set your qemu binary with the qemu_binary variable. i.e. on EL, it's qemu-kvm. :

example:

$ packer build -var qemu_binary="/usr/libexec/qemu-kvm" -only=qemu.almalinux-8-gencloud-x86_64 .

License

Licensed under the MIT license, see the LICENSE file for details.