Build a Vultr Marketplace application image from an instance snapshot using the Vultr Console or Vultr API to package a configured server as your app.
Building from a snapshot means you pre-install your application on a server, set up post-deployment scripts, and take a snapshot of the disk image. When customers deploy your app, they get your snapshot, and cloud-init runs your scripts. Prefer building from Vendor Data when your application supports it, since it avoids maintaining a snapshot.
This guide explains how to prepare a server and build an image from its snapshot using the Vultr Console or the Vultr API.
To open the snapshot selector, click Marketplace in the Vultr Console's left-hand menu, click the application name, click the Builds tab, then click the Build From Snapshot button to switch from the default Vendor Data view.
Optimize the server before you take the snapshot:
marketplace-2c-2gb plan, which is optimized for Marketplace applications. This plan includes 2 vCPUs, 2 GB of memory, and 8 GB of storage.Adapt the following code snippets to your needs and your OS distribution. These steps are also available as an example shell script in our GitHub repository.
Create the /tmp directory if it doesn't already exist.
Set the proper permissions on the directory.
For yum-based distributions:
Update installed packages.
Clean the package cache.
For apt-based distributions:
Refresh the package index.
Upgrade installed packages.
Remove packages that are no longer needed.
Clean the package cache.
Clean the temporary directories.
Clean /tmp.
Clean /var/tmp.
Clean SSH keys.
Remove the authorized keys and existing host keys.
Create an empty revoked keys file.
Set the proper permissions on the revoked keys file.
Clean the logs.
Truncate logs modified in the last day.
Remove compressed log archives.
Remove numbered rotated logs.
Remove date-stamped rotated logs.
Clear the auth log.
Clean old cloud-init information.
Clean the session history.
Clear the current shell session's history.
Clear the saved history file.
Unset the history file variable so nothing is written back to it before the snapshot.
Update the mlocate database.
Wipe the random seed file.
Distributions that use systemd must wipe the machine identifier to prevent boot problems.
Remove the existing machine ID. Some distributions keep a separate copy at /var/lib/dbus/machine-id instead of symlinking it to /etc/machine-id, so remove both.
Create an empty replacement file. systemd generates a new machine ID the next time the system boots.
Clear the last login log.
Clear the login/logout record.
Wipe unused disk space with zeros for security and compression.
Fill the free space with a zeroed file.
The command runs until the disk is full and exits with a No space left on device error. This is the expected result.
Flush the write to disk.
Remove the zeroed file.
Flush the deletion to disk.
Not all Linux distributions support fstrim, but you may consider running this final step before making the snapshot.
Vultr can snapshot a running server, but you may prefer a clean shutdown. If so, consider halting and powering off the server before taking the snapshot.
To power off:
Navigate to the Add Snapshot page in the Vultr Console.
Select your instance in the dropdown.
Enter a descriptive label.
Click Take Snapshot. Wait a few minutes for the snapshot to complete.
Click Marketplace in the left-hand menu, then click the application name.
Click the Builds tab.
Select the snapshot image you just created.
Click Build App Image. The Vultr Marketplace takes your snapshot and builds it into an App Image.
0 Comments
Be the first to comment and share your perspective with the community.