hashicorp / packer-plugin-docker

Packer plugin for Docker Builder
https://www.packer.io/docs/builders/docker
Mozilla Public License 2.0
31 stars 25 forks source link

Push docker image to ECR public gallery #45

Closed ghost closed 2 years ago

ghost commented 3 years ago

This issue was originally opened by @Laakso as hashicorp/packer#10948. It was migrated here as a result of the Packer plugin split. The original body of the issue is below.


Description

Since AWS released their public container registry it would be nice that the packer image would be pushed there as well.

Use Case(s)

Push packer container image to ECR public container registry.

devashish-patel commented 2 years ago

This feature will be available in the upcoming release. Here is the example template to tag and push docker image to ECR Public:

// NOTES:
// Check following items before running the template:
// 1. `docker` is running locally
// 2. Appropriate variables are set under `default` profile in ` ~/.aws/credentials`
// 3. Change `registry_alias` and `registry_name` variables in this template with your appropriate values

variables {
  registry_alias = "<your_registry_alias>"
  registry_name  = "<your_registry_name>"
}

source "docker" "ubuntu-bionic" {
  image  = "ubuntu:bionic"
  commit = true
}

build {
  name = "docker-push-ecr-public"
  sources = [
    "source.docker.ubuntu-bionic"
  ]

  post-processors {
    post-processor "docker-tag" {
      repository = "public.ecr.aws/${var.registry_alias}/${var.registry_name}"
      tags       = ["latest"]
    }

    post-processor "docker-push" {
      ecr_login    = true
      aws_profile  = "default"
      login_server = "https://public.ecr.aws/${var.registry_alias}/${var.registry_name}"
    }
  }
}