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

feat(docker): authenticate using DockerHub credentials #2548

Merged
merged 1 commit into from
Jan 28, 2021
Merged

feat(docker): authenticate using DockerHub credentials #2548

merged 1 commit into from
Jan 28, 2021

Conversation

hutson
Copy link
Contributor

@hutson hutson commented Jan 25, 2021

Ubuntu builds, by default, pull images anonymously from the
official DockerHub. DockerHub rate limits requests from
anonymous and unpaid accounts:

When those rate limits are reached the Packer build will
fail with an error indicated the rate limit has been
reached.

Add support for providing credentials for a paid
account that can be used by the Docker setup steps to
authenticate when pulling images from DockerHub, thereby
avoiding the rate limit.

Related to #2094

"type": "shell",
"scripts": [
"{{template_dir}}/scripts/installers/docker-compose.sh",
"{{template_dir}}/scripts/installers/docker-moby.sh"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I intentionally moved these scripts into their own provisioner block so that the DockerHub credentials were not exposed to any other unrelated setup scripts.

# Always attempt to logout so we do not leave our credentials on the built image.
docker logout
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In my testing docker logout will not return a non-zero exit code even if you never logged into DockerHub. Therefore I believe it's safe/safer to always call it in this script.

@hutson
Copy link
Contributor Author

hutson commented Jan 25, 2021

This PR only adds support for Ubuntu. My team only works with Ubuntu at the moment, so we're only focused on getting authentication working for that use case. In the future we will look into ensuring this works for Windows builds.

@AlenaSviridenko
Copy link
Contributor

AlenaSviridenko commented Jan 26, 2021

Hi @hutson!
Thank you for contriubution, we don't mind accepting these changes for Ubuntu and later for Windows. Please, pull latest main changes, we merged a fix for broken cargo installation here #2545, and I will run checks to validate your PR. Nevermind, cargo fixed this issue on their side, will run checks now. Nope, they didn't fixed that, sorry. Please, pull the latest main

@AlenaSviridenko
Copy link
Contributor

/azp run ubuntu1604, ubuntu1804, ubuntu2004

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

Ubuntu builds, by default, pull images anonymously from the
official DockerHub. DockerHub rate limits requests from
anonymous and unpaid accounts:
- https://docs.docker.com/docker-hub/download-rate-limit/

When those rate limits are reached the Packer build will
fail with an error indicated the rate limit has been
reached.

Add support for providing credentials for a paid
account that can be used by the Docker setup steps to
authenticate when pulling images from DockerHub, thereby
avoiding the rate limit.

Related to #2094
@hutson
Copy link
Contributor Author

hutson commented Jan 26, 2021

Pull request has been rebased on top of the latest from main.

@AlenaSviridenko AlenaSviridenko merged commit 46e0c05 into actions:main Jan 28, 2021
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.

4 participants