Skip to content

Commit 7e17235

Browse files
committed
Create ECR for Carbon and Other Updates
Why these changes are being introduced: The Carbon app introduces a few changes to our automated build process. There are changes in the shared workflows in the MIT Libraries .giuthub repository that reflect the automated build changes necessary for carbon. The changes in this repo update the Terraform Outputs to match the new input requirements of the shared workflows. As part of addressing the needs of the Carbon app, it made sense to consolidate the shared workflows by using a few conditional steps. The changes here continue that idea of consolidation with conditional text. How this addresses that need: * Create carbon_ecr.tf to buid the ECR repository for the Carbon app * Create three new template files for dev-build, stage-build, and prod-promote caller workflow outputs * Create one new template file for the Makefile output * Update the output resources for just the carbon ECR to use the new template files Side effects of this change: None. In fact, the only changes are changes to output values. This will not make any changes to the infrastructure in AWS. In the near future, we will need to update the Terraform Outputs to use the new templates and eventually remove the outdated templates once we have upgraded across our multiple repositories.
1 parent 9535000 commit 7e17235

File tree

7 files changed

+187
-0
lines changed

7 files changed

+187
-0
lines changed

.terraform.lock.hcl

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ then replace all the ssm parameter references for `oidc_arn` with `aws_iam_openi
7272
| Name | Source | Version |
7373
|------|--------|---------|
7474
| ecr\_alma\_webhook\_lambdas | ./modules/ecr | n/a |
75+
| ecr\_carbon | ./modules/ecr | n/a |
7576
| ecr\_dss | ./modules/ecr | n/a |
7677
| ecr\_geoserver | ./modules/ecr | n/a |
7778
| ecr\_geosolr | ./modules/ecr | n/a |
@@ -116,6 +117,10 @@ then replace all the ssm parameter references for `oidc_arn` with `aws_iam_openi
116117
| alma\_webhook\_lambdas\_makefile | Full contents of the Makefile for the alma-webhook-lambdas repo (allows devs to push to Dev account only) |
117118
| alma\_webhook\_lambdas\_prod\_promote\_workflow | Full contents of the prod-promote.yml for the alma-webhook-lambdas repo |
118119
| alma\_webhook\_lambdas\_stage\_build\_workflow | Full contents of the stage-build.yml for the alma-webhook-lambdas repo |
120+
| carbon\_dev\_build\_workflow | Full contents of the dev-build.yml for the carbon repo |
121+
| carbon\_makefile | Full contents of the Makefile for the carbon repo (allows devs to push to Dev account only) |
122+
| carbon\_prod\_promote\_workflow | Full contents of the prod-promote.yml for the carbon repo |
123+
| carbon\_stage\_build\_workflow | Full contents of the stage-build.yml for the carbon repo |
119124
| dss\_fargate\_dev\_build\_workflow | Full contents of the dev-build.yml for the dss repo |
120125
| dss\_fargate\_makefile | Full contents of the Makefile for the dss repo (allows devs to push to Dev account only) |
121126
| dss\_fargate\_prod\_promote\_workflow | Full contents of the prod-promote.yml for the dss repo |

