简体   繁体   中英

Path and options for saving a Packer VM image to GCP Artifact Registry

(Warning, Newbie here) I'm learning Packer by building a VM. I followed links to cloud-builders-community/packer example. Unfortunately this seems to be out of date. It pushes the output to gcr.io … which I'm discovering is being deprecated in favour of Artifact Registry. It's also using YAML instead of HCL2.

Is this old code and is there an up to date equivalent somewhere else?

Assuming I can or should continue using this sample code… I'm confused about a couple things. Artifact Registry: Create Repository has options for Docker, Maven, etc. but does not have an option for VM images. Do I just choose Docker?

Then in cloud-builders-community/packer/cloudbuild.yaml what path do I use to replace gcr.io? gcr.io appears multiple times.

From: https://github.com/GoogleCloudPlatform/cloud-builders-community/packer/cloudbuild.yaml

steps:
  - name: 'gcr.io/cloud-builders/wget'
    args: ["https://releases.hashicorp.com/packer/${_PACKER_VERSION}/packer_${_PACKER_VERSION}_linux_amd64.zip"]
  - name: 'gcr.io/cloud-builders/docker'
    args: ['build', '-t', 'gcr.io/$PROJECT_ID/packer:${_PACKER_VERSION}',
           '-t', 'gcr.io/$PROJECT_ID/packer',
           '--build-arg', 'PACKER_VERSION=${_PACKER_VERSION}',
           '--build-arg', 'PACKER_VERSION_SHA256SUM=${_PACKER_VERSION_SHA256SUM}',
           '.']
substitutions:
  _PACKER_VERSION: 1.7.8
  _PACKER_VERSION_SHA256SUM: 8a94b84542d21b8785847f4cccc8a6da4c7be5e16d4b1a2d0a5f7ec5532faec0

images:
  - 'gcr.io/$PROJECT_ID/packer:latest'
  - 'gcr.io/$PROJECT_ID/packer:${_PACKER_VERSION}'
tags: ['cloud-builders-community']

BTW, the overall arc of my learning project is:

Packer => VM Image => GCP Artifact Repository => Terraform => GCP VM

I don't know specifics about packer, but in general, for using AR with docs that specify gcr.io:

  • Anytime you want to use AR as a replacement for GCR, you should choose docker.

  • You should replace gcr.io/$PROJECT_ID with $REGION-docker.pkg.dev/$PROJECT_ID/$REPOSITORY_ID for anywhere it refers to your project, and leave the gcr.io url as-is for other people's projects (like cloud-builders).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM