Last active
June 11, 2024 00:17
-
-
Save miguelmota/c13bd2f5cc5493c82689c40117846571 to your computer and use it in GitHub Desktop.
Makefile docker push to AWS Elastic Container Registry (ECR)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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
I ended up with this Makefile, which uses get-login-password and uses variables to reduce duplication: