Skip to content

Commit 5d63b17

Browse files
committed
feat: push image to ecr
1 parent bb09cb2 commit 5d63b17

File tree

4 files changed

+83
-0
lines changed

4 files changed

+83
-0
lines changed

tf-module/ds_img_to_ecr/ecr1.tf

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
provider "aws" {
2+
region = var.aws_region
3+
4+
ignore_tags {
5+
key_prefixes = ["gsfc-ngap"]
6+
}
7+
}
8+
data "aws_caller_identity" "current" {}
9+
10+
locals {
11+
account_id = data.aws_caller_identity.current.account_id
12+
}
13+
14+
15+
resource "aws_ecr_repository" "repo" {
16+
name = var.ecr_repo_name
17+
image_tag_mutability = "IMMUTABLE"
18+
encryption_configuration {
19+
encryption_type = "AES256"
20+
}
21+
}
22+
23+
output "ecr_repo_url" {
24+
value = aws_ecr_repository.repo.repository_url
25+
}
26+
27+
resource "null_resource" "docker_pull_push" {
28+
provisioner "local-exec" {
29+
command = <<EOT
30+
aws ecr get-login-password --region ${var.aws_region} | docker login --username AWS --password-stdin ${aws_ecr_repository.repo.repository_url}
31+
docker pull --platform=linux/amd64 ${var.github_image_url}:${var.image_tag}
32+
docker tag ${var.github_image_url}:${var.image_tag} ${aws_ecr_repository.repo.repository_url}:${var.image_tag}
33+
docker push ${aws_ecr_repository.repo.repository_url}:${var.image_tag}
34+
EOT
35+
}
36+
depends_on = [aws_ecr_repository.repo]
37+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
terraform {
2+
backend "s3" {
3+
region = "us-west-2"
4+
bucket = "am-uds-dev-cumulus-tf-state"
5+
key = "am-uds-dev-cumulus/ds_img_to_ecr/unity/terraform.tfstate"
6+
dynamodb_table = "am-uds-dev-cumulus-tf-locks"
7+
}
8+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
tags = {
2+
Venue = "venue-dev",
3+
ServiceArea = "ds",
4+
CapVersion = "18.0.0"
5+
Component = "Cumulus",
6+
Proj = "Unity",
7+
CreatedBy = "ds",
8+
Env = "venue-dev",
9+
Stack = "Cumulus"
10+
}
11+
aws_region = "us-west-2"
12+
image_tag="9.6.0"
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
variable "aws_region" {
2+
type = string
3+
default = "us-west-2"
4+
}
5+
variable "tags" {
6+
description = "Tags to be applied to Cumulus resources that support tags"
7+
type = map(string)
8+
default = {}
9+
}
10+
11+
variable "github_image_url" {
12+
description = "The full URL of the public Docker image on GitHub (e.g., ghcr.io/user/repo)"
13+
default = "ghcr.io/unity-sds/unity-data-services"
14+
type = string
15+
}
16+
17+
variable "image_tag" {
18+
description = "The tag of the image to pull from GitHub"
19+
type = string
20+
}
21+
22+
variable "ecr_repo_name" {
23+
description = "The name of the ECR repository"
24+
default = "unity-data-services"
25+
type = string
26+
}

0 commit comments

Comments
 (0)