{"id":15222018,"url":"https://github.com/googlecloudplatform/marketplace-vm-imagebuilder","last_synced_at":"2025-10-20T01:30:29.736Z","repository":{"id":46165879,"uuid":"166116694","full_name":"GoogleCloudPlatform/marketplace-vm-imagebuilder","owner":"GoogleCloudPlatform","description":"A tool to automate the build process of VM images for Google Cloud Platform (GCP).","archived":false,"fork":false,"pushed_at":"2024-12-04T21:57:49.000Z","size":88,"stargazers_count":36,"open_issues_count":2,"forks_count":16,"subscribers_count":27,"default_branch":"master","last_synced_at":"2024-12-18T08:41:07.087Z","etag":null,"topics":["chef","cloud","gcp-compute","google-cloud-marketplace","packer"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GoogleCloudPlatform.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-01-16T21:43:34.000Z","updated_at":"2024-12-04T00:50:50.000Z","dependencies_parsed_at":"2023-01-19T05:31:10.614Z","dependency_job_id":"5c3c12fb-6dc5-44c6-9e62-4177d8d05fe7","html_url":"https://github.com/GoogleCloudPlatform/marketplace-vm-imagebuilder","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoogleCloudPlatform%2Fmarketplace-vm-imagebuilder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoogleCloudPlatform%2Fmarketplace-vm-imagebuilder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoogleCloudPlatform%2Fmarketplace-vm-imagebuilder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoogleCloudPlatform%2Fmarketplace-vm-imagebuilder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GoogleCloudPlatform","download_url":"https://codeload.github.com/GoogleCloudPlatform/marketplace-vm-imagebuilder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237243005,"owners_count":19278060,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chef","cloud","gcp-compute","google-cloud-marketplace","packer"],"created_at":"2024-09-28T15:09:55.697Z","updated_at":"2025-10-20T01:30:29.731Z","avatar_url":"https://github.com/GoogleCloudPlatform.png","language":"Shell","readme":"# Imagebuilder\n\n## About\n\nThis repository hosts Imagebuilder, a tool to automate the build process of VM images for Google Cloud Platform (GCP). Imagebuilder uses Chef cookbooks and Packer to run a VM instance on GCP, install additional software, configure it and create a VM image cleaned up from user sensitive data.\n\nFor an introduction to Chef and Packer, see the documentation for [Chef](https://docs.chef.io/cookbooks.html) and [Packer](https://www.packer.io/docs/).\n\n### Workflow diagram\n\n\u003c!-- Use draw.io as editor. --\u003e\n\n![Workflow diagram](docs/images/imagebuilder-workflow-diagram.svg)\n\n\u003c!-- Save a diagram in SVG format with transparent background,\nand don't check the \"Include a copy of my diagram\" option --\u003e\n\n## Disclaimer\n\nThis is not an officially supported Google product.\n\n## Prerequisites\n\n* In the GCP Console, create a service account, and download the JSON key for\n  the account. For steps to create a service account, see the [IAM\n  documentation](https://cloud.google.com/iam/docs/creating-managing-service-account-keys). For steps to create and download a service account's key, see [Creating and Managing Service Account Keys](https://cloud.google.com/iam/docs/creating-managing-service-account-keys).\n\n  For detailed steps to create the service account and keys, see [Creating the Imagebuilder service account](docs/creating-service-account.md).\n\n* Create a Google Cloud Storage (GCS) bucket to store your build logs. For steps\n  to create a GCS bucket, see the [GCS documentation](https://cloud.google.com/storage/docs/creating-buckets).\n\n## Getting Started\n\n\u003e NOTE: Imagebuilder currently supports Debian based VM images.\n\n### Clone this repository\n\n```shell\ngit clone https://github.com/GoogleCloudPlatform/marketplace-vm-imagebuilder.git\ncd marketplace-vm-imagebuilder\n```\n\n### Use the Docker image\n\nTo build the `imagebuilder` container image, run the following `docker` command:\n\n```shell\ndocker build -t imagebuilder .\n```\n\n### Set the environment variables for your build environment\n\n```shell\nexport PROJECT=\u003cYOUR GCP PROJECT\u003e\nexport BUCKET=\u003cGCS BUCKET NAME TO STORE BUILD LOGS\u003e\nexport SOLUTION_NAME=\u003cVM IMAGE TO BE BUILT\u003e\n```\n\n### Run the build process\n\nThe build is executed in the imagebuild container using a service account for authentication.\nAuthentication can be done using the service account key or local credentials as explained below.\n\n#### Using Service Account Key\n\nThe service account key allows imagebuild to authenticate to GCP. If the key is available, mount a volume in the docker command, as below:\n\n```shell\nexport KEY_FILE_PATH=\u003cABSOLUTE PATH FOR THE SERVICE ACCOUNT KEY\u003e\ndocker run \\\n  -v \"$PWD/examples/chef:/chef:ro\" \\\n  -v \"$PWD/examples/packer:/packer:ro\" \\\n  -v \"$PWD/examples/tests:/tests:ro\" \\\n  -v \"$KEY_FILE_PATH:/service-account.json:ro\" \\\n  -e \"PROJECT=$PROJECT\" \\\n  -e \"BUCKET=$BUCKET\" \\\n  -e \"SOLUTION_NAME=$SOLUTION_NAME\" \\\n  imagebuilder\n```\n\n#### Using Service Account Name and local credentials\n\nThe service account key might not be available when executing locally for manual testing. In this case, login with gcloud and mount the credentials to the container.\n\n```\ngcloud auth application-default login\n```\n\nFollow instructions to get authentication token and complete the login.\n\nSet the env variable `SERVICE_ACCOUNT_EMAIL` and mount the gcloud config into `/root/.config/gcloud` when executig the docker command:\n\n```shell\nexport SERVICE_ACCOUNT_EMAIL=serviceaccountname@projectname.iam.gserviceaccount.com\ndocker run \\\n  -v \"$PWD/examples/chef:/chef:ro\" \\\n  -v \"$PWD/examples/packer:/packer:ro\" \\\n  -v \"$PWD/examples/tests:/tests:ro\" \\\n  -v \"$HOME/.config/gcloud:/root/.config/gcloud\" \\\n  -e \"PROJECT=$PROJECT\" \\\n  -e \"SERVICE_ACCOUNT_EMAIL=$SERVICE_ACCOUNT_EMAIL\" \\\n  -e \"BUCKET=$BUCKET\" \\\n  -e \"SOLUTION_NAME=wordpress\" \\\n  imagebuilder\n```\n\n## Volume mounts\n\nThese are the filesystem paths used by the `imagebuilder` container image:\n\nPath                  | Description                                                                                                                                                                                                                                                                                                                                                                | Required\n--------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------\n/packer               | Packer templates that specify the configuration for the VM image.\u003cbr/\u003e\u003cbr/\u003eThe volume must contain a `templates` directory. Your template must be in a subdirectory that matches the `$SOLUTION_NAME` environment variable. The template is expanded with the [`packergen.py`](scripts/packergen.py) script.                                                               | Yes\n/chef                 | Chef cookbooks used in the build process.\u003cbr/\u003e\u003cbr/\u003eThe volume must contain a `cookbooks` directory. Your cookbook must be in its own subdirectory. You specify the name of your cookbook in your Packer template's [`run_list` attribute](examples/packer/templates/sample-app/packer.in.json#L4).                                                                         | Yes\n/tests                | A directory with test specs. The directory must contain an executable Bash script called `run-tests-on-instance.sh`, which is used as an entrypoint. \u003cbr/\u003e\u003cbr/\u003eThe `run-tests-on-instance.sh` script has access to the `$PACKER_SSH_USERNAME` and `$SOLUTION_NAME` variables. The return code of this script should indicate the result of tests: for success, return `0`. | No\n/service-account.json | The JSON key for the GCP service account that you created.\u003cbr/\u003e\u003cbr/\u003e The key is used to set an authentication context for `gcloud` commands and the `packer` binary for managing resources in your GCP project.                                                                                                                                                            | Yes\n\n## Environment variables\n\nThe following environment variables are **required**:\n\n-   `SOLUTION_NAME`:\n\n    The VM image to be built. The name must be the same as the folder that has your Packer template.\n\n-   `PROJECT`:\n\n    A GCP project where VM instances will be created and VM image will be built.\n\n-   `BUCKET`:\n\n    A GCS bucket that stores the logs generated by the instance's shutdown\n    script. Packer uses the log to verify that the shutdown script ran\n    successfully. At the end of the build process, the log is deleted.\n\nThe following environment variables are **optional**:\n\n-   `KEY_FILE_PATH` (defaults to `/service-account.json`):\n\n    An absolute path of the GCP service account JSON key to used by the `gcloud`\n    CLI and the `packer` binary.\n\n-   `ZONE` (defaults to `us-central1-f`):\n\n    The GCP zone in which the VM instance is created. The VM instance is used as\n    the base for creating the image.\n\n    For a list of zones, see [Regions and Zones in the Compute Engine documentation](https://cloud.google.com/compute/docs/regions-zones/)\n\n-   `IMAGE_NAME` (defaults to `$SOLUTION_NAME-v$(($(date +%s%N)/1000000))`):\n\n    An image name to be built and saved in your GCP project.\n\n-   `PACKER_DIR` (defaults to `/packer/templates`):\n\n    An absolute path to the Packer templates directory. A directory of\n    `$SOLUTION_NAME` should be present there.\n\n-   `CHEF_DIR` (defaults to `/chef`):\n\n    The absolute path to the Chef cookbooks directory.\n\n-   `TESTS_DIR` (defaults to `/tests`):\n\n    The absolute path to the image tests directory. The directory must contain an executable\n    Bash script called `run-tests-on-instance.sh`. Used when the\n    `$RUN_TESTS` variable is `true`.\n\n-   `RUN_TESTS` (`true` or `false`; defaults to `false`):\n\n    Whether tests should be run on the newly-built VM image.\n\n-   `ATTACH_LICENSE` (`true` or `false`; defaults to `false`):\n\n    Whether to attach a GCP Marketplace license to the newly-built VM image. The\n    license name must be provided in the solution package template.\n\n-   `LICENSE_PROJECT_NAME` (defaults to `none`):\n\n    A GCP project where the license was created. Required if `$ATTACH_LICENSE`\n    is set to `true`.\n\n-   `USE_INTERNAL_IP` (`true` or `false`; defaults to `false`):\n\n    Whether to use an internal IP to configure SSH connection to instances\n    created by `imagebuilder`. If `false`, then an external IP is used.\n\n-   `PUBLISH_TO_PROJECT` (defaults to `none`):\n\n    The name of a GCP project to copy the VM image to. The image is created in\n    the project you specific in `$PROJECT`, and then copied to `$PUBLISH_TO_PROJECT`.\n\n-   `TESTS_CUSTOM_METADATA` (defaults to `none`):\n\n    Custom metadata for the test instance. Each metadata entry is a key/value pair\n    separated by an equals sign. You can use multiple metadata keys, separated\n    by a comma.\n\n    For example:\n\n    ```\n    TESTS_CUSTOM_METADATA='google-monitoring-enable=1,google-logging-enable=1'\n    ```\n\n    For detailed information on using instance metadata, see the [Compute Engine\n    documentation](https://cloud.google.com/compute/docs/storing-retrieving-metadata).\n\n## Packer template\n\nA Packer template is a JSON file that supports the following attributes:\n\nAttribute             | Type   | Required | Description\n--------------------- | ------ | -------- |------------\n`chef`                | dict   | Yes      | Chef config, used mostly for the run_list property to define the recipies to run.\n`source_image_family` | string | Yes      | The image family to be used as a base image to run Packer build.\n`license`             | string | No       | VM image license name to be attached - for Marketplace it should match an exisiting VM solution name.\n`image_family`        | string | No       | The image family set to the final image.\n\nFor example:\n\n```json\n{\n  \"license\": \"imagebuilder-test\",\n  \"source_image_family\": \"debian-11\",\n  \"chef\": {\n    \"run_list\": [ \"sample-app\" ]\n  }\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgooglecloudplatform%2Fmarketplace-vm-imagebuilder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgooglecloudplatform%2Fmarketplace-vm-imagebuilder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgooglecloudplatform%2Fmarketplace-vm-imagebuilder/lists"}