christian-korneck / docker-pushrm

"Docker Push Readme" - a Docker CLI plugin to update container repo docs
MIT License
138 stars 4 forks source link

[Problem] On GitLab, Docker unauthorised me to login although I don't have access token and don't enable 2FA auth #20

Closed gusbemacbe closed 2 years ago

gusbemacbe commented 2 years ago

Describe the problem or bug

docker-pushrm version check version with:

Docker CLI version and platform

Log:

Using Docker executor with image chko/docker-pushrm ...
Pulling docker image chko/docker-pushrm ...
Using docker image sha2[5](https://gitlab.com/gusbemacbe/complete-linux/-/jobs/2678886371#L5)[6](https://gitlab.com/gusbemacbe/complete-linux/-/jobs/2678886371#L6):593581420f9c4bde08e0bd193118f1a133eebd7f4ea294cdadc7219479b39cf2 for chko/docker-pushrm with digest chko/docker-pushrm@sha256:17ec64bbd0b25a6e1a698384691b543823de3303a625d8225df19073b2d72bc7 ...
#  ...
level=debug msg="root cmd init config"
level=debug msg="home dir: /home"
level=debug msg="subcommand \"pushrm\" called"
level=debug msg="Using target: docker.io/gusbemacbe/complete-alpine:latest"
level=debug msg="using README file: /builds/gusbemacbe/complete-linux/complete-alpine/README.md"
level=debug msg="server: docker.io"
level=debug msg="namespace: gusbemacbe"
level=debug msg="repo: complete-alpine"
level=debug msg="tag: latest"
level=debug msg="repo provider: dockerhub"
level=debug msg="Dockerhub.GetAuthident called"
level=debug msg="using credentials for user gusbemacbe from generic env var"
level=debug msg="Using Docker creds: gusbemacbe ********"
level=debug msg="Dockerhub.Pushrm called"
level=debug msg="retrieve Dockerhub jwt token, status code: 401"
level=debug msg="error retrieving Dockerhub jwt token, bad status code for response: 401 Unauthorized"
level=error msg="error trying to get a JWT token from Dockerhub for the stored Docker login. Try \"docker logout\" and \"docker login\". Also, if you have 2FA auth enabled in Dockerhub you'll need to disable it for this tool to work. (This is an unfortunate Dockerhub limitation, see docs for more infos). "
Cleaning up project directory and file based variables
00:01
ERROR: Job failed: exit code 1
christian-korneck commented 2 years ago

hi @gusbemacbe I copied your .gitlab-ci.yml, reduced it to the relevant parts, made some smaller changes, ran it in gitlab it seems to be working. I assume there are some flaws leading to empty variables or so.

This works for me: (you can ignore the build step- that's just for building and pushing a dummy image and printing some stuff for debugging. The complete-alpine part is the relevant one, which I copied from your file and modified it.)

gitlab-ci.yml :

stages:
- build
- release

docker-build:
  image: docker:latest
  stage: build
  services:
    - docker:dind
  before_script:
    - docker login -u "$DOCKER_HUB_LOGIN" -p "$DOCKER_HUB_PASSWORD"
  script:
    - docker build -t "docker.io/$DOCKER_HUB_LOGIN/test228:latest" .
    - docker push "docker.io/$DOCKER_HUB_LOGIN/test228:latest"
    - echo ------1-------
    - echo $DOCKER_HUB_PASSWORD
    - echo ------2-------
    - echo $DOCKER_HUB_LOGIN
    - echo ------3-------
    - echo $DOCKER_HUB_PASSWORD | wc -m

complete-alpine:
  stage: release
  image:
    name: chko/docker-pushrm
    entrypoint: ["/bin/sh", "-c", "/docker-pushrm"]
  variables:
    DOCKER_USER: $DOCKER_HUB_LOGIN
    DOCKER_PASS: $DOCKER_HUB_PASSWORD
    PUSHRM_TARGET: docker.io/$DOCKER_USER/test228
    PUSHRM_SHORT: hello short description
    PUSHRM_FILE: $CI_PROJECT_DIR/README.md
    PUSHRM_DEBUG: 1
  script: "/bin/true"

and on the gitlab project these CI variables are defined:

image

and that's the result (success):

image

Hope this helps.

gusbemacbe commented 2 years ago

Your new GitLab CI config worked now. Thank you!

image