GitXplorerGitXplorer
a

docker-ecr-actions-workflow

public
35 stars
8 forks
0 issues

Commits

List of commits on branch main.
Verified
138ab7afb610caa1d556609bb8fe63920a92f415

Create policy.json

rruchimo committed a year ago
Verified
8be9f2f5eb7ed2ae9d3bc8f3b9097dea110ef2da

Merge pull request #3 from aws-samples/cleanup

rruchimo committed a year ago
Verified
b0644b0cae764670a54ef13785c938183a5a209c

clean-up

rruchimo committed a year ago
Verified
ce1e4841b5e1029015e68f7af8335aef441517d7

First release of reusable Github workflow (#1)

rruchimo committed a year ago
Verified
70187d7076b3dbffa3fd630c1c6e6a7c6b7b0dff

Initial commit

aamazon-auto committed a year ago

README

The README file for this repository.

Docker ECR Actions Workflow

This repository contains the reusable workflow for building and publishing Docker images. Provides steps on how to automate the build process of your Dockerfiles using Terraform and Github actions, this minimizes the possibility of human error and substantially reduces the deployment time.

Deployment of resources can be triggered upon Github ‘push’ action to the main branch of your github repository. Or it can configured to be executed manually from the Github Actions console using the flag "workflow_dispatch".

This solution has the flag as "workflow_dispatch", but this can be replaced with "push" to trigger the workflows on every push; more details can be found here.

Table of content

Summary of build steps

  • Build the image according to the Dockerfile
  • Ensure an ECR repository for this GitHub repository exists
  • Tag and publish the image to the ECR repository

Prerequisites

Setup

  • Dockerfile and any build-related data
  • policy.json to dictate the ECR lifecycle policy

Architecture

image

How to Use

The reusable Github Actions workflow template is available under the folder ".github/workflows". As mentioned above the action to trigger the workflow is currently set to "workflow_dispatch", but this can be changed to "push" or "workflow_call" based on your required. for more information check here

A sample Dockerfile is added under the directory "e2e-test", this is just for reference and execution of the pipeline.

  1. Either edit the ".github/workflows/workflow.yaml" file to update the inputs. This can also be passed via the console when triggering manually.
  2. Make sure to pass the right AWS Account ID and region as Inputs.
  3. A sample ECR lifecycle policy is added here at "e2e-test/policy.json". Refer next section for more information.
  4. Two IAM roles are required as inputs: a. An IAM role with permissions to setup the Terraform S3 backend and provided as input backend_iam_role b. An IAM role with permissions to Github, which is also used in the ECR policy to restrict ECR operations, refer data.tf file.

ECR Policy

Example policy.json (find some other examples here):

{
  "rules": [
    {
      "rulePriority": 1,
      "description": "Keep last 30 images",
      "selection": {
        "tagStatus": "tagged",
        "tagPrefixList": [ "prod" ],
        "countType": "imageCountMoreThan",
        "countNumber": 30
      },
      "action": {
        "type": "expire"
      }
    }
  ]
}

Best practices

Please make sure to follow provided best practices, as this is not in the scope of this solution.

  • Best practices for writing Dockerfiles
  • VPC Endpoint for ECR : VPC endpoints are powered by AWS PrivateLink, a technology that enables you to privately access Amazon ECR APIs through private IP addresses. For Amazon ECS tasks using the Fargate launch type, the VPC endpoint enables the task to pull private images from Amazon ECR without assigning a public IP address to the task.

Contributing

See CONTRIBUTING for more information.

License

This library is licensed under the MIT-0 License. See the LICENSE file.

Contributors

  • Ruchika Modi