DEV Community

ant Kenworthy
ant Kenworthy

Posted on

Packer: Using an image family from another project

Following on from my previous post: Packer: Building images on Google Cloud You should now be able to build compute images on GCP and you may have used this to build a pre-configured image you can effortlessly deploy again and again without having to wait to install software.

You may now want to use that image, or someone else's image from a different project as a starting point for your web or database server.

If you do you, can add the following line to your packer template in the builders section to specify another project to source your image from:

source_image_project_id
Enter fullscreen mode Exit fullscreen mode

Here's how that may look when used in your packer template:

{
  "builders": [
    {
      "type": "googlecompute",
      "project_id": "my project",
      "zone": "us-central1-a",
      "source_image_family": "base-image-linux",
      "source_image_project_id":, "example-project",
      "ssh_username": "packer",
      "image_name": "packer-{{timestamp}}",
      "image_family": "socks-web"
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

Here the base-image-linux may contain our companies standard logging setup and common utilities. From this you could then install your web server or database utilities on top of that common image.

Another example may be to use the public images provided by a regulatory body where you need to add some helper scripts before you deploy it to your project.

🎉

Discussion (0)