16 Aug
|
Shersoft
|
Anupgarh
Apr 13, 2024
If you’re building containerised services, or using a CI/CD system, you’ll likely end up building base images that contain the customisations that fit your organisation’s needs. For example, you might update OS packages, install a newer version of a package manager, or install the CLI tool(s) of your chosen cloud provider. Keeping these images up-to-date can become a maintenance burden, especially if you want to keep several versions available for different programming languages or runtimes.
Let’s explore how we can automate this process.
In the shersoft-ltd/evergreen-ci-and-base-images repository, we’ll start by creating some Amazon Elastic Container Registry (ECR) repositories for our images (modules/ecr-repository/main.tf):
resource "aws_ecr_repository" "main" { name = var.name }
We’re Going To Be Making Lots Of Images Each Day, So Let’s Also Add In a Lifecycle Policy That Will Clean Up Any Draft Images, And Those That Are Untagged
resource "aws_ecr_lifecycle_policy" "main" { repository = aws_ecr_repository.main.id policy = jsonencode({ "rules" :
[ { "rulePriority" : 1, "description" : "Retire draft images.", "selection" : { "tagStatus" : "tagged", "tagPrefixList" : [ "draft" ], "countType" : "sinceImagePushed", "countUnit" : "days", "countNumber" : 1 }, "action" : { "type" : "expire" } }, { "rulePriority" : 2, "description" : "Retire untagged images.", "selection" : { "tagStatus" : "untagged", "countType" : "sinceImagePushed", "countUnit" : "days", "countNumber" : 1 }, "action" : { "type" : "expire" } } ] }) }
With that in place, we’ll setup the following file structure:
runtimes/node/Dockerfile runtimes/node/self-test.js runtimes/node/self-test.sh runtimes/node-ci-cd/Dockerfile runtimes/node-ci-cd/self-test.js runtimes/node-ci-cd/self-test.sh runtimes/python/Dockerfile runtimes/python/self-test.py runtimes/python/self-test.sh
Each Runtime We’re Building Images For Will Have a Dockerfile That Defines How To Build The Image, And a Sel
📌 Keeping base and CI/CD Docker images up-to-date in AWS (Anupgarh)
🏢 Shersoft
📍 Anupgarh