Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add ECR Lifecycle Policy Option to docker-build module #243

Merged

Conversation

1Mill
Copy link
Contributor

@1Mill 1Mill commented Dec 28, 2021

Description

Let users add ECR lifecycle policy rules to automate the cleaning up of unused images generated by the docker-build module.

Motivation and Context

I use this module to build and publish many Docker Images to ECR and I want to be able to easily delete unneeded Docker Images. Since this module is the one building and publishing the Docker Images to ECR it seems best to extend the module to also support the JSON ECR lifecycle policy document.

Breaking Changes

This is not a breaking change and is only added non-breaking functionality to the module.

How Has This Been Tested?

  • I have tested and validated these changes using one or more of the provided examples/* projects
// examples/container-image/main.tf

module "docker_image" {
  source = "../../modules/docker-build"

  create_ecr_repo = true
  ecr_repo        = random_pet.this.id
  image_tag       = "1.0"
  source_path     = "context"
  build_args = {
    FOO = "bar"
  }
  ecr_repo_lifecycle_policy = <<EOF
{
  "rules": [
    {
      "rulePriority": 1,
      "description": "Keep only the last 2 images",
      "selection": {
        "tagStatus": "any",
        "countType": "imageCountMoreThan",
        "countNumber": 2
      },
      "action": {
        "type": "expire"
      }
    }
  ]
}
EOF
}

Copy link
Member

@antonbabenko antonbabenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good. Please fix docs (pre-commit run -a) to make GH checks green.

modules/docker-build/main.tf Outdated Show resolved Hide resolved
modules/docker-build/variables.tf Outdated Show resolved Hide resolved
@1Mill
Copy link
Contributor Author

1Mill commented Jan 5, 2022

@antonbabenko, I committed your changes about the default null value and updated the README. I gad quite a few issues with getting pre-commit working so may want to double check the pre-commit run -a command.

@antonbabenko antonbabenko merged commit 577b077 into terraform-aws-modules:master Jan 5, 2022
antonbabenko pushed a commit that referenced this pull request Jan 5, 2022
# [2.29.0](v2.28.0...v2.29.0) (2022-01-05)

### Features

* Add ECR Lifecycle Policy Option to docker-build module ([#243](#243)) ([577b077](577b077))
@antonbabenko
Copy link
Member

This PR is included in version 2.29.0 🎉

@1Mill 1Mill deleted the add-ecr-policy-support branch January 6, 2022 03:44
@github-actions
Copy link

github-actions bot commented Nov 8, 2022

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants