Set up an ECR Repository

This document describes how to create a new Amazon ECR (Elastic Container Registry) repository in the AWS Shared account using the BYM-IKT/SharedKontoInfrastruktur repository.

An ECR repository is used to store container images so that containerized applications can be deployed to AWS.

Prerequisites

Note

Step 2b must be performed in an environment that supports symbolic links.

Steps

Step 1. Clone the repository

git clone git@github.com:BYM-IKT/SharedKontoInfrastruktur.git
cd SharedKontoInfrastruktur

Step 2. Verify application folder

Check if the following folder exists:

./Shared/<application-name>/

  • If the folder exists, continue to step 3.
  • If the folder does not exist, follow the steps below.

Step 2a — Copy the Example Template

cd Shared
cp -a eksempel/<application-name>

Step 2b — Rename Terraform Template Files

Navigate to:

./Shared/<application-name>/eu-west-1/ecr/
Rename the files:

From To
main.tfignore main.tf
state.tfignore state.tf

Step 2c — Replace Template Name

Replace all occurrences of the word eksempel with <application-name> in the following files:

- ./Shared/<application-name>/eu-west-1/environment.tf

- ./Shared/<application-name>/eu-west-1/ecr/main.tf

- ./Shared/<application-name>/eu-west-1/ecr/state.tf

Expected Folder Structure

Shared/
└── <application-name>/         Renamed folder
    └── eu-west-1/
        ├── ecr/
           ├── main.tf        Renamed and edited
           ├── state.tf       Renamed and edited
           └── ...
        └── environment.tf     Edited

Step 3. Define the ECR Repository Name

Open:

./Shared/<application-name>/eu-west-1/ecr/main.tf
In the locals block, add the desired ECR repository name to the list:
./Shared/kattehotell/eu-west-1/ecr/main.tf
1
2
3
4
5
6
locals {
  kattehotell_repos = toset([
    ...
    "api",
  ])
}

Step 4. Create a Pull Request

  1. Create a new branch

  2. Commit your changes

  3. Push the branch

  4. Create a Pull Request to master

Step 5. Merge to Master

After the Pull Request is merged into master, the ECR repository will be automatically created.

Result

The ECR repository will be available at:

<Shared-account-id>.dkr.ecr.eu-west-1.amazonaws.com/<repo-name>