carbon_ecr.tf

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
2+
# carbon containers
3+
# This is a standard ECR for an ECS with a Fargate launch type
4+
locals {
5+
ecr_carbon = "carbon-${var.environment}"
6+
}
7+
module "ecr_carbon" {
8+
source = "./modules/ecr"
9+
repo_name = "carbon"
10+
login_policy_arn = aws_iam_policy.login.arn
11+
oidc_arn = data.aws_ssm_parameter.oidc_arn.value
12+
environment = var.environment
13+
tfoutput_ssm_path = var.tfoutput_ssm_path
14+
tags = {
15+
app-repo = "carbon"
16+
}
17+
}
18+
19+
20+
## Outputs to Terraform Cloud for devs ##
21+
22+
## For carbon application repo and ECR repository
23+
# Outputs in dev
24+
output "carbon_dev_build_workflow" {
25+
value = var.environment == "prod" || var.environment == "stage" ? null : templatefile("${path.module}/files/dev-build.tpl", {
26+
region = var.aws_region
27+
role = module.ecr_carbon.gha_role
28+
ecr = module.ecr_carbon.repository_name
29+
function = ""
30+
}
31+
)
32+
description = "Full contents of the dev-build.yml for the carbon repo"
33+
}
34+
output "carbon_makefile" {
35+
value = var.environment == "prod" || var.environment == "stage" ? null : templatefile("${path.module}/files/makefile.tpl", {
36+
ecr_name = module.ecr_carbon.repository_name
37+
ecr_url = module.ecr_carbon.repository_url
38+
function = ""
39+
}
40+
)
41+
description = "Full contents of the Makefile for the carbon repo (allows devs to push to Dev account only)"
42+
}
43+
44+
# Outputs in stage
45+
output "carbon_stage_build_workflow" {
46+
value = var.environment == "prod" || var.environment == "dev" ? null : templatefile("${path.module}/files/stage-build.tpl", {
47+
region = var.aws_region
48+
role = module.ecr_carbon.gha_role
49+
ecr = module.ecr_carbon.repository_name
50+
function = ""
51+
}
52+
)
53+
description = "Full contents of the stage-build.yml for the carbon repo"
54+
}
55+
56+
# Outputs after promotion to prod
57+
output "carbon_prod_promote_workflow" {
58+
value = var.environment == "stage" || var.environment == "dev" ? null : templatefile("${path.module}/files/prod-promote.tpl", {
59+
region = var.aws_region
60+
role_stage = "${module.ecr_carbon.repo_name}-gha-stage"
61+
role_prod = "${module.ecr_carbon.repo_name}-gha-prod"
62+
ecr_stage = "${module.ecr_carbon.repo_name}-stage"
63+
ecr_prod = "${module.ecr_carbon.repo_name}-prod"
64+
function = ""
65+
}
66+
)
67+
description = "Full contents of the prod-promote.yml for the carbon repo"
68+
}

files/dev-build.tpl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
### This is the Terraform-generated dev-build.yml workflow for the ${ecr} app repository ###
2+
### If this is a Lambda repo, uncomment the FUNCTION line at the end of the document ###
3+
### If the container requires any additional pre-build commands, uncomment and edit ###
4+
### the PREBUILD line at the end of the document. ###
5+
name: Dev Container Build and Deploy
6+
on:
7+
workflow_dispatch:
8+
pull_request:
9+
branches:
10+
- main
11+
paths-ignore:
12+
- '.github/**'
13+
14+
jobs:
15+
deploy:
16+
name: Dev Container Deploy
17+
uses: mitlibraries/.github/.github/workflows/ecr-shared-deploy-dev.yml@main
18+
secrets: inherit
19+
with:
20+
AWS_REGION: "${region}"
21+
GHA_ROLE: "${role}"
22+
ECR: "${ecr}"
23+
# FUNCTION: "${function}"
24+
# PREBUILD:

files/makefile.tpl

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
### This is the Terraform-generated header for ${ecr_name}. If ###
2+
### this is a Lambda repo, uncomment the FUNCTION line below ###
3+
### and review the other commented lines in the document. ###
4+
ECR_NAME_DEV:=${ecr_name}
5+
ECR_URL_DEV:=${ecr_url}
6+
# FUNCTION_DEV:=${function}
7+
### End of Terraform-generated header ###
8+
9+
### Terraform-generated Developer Deploy Commands for Dev environment ###
10+
dist-dev: ## Build docker container (intended for developer-based manual build)
11+
docker build --platform linux/amd64 \
12+
-t $(ECR_URL_DEV):latest \
13+
-t $(ECR_URL_DEV):`git describe --always` \
14+
-t $(ECR_NAME_DEV):latest .
15+
16+
publish-dev: dist-dev ## Build, tag and push (intended for developer-based manual publish)
17+
docker login -u AWS -p $$(aws ecr get-login-password --region us-east-1) $(ECR_URL_DEV)
18+
docker push $(ECR_URL_DEV):latest
19+
docker push $(ECR_URL_DEV):`git describe --always`
20+
21+
### If this is a Lambda repo, uncomment the two lines below ###
22+
# update-lambda-dev: ## Updates the lambda with whatever is the most recent image in the ecr (intended for developer-based manual update)
23+
# aws lambda update-function-code --function-name $(FUNCTION_DEV) --image-uri $(ECR_URL_DEV):latest
24+
25+
26+
### Terraform-generated manual shortcuts for deploying to Stage. This requires ###
27+
### that ECR_NAME_STAGE, ECR_URL_STAGE, and FUNCTION_STAGE environment ###
28+
### variables are set locally by the developer and that the developer has ###
29+
### authenticated to the correct AWS Account. The values for the environment ###
30+
### variables can be found in the stage_build.yml caller workflow. ###
31+
dist-stage: ## Only use in an emergency
32+
docker build --platform linux/amd64 \
33+
-t $(ECR_URL_STAGE):latest \
34+
-t $(ECR_URL_STAGE):`git describe --always` \
35+
-t $(ECR_NAME_STAGE):latest .
36+
37+
publish-stage: ## Only use in an emergency
38+
docker login -u AWS -p $$(aws ecr get-login-password --region us-east-1) $(ECR_URL_STAGE)
39+
docker push $(ECR_URL_STAGE):latest
40+
docker push $(ECR_URL_STAGE):`git describe --always`
41+
42+
### If this is a Lambda repo, uncomment the two lines below ###
43+
# update-lambda-stage: ## Updates the lambda with whatever is the most recent image in the ecr (intended for developer-based manual update)
44+
# aws lambda update-function-code --function-name $(FUNCTION_STAGE) --image-uri $(ECR_URL_STAGE):latest

files/prod-promote.tpl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
### This is the Terraform-generated prod-promote.yml workflow for the ${ecr} app repository. ###
2+
### If this is a Lambda repo, uncomment the FUNCTION line at the end of the document ###
3+
name: Prod Container Promote
4+
on:
5+
workflow_dispatch:
6+
release:
7+
types: [published]
8+
9+
jobs:
10+
deploy:
11+
name: Prod Container Promote
12+
uses: mitlibraries/.github/.github/workflows/ecr-shared-promote-prod.yml@main
13+
secrets: inherit
14+
with:
15+
AWS_REGION: "${region}"
16+
GHA_ROLE_STAGE: ${role_stage}
17+
GHA_ROLE_PROD: ${role_prod}
18+
ECR_STAGE: "${ecr_stage}"
19+
ECR_PROD: "${ecr_prod}"
20+
# FUNCTION: "${function}"
21+

files/stage-build.tpl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
### This is the Terraform-generated dev-build.yml workflow for the ${ecr} app repository ###
2+
### If this is a Lambda repo, uncomment the FUNCTION line at the end of the document ###
3+
### If the container requires any additional pre-build commands, uncomment and edit ###
4+
### the PREBUILD line at the end of the document. ###
5+
name: Stage Container Build and Deploy
6+
on:
7+
workflow_dispatch:
8+
push:
9+
branches:
10+
- main
11+
paths-ignore:
12+
- '.github/**'
13+
14+
jobs:
15+
deploy:
16+
name: Stage Container Deploy
17+
uses: mitlibraries/.github/.github/workflows/ecr-shared-deploy-stage.yml@main
18+
secrets: inherit
19+
with:
20+
AWS_REGION: "${region}"
21+
GHA_ROLE: "${role}"
22+
ECR: "${ecr}"
23+
# FUNCTION: "${function}"
24+
# PREBUILD:

0 commit comments

Comments
 (0)