我想构建一个 CI 管道,在将 Dockerized 应用程序上传到 Artifact Registry 并首次部署之前,基础设施阶段使用 Terraform 在 Google Compute Engine 上提供容器优化的操作系统实例。
我的 Terraform 配置:
data "google_compute_image" "cos" {
family = "cos-stable"
project = "cos-cloud"
}
resource "google_compute_instance" "container_optimized_os_vm" {
name = "container-optimized-os-vm"
machine_type = "f1-micro"
allow_stopping_for_update = true
network_interface {
network = "default"
}
boot_disk {
initialize_params {
image = data.google_compute_image.cos.self_link
}
}
metadata = {
google-logging-enabled = "true"
gce-container-declaration =<<EOT
spec:
containers:
- image: image-repository/image-name:latest
name: containervm
securityContext:
privileged: false
stdin: false
tty: false
volumeMounts: []
restartPolicy: Always
volumes: []
EOT
}
}
我从 Artifact Registry 部署最新版本图像的命令:
gcloud compute instances update-container container-optimized-os-vm \
--zone europe-west2-b \
--container-image "europe-west2-docker.pkg.dev/my-project-id/my-image-repository-name/my-image-name:latest"
当我省略gce-container-declaration
元数据时,我收到以下错误:
ERROR: (gcloud.compute.instances.update-container) Instance doesn't have gce-container-declaration metadata key - it is not a container.
我希望能够在不指定图像的情况下配置实例gce-container-declaration
——这可能吗?我担心的是,当检测到基础架构更改时,gce-container-declaration
将部署其中的图像而不是我的应用程序的图像。