Skip to content

Commit 0ab3ae7

Browse files
committed
Refactor deployment workflow and ECR repository configuration
- Updated the deployment workflow to use a new naming convention for the Docker image tag and repository. - Removed the conditional check for existing images in ECR, ensuring a build and push occurs every time. - Introduced a new ECR repository resource for the record processor, enhancing image management. - Adjusted IAM policies and ECS task definitions to reference the new repository configuration.
1 parent 35d95ea commit 0ab3ae7

3 files changed

Lines changed: 17 additions & 38 deletions

File tree

.github/workflows/deploy-backend.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,16 +127,12 @@ jobs:
127127
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
128128
working-directory: lambdas
129129
run: |
130-
IMAGE_TAG="${GITHUB_SHA}"
131-
REPOSITORY_NAME="imms-${SUB_ENVIRONMENT}-processing-repo"
130+
IMAGE_TAG="${SUB_ENVIRONMENT}-${GITHUB_SHA}"
131+
REPOSITORY_NAME="imms-recordprocessor-repo"
132132
IMAGE_URI="${ECR_REGISTRY}/${REPOSITORY_NAME}:${IMAGE_TAG}"
133133
134-
if aws ecr describe-images --repository-name "${REPOSITORY_NAME}" --image-ids imageTag="${IMAGE_TAG}" --region "${AWS_REGION}" >/dev/null 2>&1; then
135-
echo "Image ${IMAGE_TAG} already exists in ECR, skipping build and push"
136-
else
137-
docker build -f recordprocessor/Dockerfile -t "${IMAGE_URI}" .
138-
docker push "${IMAGE_URI}"
139-
fi
134+
docker build -f recordprocessor/Dockerfile -t "${IMAGE_URI}" .
135+
docker push "${IMAGE_URI}"
140136
141137
terraform-apply:
142138
permissions:
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
resource "aws_ecr_repository" "processing_repository" {
2+
image_scanning_configuration {
3+
scan_on_push = true
4+
}
5+
image_tag_mutability = "IMMUTABLE"
6+
name = "${local.short_prefix}-recordprocessor-repo"
7+
}
8+
9+
#TODO add lifecycle policy to manage images

infrastructure/instance/ecs_batch_processor_config.tf

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# Define the ECS Cluster
21
resource "aws_ecs_cluster" "ecs_cluster" {
32
name = "${local.short_prefix}-ecs-cluster"
43

@@ -11,33 +10,8 @@ resource "aws_ecs_cluster" "ecs_cluster" {
1110
}
1211
}
1312

14-
resource "aws_ecr_repository" "processing_repository" {
15-
image_scanning_configuration {
16-
scan_on_push = true
17-
}
18-
image_tag_mutability = "IMMUTABLE"
19-
name = "${local.short_prefix}-processing-repo"
20-
force_delete = local.is_temp
21-
}
22-
23-
resource "aws_ecr_lifecycle_policy" "processing_repository_policy" {
24-
repository = aws_ecr_repository.processing_repository.name
25-
policy = jsonencode({
26-
"rules" : [
27-
{
28-
"rulePriority" : 1,
29-
"description" : "Keep only the last 2 images",
30-
"selection" : {
31-
"tagStatus" : "any",
32-
"countType" : "imageCountMoreThan",
33-
"countNumber" : 2
34-
},
35-
"action" : {
36-
"type" : "expire"
37-
}
38-
}
39-
]
40-
})
13+
data "aws_ecr_repository" "recordprocessor_repository" {
14+
name = "${local.short_prefix}-recordprocessor-repo"
4115
}
4216

4317
# Define the IAM Role for ECS Task Execution
@@ -131,7 +105,7 @@ resource "aws_iam_policy" "ecs_task_exec_policy" {
131105
Action = [
132106
"ecr:GetAuthorizationToken"
133107
],
134-
Resource = "arn:aws:ecr:${var.aws_region}:${var.immunisation_account_id}:repository/${local.short_prefix}-processing-repo"
108+
Resource = "arn:aws:ecr:${var.aws_region}:${var.immunisation_account_id}:repository/${data.aws_ecr_repository_recordprocessor_repository.name}"
135109
},
136110
{
137111
"Effect" : "Allow",
@@ -171,7 +145,7 @@ resource "aws_ecs_task_definition" "ecs_task" {
171145

172146
container_definitions = jsonencode([{
173147
name = "${local.short_prefix}-process-records-container"
174-
image = "${aws_ecr_repository.processing_repository.repository_url}:${var.recordprocessor_image_tag}"
148+
image = "${data.aws_ecr_repository.recordprocessor_repository.repository_url}:${var.recordprocessor_image_tag}"
175149
essential = true
176150
environment = [
177151
{

0 commit comments

Comments
 (0)