Accelerate Multi‑Cloud Deployments: How Packer Boosts Image Building for UCloud Rome
This article explains how UCloud's Rome product leverages HashiCorp Packer, combined with GitLab, Jenkins, and Terraform, to automate multi‑cloud image creation, dramatically reducing build time from hours to minutes while improving reliability and consistency across dozens of data centers.
Multi‑cloud deployments are increasingly common, offering higher availability and lower risk, but they also introduce challenges in network interconnection and image management. UCloud addresses these issues with its Rome product, a cross‑cloud network acceleration service spanning over 20 data centers.
Why Traditional Image Creation Fails
Creating images manually through cloud provider consoles is labor‑intensive, error‑prone, and suffers from inconsistent image formats across providers, leading to low replication efficiency and slow delivery.
Packer as the Solution
Packer, an open‑source tool from HashiCorp, enables automated, parallel image building with a single configuration file, supporting multiple clouds via custom builders. UCloud contributed the UCloud Packer Builder, now part of the official Packer release.
CI/CD Pipeline: GitLab + Jenkins + Packer + Terraform
The automated workflow consists of:
Store Packer templates and source code in GitLab.
Trigger Jenkins to build the application and produce release artifacts.
Jenkins supplies cloud credentials, invokes Packer to build images in parallel.
Packer creates temporary VMs, runs provisioners, produces the final image, and cleans up resources, returning the image ID.
Terraform uses the image ID to provision the final instances.
Performance Gains
Testing shows that traditional methods take 4–5 hours to build and replicate images across two clouds and 20+ data centers, whereas Packer completes the same task in 20–30 minutes.
Using Packer Locally
Install Packer and set cloud credentials:
curl -Ls https://releases.hashicorp.com/packer/1.4.4/packer_1.4.4_linux_amd64.zip -o packer.zip && unzip packer.zip && mv packer /usr/local/bin/ export UCLOUD_PUBLIC_KEY="Your UCloud Public Key"
export UCLOUD_PRIVATE_KEY="Your UCloud Private Key"
export UCLOUD_PROJECT_ID="Your UCloud Project ID"Create a Packer template (example.json) with three main blocks:
variables
{
"variables": {
"ucloud_public_key": "{{env `UCLOUD_PUBLIC_KEY`}}",
"ucloud_private_key": "{{env `UCLOUD_PRIVATE_KEY`}}",
"ucloud_project_id": "{{env `UCLOUD_PROJECT_ID`}}",
"access_key": "{{env `ALICLOUD_ACCESS_KEY`}}",
"secret_key": "{{env `ALICLOUD_SECRET_KEY`}}"
}
}builders
{
"builders": [{
"name": "cn-bj2",
"type": "ucloud-uhost",
"public_key": "{{user `ucloud_public_key`}}",
"private_key": "{{user `ucloud_private_key`}}",
"project_id": "{{user `ucloud_project_id`}}",
"region": "cn-bj2",
"availability_zone": "cn-bj2-05",
"instance_type": "n-basic-2",
"source_image_id": "uimage-y11zpg",
"ssh_username": "root",
"image_name": "appName_{{timestamp}}",
"image_copy_to_mappings": [{
"project_id": "projectId",
"region": "cn-sh2",
"name": "appName_{{timestamp}}",
"description": "appName_{{timestamp}}"
}]
}]
}provisioners
{
"provisioners": [
{"type": "shell", "script": "scripts/init.sh"},
{"type": "file", "source": "../../deployFile", "destination": "/home/admin/"}
]
}Build the image with:
packer build --parallel-builds=100 example.jsonIssues Encountered & Solutions
Missing source image IDs in console – use UCloud DescribeImage API.
Base image and instance type mismatches – leverage image_copy_to_mappings to copy images across regions.
Unsupported boot_disk_type in some regions – set it to local_normal or local_ssd.
Duplicate builder names cause errors – add unique name fields.
Conclusion
Packer dramatically improves image creation speed and success rate in UCloud's Rome multi‑cloud environment, enabling rapid onboarding of new regions and consistent production environments. With official UCloud Packer Builder integration, users can combine Terraform, CLI, and other tools to achieve full IaC, continuous integration, and fast delivery in multi‑cloud DevOps scenarios.
UCloud Tech
UCloud is a leading neutral cloud provider in China, developing its own IaaS, PaaS, AI service platform, and big data exchange platform, and delivering comprehensive industry solutions for public, private, hybrid, and dedicated clouds.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
