Skip to content

Commit 81c4599

Browse files
committed
Adding CHANGELOG and making profile optional
1 parent 71309a7 commit 81c4599

File tree

6 files changed

+36
-17
lines changed

6 files changed

+36
-17
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Changelog
2+
3+
## 0.0.2
4+
5+
Made provision of AWS profile credential optional. If not specified the awscli will look for credentials in order from the [usual sources](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html).
6+
7+
## 0.0.1
8+
9+
Initial release of ecs-mirror module

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,24 @@ In late 2020, Docker Hub announced that the Hub service would begin limiting the
77

88
The [AWS recommendation](https://aws.amazon.com/blogs/containers/advice-for-customers-dealing-with-docker-hub-rate-limits-and-a-coming-soon-announcement/) for those not wishing to upgrade to a paid plan is to mirror the Dockerhub image to their own AWS ECR repository.
99

10-
This simple task requires a basic 'pull from Dockerhub-push to ECR' loop for which there exists no good bootstrapping solution (outside of a convolution such as a CodeBuild pipeline) for a new ECR repository that would look to use a Dockerhub image as its 'base' image which can then be used in subsequent builds without the pull limits.
10+
This simple task requires a basic 'pull from Dockerhub-push to ECR' loop for which there exists no simple bootstrapping solution. The typical use case is a new ECR repository that would look to use a Dockerhub image as its 'base' image which can then be used in subsequent builds without the pull limits.
1111

1212
This module is a simple terraform `local-exec` provisioner which runs the required awscli and docker push commands to ECR, and can be woven in to your existing set-up.
1313

1414
## Requirements
1515

16-
- aws-cli installed and configured with a named [profile](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html) that has permissions to push to the desired ECR repository
16+
- aws-cli v2 installed and configured with a named [profile](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html) that has permissions to push to the desired ECR repository
1717
- [Docker installed](https://docs.docker.com/engine/install/) on the machine executing terraform, and permissions for the user executing terraform to run docker commands (e.g. by adding the user to the 'docker' user group)
1818

19+
## Idempotence
20+
21+
As this module is essentially running a series of bash commands, it ensures idempotence by triggering only when any of the values of the `docker_source`, `ecr_repo_name` or `ecr_repo_tag` variables are changed.
22+
1923
## Usage Example
2024

2125
```
2226
module "ecr_mirror" {
23-
source = "./docker_init"
27+
source = "TechToSpeech/terraform-aws-ecr-mirror.git"
2428
aws_account_id = "123456544225"
2529
aws_region = "eu-west-1"
2630
docker_source = "wordpress:php7.4-apache"

docker_pullpush.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1+
#!/bin/bash
2+
3+
if [[ ${#6} -gt 0 ]]; then
4+
profile="--profile $6"
5+
fi
6+
17
docker pull $1
2-
aws ecr get-login-password --region $2 --profile $4 | docker login --username AWS --password-stdin $3.dkr.ecr.$2.amazonaws.com
3-
docker tag $1 $3.dkr.ecr.eu-west-1.amazonaws.com/$5:$6
4-
docker push $3.dkr.ecr.eu-west-1.amazonaws.com/$5:$6
8+
aws ecr get-login-password --region $2 $profile | docker login --username AWS --password-stdin $3.dkr.ecr.$2.amazonaws.com
9+
docker tag $1 $3.dkr.ecr.eu-west-1.amazonaws.com/$4:$5
10+
docker push $3.dkr.ecr.eu-west-1.amazonaws.com/$4:$5

main.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
resource "null_resource" "docker_pullpush" {
2+
3+
triggers = {
4+
shell_hash = sha256("${var.docker_source}${var.ecr_repo_name}${var.ecr_repo_tag}")
5+
}
6+
provisioner "local-exec" {
7+
command = "${abspath(path.module)}/docker_pullpush.sh ${var.docker_source} ${var.aws_region} ${var.aws_account_id} ${var.ecr_repo_name} ${var.ecr_repo_tag} ${var.aws_profile}"
8+
}
9+
}

main.tf.tf

Lines changed: 0 additions & 10 deletions
This file was deleted.

variables.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ variable "aws_account_id" {
1111
}
1212

1313
variable "aws_profile" {
14-
description = "The awscli profile name (located in the ~/.aws/credentials file) used to authenticate the ECR login and push."
14+
description = "The awscli profile name (located in the ~/.aws/credentials file) used to authenticate the ECR login and push (Optional)"
15+
default = ""
1516
}
1617

1718
variable "ecr_repo_name" {

0 commit comments

Comments
 (0)