build-push-action: Not worked with ECR actions
After ECR login action, can pull and push images from ECR repository on run docker command directly.
Maybe it required to support local ~/.docker/config.json
But cannot pull and push on docker/build-push-action caused by no basic auth credentials error.
My workflow is
build_and_push_image:
name: Build and push docker image to ECR.
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v2
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: **********
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Pull from ECR (pull test)
run: docker pull ${{ steps.login-ecr.outputs.registry }}/${{ secrets.REGISTRY }}:latest
- name: Debug auth (pull test)
run: cat ~/.docker/config.json
- name: Build & Push
uses: docker/build-push-action@v1
with:
repository: ${{ steps.login-ecr.outputs.registry }}/${{ secrets.REGISTRY }}
add_git_labels: true
tag_with_ref: true
- name: Logout of Amazon ECR
if: always()
run: docker logout ${{ steps.login-ecr.outputs.registry }}
Successfully pull on command line: Pull from ECR (pull test)
Pull from ECR (pull test)6s
***.dkr.ecr.us-east-1.amazonaws.com/***:latest
...
18ebb058d5da: Pull complete
Digest: sha256:ac4754ea1154010603db8d7cbe07bb1a33954e59b088efab46445c69d8b0fc58
Status: Downloaded newer image for ***.dkr.ecr.us-east-1.amazonaws.com/***:latest
***.dkr.ecr.us-east-1.amazonaws.com/***:latest
Logged in to ECR: Debug auth (pull test)
Run cat ~/.docker/config.json
{
"auths": {
"***.dkr.ecr.us-east-1.amazonaws.com": {
"auth": "***"
}
},
"HttpHeaders": {
"User-Agent": "Docker-Client/3.0.11+azure (linux)"
}
}
Failed to push or pull on docker/build-push-action@v1
...
Successfully built a60891a407a2
Successfully tagged ***.dkr.ecr.us-east-1.amazonaws.com/***:topic-use_original_docker_actions
Pushing image [***.dkr.ecr.us-east-1.amazonaws.com/***:topic-use_original_docker_actions]
The push refers to repository [***.dkr.ecr.us-east-1.amazonaws.com/***]
no basic auth credentials
Error: exit status 1
Usage:
github-actions build-push [flags]
Flags:
-h, --help help for build-push
exit status 1
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 19
- Comments: 23 (5 by maintainers)
I haven’t been able to get this to work for me. I’m trying to use ECR as the cache repo of my multi-stage docker build. I’m not doing a push to the repo in this step, that happens later (…although I could change that if it makes it easier). I’ve been trying to use snippets from this thread as a guide but with no luck. I tried the following:
This gave me the error
Unexpected input(s) 'registry', 'repository', valid inputs are [<lotsofthings>]and ultimately a401: authorization failederror.Going by the error and since I couldn’t find mention of the
registryorrepositoryin the documentation for thedocker/build-push-action@v2action, I removed those inputs and tried moving them to the cache-to/from parameters instead, like so:This gave me a 400 bad request error:
buildx failed with: error: failed to solve: error writing manifest blob: failed commit on ref "sha256:66ce855480d97b26457d6639cd3542ee6d8b0959e81d372111829f3aedd31a6e": unexpected status: 400 Bad RequestI’ve not been able to find any other documentation/examples of how to use ECR for the build cache. Can someone point me to where I’m going wrong?
It’s my temporary solution.
@Surgo
Be careful, inputs have changed in v2. See Usage section and also this workflow as an example.
Great!
+1 on the issue - I’m having an analogous problem with digitalocean’s container registry: this configuration doesn’t work (nor variants with dummy credentials do):
login succeeds in its own step, then build-push-action doesn’t pick up the existing login. while, analogous to suggested workarounds, this works:
yes, this has nothing do to with ECR - but to me it looks like the same underlying problem of not picking up existing logins. (ofc please lmk if I’m completely mistaken and this is out of place in this issue)
A full example with ECR would be great! I’ve tried both:
and
First gave me a
401 Unauthorizedand the second gave meinsufficient_scope: authorization failedat the end of the docker image building (all layers completed).v2 released 🎉
@Surgo You should be able to use the ECR action with our future build-push-action v2 (#92). Can you try it? You can also use the login-action which works perfectly for ECR (both for AWS CLI v1 and v2 on the
ubuntu-20.04GitHub runner).Here’s a slightly improved version of the workaround. It fixes: