Skip to content

Instantly share code, notes, and snippets.

@ludwig
Forked from miguelmota/Makefile
Created June 19, 2023 21:56
Show Gist options
  • Save ludwig/7c6347e8ebbe2fc4df13f2bfdbac25c5 to your computer and use it in GitHub Desktop.
Save ludwig/7c6347e8ebbe2fc4df13f2bfdbac25c5 to your computer and use it in GitHub Desktop.
Makefile docker push to AWS Elastic Container Registry (ECR)
# Login to AWS registry (must have docker running)
docker-login:
$$(aws ecr get-login --no-include-email --region us-east-1 --profile=mycompany)
# Build docker target
docker-build:
docker build -f Dockerfile --no-cache -t mycompany/myapp .
# Tag docker image
docker-tag:
$(eval REV=$(shell git rev-parse HEAD | cut -c1-7))
docker tag mycompany/myapp:latest 123.dkr.ecr.us-east-1.amazonaws.com/mycompany/myapp:latest
docker tag mycompany/myapp:latest 123.dkr.ecr.us-east-1.amazonaws.com/mycompany/myapp:$(REV)
# Push to registry
docker-push:
$(eval REV=$(shell git rev-parse HEAD | cut -c1-7))
docker push 123.dkr.ecr.us-east-1.amazonaws.com/mycompany/myapp:latest
docker push 123.dkr.ecr.us-east-1.amazonaws.com/mycompany/myapp:$(REV)
# Build docker image and push to AWS registry
docker-build-and-push: docker-login docker-build docker-tag docker-push 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment