Skip to content

Instantly share code, notes, and snippets.

@thehackermonkey
Created September 30, 2020 16:21
Show Gist options
  • Save thehackermonkey/b458c87e3c02aea58b8d464d0dd89e50 to your computer and use it in GitHub Desktop.
Save thehackermonkey/b458c87e3c02aea58b8d464d0dd89e50 to your computer and use it in GitHub Desktop.
Build and upload docker image to ECR (aws cli 2.0.+)
organization = {YOUR_ORGANIZATION_PROFILE_NAME use 'default' if no multiple organizations}
ecr_id = {YOUR_AWS_ACCOUNT_ID}
project_name = {YOUR_ECR_PROJECT_NAME}
aws_region = {AWS_REGION}
git_sha = $(shell git rev-parse --short=8 HEAD)
docker-login:
$(aws --region $(aws_region) ecr get-login-password \
| docker login \
--password-stdin \
--username AWS \
$(ecr_id).dkr.ecr.$(aws_region).amazonaws.com)
@echo Logged in 🔑
docker-build:
@echo Building 🚀
docker build --target ${organization} -t $(organization)/$(project_name):$(git_sha) .
docker-tag:
@echo Tagging 🏷
docker tag $(organization)/$(project_name):$(git_sha) $(ecr_id).dkr.ecr.us-west-2.amazonaws.com/$(organization)/$(project_name):$(git_sha)
docker tag $(organization)/$(project_name):$(git_sha) $(ecr_id).dkr.ecr.us-west-2.amazonaws.com/$(organization)/$(project_name):latest
docker-push:
@echo Pushing 🚢
docker push $(ecr_id).dkr.ecr.us-west-2.amazonaws.com/$(organization)/$(project_name):$(git_sha)
docker push $(ecr_id).dkr.ecr.us-west-2.amazonaws.com/$(organization)/$(project_name):latest
echo Succeed ✅
docker-build-and-push: docker-login docker-build docker-tag docker-push
@thehackermonkey
Copy link
Author

Spent too much time looking for the login part using aws cli 2.0 + . Hope it helps someone out there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment