Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Target ECR registry by Account ID and Region #20

Merged
merged 5 commits into from May 26, 2020

Conversation

HenryCook
Copy link
Contributor

@HenryCook HenryCook commented May 22, 2020

Background

We're looking to build and push our Docker images to the account where our ECR repositories reside, which are then shared across multiple accounts.

The region we use is the same across all accounts however where we build images is different to where we store them.

Ideally I wouldn't be touching on the region however it's required by get-login-password.

Changes

  • Now using get-login-password command, due to get-login being deprecated
  • Ability to target registries by Account ID
  • Ability to set region for registry that is being targeted

Example

steps:
  - label: "Building and pushing image to ECR :docker:"
    plugins:
      - henrycook/docker-ecr-publish#v1.5.0:
          ecr-name: my-repo
          account_id: 12345678910
          region: eu-west-1
          tags: ${BUILDKITE_COMMIT}

Notes

This may introduce a breaking change in regards to the region changes as I couldn't think of a sane way to handle this. Open to ideas on potential nicer ways to handle this.

If the get-login command wasn't being deprecated we wouldn't have to amend the region, however it seems this has been requested already (#14).

For our use case we store all of our ECR repositories in a single
account, and access these repos from others. Therefore we require the
need to specify the account which possess the repostories, along with
the region.

The region wasn't a necessary change however I have seen others
requesting this and it was an easy implementation alongside this work.
Reason for this is because when trying to grab the region via the means
previously implemented it was unsuccessful on a Buildkite agent running
on EC2.

As we have changed to using `get-login-password` due to the previous
implementation being deprecated, it requires the region as well as the
account id to be given as part of the docker login command.

Ideally I would leave the region out of these changes entirely.

If nothing is given both via the `region` flag or `AWS_DEFAULT_REGION`
env var, it will default to `eu-west-1`.
Copy link
Member

@72636c 72636c left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, sorry it took me a while to get to it!

local region="${1}"
local account_id="${2}"

aws ecr get-login-password \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

README.md Outdated Show resolved Hide resolved
@HenryCook
Copy link
Contributor Author

Thanks for the PR, sorry it took me a while to get to it!

Not a problem, thank you for giving it a once over.

@72636c
Copy link
Member

72636c commented May 26, 2020

This may introduce a breaking change in regards to the region changes as I couldn't think of a sane way to handle this. Open to ideas on potential nicer ways to handle this.

I'm releasing this as v2.0.0. I had a squiz too and AWS_DEFAULT_REGION looks like the best we can do; I had no luck with aws configure get region.

@72636c 72636c merged commit 7753017 into seek-oss:master May 26, 2020
@72636c 72636c mentioned this pull request May 26, 2020
@ouranos
Copy link
Contributor

ouranos commented Jul 14, 2020

I think this breaks the cache_from feature with the ecr:// shortand as this line doesn't specify the account nor the region causing "unbound variable" errors.

@ouranos
Copy link
Contributor

ouranos commented Jul 15, 2020

Patched in #21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants