Skip to content

Commit

Permalink
move docker authentication to infra
Browse files Browse the repository at this point in the history
  • Loading branch information
jdongo-aneo committed Nov 8, 2024
1 parent d4d2920 commit b95362d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
34 changes: 12 additions & 22 deletions infrastructure/quick-deploy/aws/ecr.tf
Original file line number Diff line number Diff line change
Expand Up @@ -87,27 +87,17 @@ locals {
default_tags = module.default_images.image_tags

#information for fluent-bit image retagging.
fluent_bit_repo_details = try(
[
for repo in local.ecr_repositories :
{
name = repo.name
tag = repo.tag
}
if repo.image == var.fluent_bit.image_name
][0],
null
)
fluent_bit_repository_name = local.fluent_bit_repo_details != null ? local.fluent_bit_repo_details.name : null
fluent_bit_image_tag = local.fluent_bit_repo_details != null ? local.fluent_bit_repo_details.tag : null

fluent_bit_repository_uri = data.aws_ecr_repository.fluent_bit.repository_url
region = data.aws_region.current.name
fluent_bit_repository_uri = [
for name, uri in module.ecr.repositories : uri
if can(regex("fluent-bit", name))
][0]
fluent_bit_image_tag = [
for name, details in local.repositories :
details.tag if can(regex("fluent-bit", details.image))
][0]
region = data.aws_region.current.name
}

data "aws_ecr_repository" "fluent_bit" {
name = local.fluent_bit_repository_name
}
data "aws_region" "current" {}

# Default tags for all images
Expand All @@ -120,20 +110,20 @@ module "default_images" {

module "ecr" {
source = "./generated/infra-modules/container-registry/aws/ecr"
aws_profile = var.profile
kms_key_id = local.kms_key
repositories = var.upload_images ? local.repositories : {}
encryption_type = var.ecr.encryption_type
tags = local.tags
}

#Temporary solution for image retagging while waiting for the muli-plateform image from fluent-bit: https://github.com/fluent/fluent-bit/issues/9509
resource "null_resource" "ecr_login_and_build" {
resource "generic_local_cmd" "build_fluent-bit_image" {
count = var.upload_images ? 1 : 0

provisioner "local-exec" {
# Command to log in to ECR and build the image
# build the muti-platform image in the registry
command = <<EOT
aws ecr get-login-password --profile ${var.profile} --region --region ${local.region} | docker login --username AWS --password-stdin ${local.fluent_bit_repository_uri}
docker buildx imagetools create ${local.fluent_bit_repository_uri}:${local.fluent_bit_image_tag} --tag ${local.fluent_bit_repository_uri}:${local.fluent_bit_image_tag} --append ${var.fluent_bit.image_name}:windows-2022-${local.fluent_bit_image_tag}
EOT
}
Expand Down
4 changes: 4 additions & 0 deletions infrastructure/quick-deploy/aws/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,9 @@ terraform {
source = "chilicat/pkcs12"
version = "~> 0.0.7"
}
generic = {
source = "aneoconsulting.github.io/aneoconsulting/generic"
version = "~> 0.1.0"
}
}
}

0 comments on commit b95362d

Please sign in to comment.