- Docker on Amazon Web Services
- Justin Menga
- 260字
- 2025-02-17 05:10:19
Automating login and logout
The following example demonstrates adding a couple of new tasks called login and logout, which will perform these actions using the Docker client:
.PHONY: test release clean version login logout
export APP_VERSION ?= $(shell git rev-parse --short HEAD)
version:
@ echo '{"Version": "$(APP_VERSION)"}'
login:
$$(aws ecr get-login --no-include-email)
logout:
docker logout https://385605022855.dkr.ecr.us-east-1.amazonaws.com
test:
docker-compose build --pull release
docker-compose build
docker-compose run test
release:
docker-compose up --abort-on-container-exit migrate
docker-compose run app python3 manage.py collectstatic --no-input
docker-compose up --abort-on-container-exit acceptance
@ echo App running at http://$$(docker-compose port app 8000 | sed s/0.0.0.0/localhost/g)
clean:
docker-compose down -v
docker images -q -f dangling=true -f label=application=todobackend | xargs -I ARGS docker rmi -f ARGS
Logging in and logging out of ECR
Notice that the login task uses a double dollar sign ($$), which is required as Make uses single dollar signs to define Make variables. When you specify a double dollar sign, Make will pass a single dollar sign to the shell, which in this case will ensure a bash command substitution is executed.
When logging out with the logout task, notice that you need to specify the Docker registry, otherwise the Docker client assumes the default public Docker Hub registry.
With these tasks in place, you can now easily log out and log in of ECR using the make logout and make login commands:
> make logout
docker logout https://385605022855.dkr.ecr.us-east-1.amazonaws.com
Removing login credentials for 385605022855.dkr.ecr.us-east-1.amazonaws.com
> make login
$(aws ecr get-login --no-include-email)
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
Login Succeeded
Running make logout and make login