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

Building images in parallel and pushing them to Docker Hub results in premature logout #141

Open
huyz opened this issue Feb 1, 2023 · 1 comment
Labels

Comments

@huyz
Copy link
Contributor

huyz commented Feb 1, 2023

Overview of the Issue

When I'm building 3 different images in parallel and pushing them to Docker Hub, the first one to complete will do a docker logout causing errors in the other 2 pushes.

Reproduction Steps

  1. Build 3 images in parallel
  2. Push them to Docker Hub

Plugin and Packer version

Packer v1.8.5
Docker plugin v1.0.8

Simplified Packer Buildfile

# Common config to be shared among multiple sources
source "docker" "ubuntu" {
   …
}

build {
  …
  dynamic "source" {
    for_each = ["ubuntu:22.04", "ubuntu:20.04", "ubuntu:18.04"]
    labels   = ["docker.ubuntu"]
    content {
      name  = source.value
      image = source.value
    }
  }
  …

  post-processors {
    post-processor "docker-tag" {
      repository = format("%s-%s", var.docker_repo_base, split(":", source.name)[0])
      tags = [split(":", source.name)[1]]
    }
    post-processor "docker-push" {
      login          = true
      login_username = var.docker_username
      login_password = var.docker_password
    }
  }
}

Operating system and Environment details

Log Fragments and crash.log files

See the 2 denied: requested access to the resource is denied below:

==> ansible-molecule.docker.ubuntu:20.04: Running post-processor:  (type docker-tag)
    ansible-molecule.docker.ubuntu:20.04 (docker-tag): Tagging image: sha256:67aaf5e084e8be28acf2f7382d25cc3fb9a252cf8a4477fc84229e20805e7fd2
    ansible-molecule.docker.ubuntu:20.04 (docker-tag): Repository: huyz/ansible-molecule-ubuntu:20.04
==> ansible-molecule.docker.ubuntu:20.04: Running post-processor:  (type docker-push)
    ansible-molecule.docker.ubuntu:20.04 (docker-push): Creating temporary Docker configuration directory
    ansible-molecule.docker.ubuntu:20.04 (docker-push): Logging in...
    ansible-molecule.docker.ubuntu:18.04:     Running setup.py install for ansible: finished with status 'done'
    ansible-molecule.docker.ubuntu:20.04 (docker-push): Login Succeeded
    ansible-molecule.docker.ubuntu:20.04 (docker-push): Pushing: huyz/ansible-molecule-ubuntu:20.04
    ansible-molecule.docker.ubuntu:20.04 (docker-push): The push refers to repository [docker.io/huyz/ansible-molecule-ubuntu]
==> ansible-molecule.docker.ubuntu:18.04: Committing the container
    ansible-molecule.docker.ubuntu:20.04 (docker-push): 56fc03fd05e4: Layer already exists
==> ansible-molecule.docker.ubuntu:18.04: Running post-processor:  (type docker-tag)
    ansible-molecule.docker.ubuntu:18.04 (docker-tag): Tagging image: sha256:2f18df89a8c6a144a353ef73149a422364abcf1b8c06cdaa494cc056f14dbf84
    ansible-molecule.docker.ubuntu:18.04 (docker-tag): Repository: huyz/ansible-molecule-ubuntu:18.04
==> ansible-molecule.docker.ubuntu:18.04: Running post-processor:  (type docker-push)
    ansible-molecule.docker.ubuntu:18.04 (docker-push): Creating temporary Docker configuration directory
    ansible-molecule.docker.ubuntu:18.04 (docker-push): Logging in...
    ansible-molecule.docker.ubuntu:18.04 (docker-push): Login Succeeded
    ansible-molecule.docker.ubuntu:18.04 (docker-push): Pushing: huyz/ansible-molecule-ubuntu:18.04
    ansible-molecule.docker.ubuntu:18.04 (docker-push): The push refers to repository [docker.io/huyz/ansible-molecule-ubuntu]
    ansible-molecule.docker.ubuntu:18.04 (docker-push): 6b47c5c1f372: Preparing
    ansible-molecule.docker.ubuntu:18.04 (docker-push): a56e9bd192dc: Preparing
    ansible-molecule.docker.ubuntu:18.04 (docker-push): a56e9bd192dc: Layer already exists
    ansible-molecule.docker.ubuntu:20.04 (docker-push): 4ef07da5ca01: Pushed
    ansible-molecule.docker.ubuntu:20.04 (docker-push): 20.04: digest: sha256:ed4ad017978da4af4d148a0652b2964b0dc0d8f80fb18781d1ad04b29cc5f7d3 size: 742
    ansible-molecule.docker.ubuntu:20.04 (docker-push): Pushing: huyz/ansible-molecule-ubuntu:20.04
    ansible-molecule.docker.ubuntu:20.04 (docker-push): The push refers to repository [docker.io/huyz/ansible-molecule-ubuntu]
    ansible-molecule.docker.ubuntu:20.04 (docker-push): 4ef07da5ca01: Preparing
    ansible-molecule.docker.ubuntu:20.04 (docker-push): 56fc03fd05e4: Preparing
    ansible-molecule.docker.ubuntu:20.04 (docker-push): 56fc03fd05e4: Layer already exists
    ansible-molecule.docker.ubuntu:20.04 (docker-push): 4ef07da5ca01: Layer already exists
    ansible-molecule.docker.ubuntu:20.04 (docker-push): 20.04: digest: sha256:ed4ad017978da4af4d148a0652b2964b0dc0d8f80fb18781d1ad04b29cc5f7d3 size: 742
    ansible-molecule.docker.ubuntu:20.04 (docker-push): Logging out...
    ansible-molecule.docker.ubuntu:20.04 (docker-push): Removing login credentials for https://index.docker.io/v1/
    ansible-molecule.docker.ubuntu:20.04 (docker-push): Removing temporary Docker configuration directory
Build 'ansible-molecule.docker.ubuntu:20.04' finished after 5 minutes 50 seconds.
    ansible-molecule.docker.ubuntu:18.04 (docker-push): 6b47c5c1f372: Pushed
    ansible-molecule.docker.ubuntu:22.04 (docker-push): 1cdb0b846b12: Pushed
    ansible-molecule.docker.ubuntu:18.04 (docker-push): 18.04: digest: sha256:2c5886599443533a38665f1b60097a4aca09650d3a26228fd507227ad9d7e7f4 size: 742
    ansible-molecule.docker.ubuntu:18.04 (docker-push): Pushing: huyz/ansible-molecule-ubuntu:18.04
    ansible-molecule.docker.ubuntu:18.04 (docker-push): The push refers to repository [docker.io/huyz/ansible-molecule-ubuntu]
    ansible-molecule.docker.ubuntu:18.04 (docker-push): 6b47c5c1f372: Preparing
    ansible-molecule.docker.ubuntu:18.04 (docker-push): a56e9bd192dc: Preparing
    ansible-molecule.docker.ubuntu:18.04 (docker-push): a56e9bd192dc: Layer already exists
    ansible-molecule.docker.ubuntu:18.04 (docker-push): 6b47c5c1f372: Layer already exists
    ansible-molecule.docker.ubuntu:22.04 (docker-push): 22.04: digest: sha256:a667935e0b50c68ee8f8ff652b30d2144ec6c0199a9294160f95557b98a67436 size: 742
    ansible-molecule.docker.ubuntu:22.04 (docker-push): Pushing: huyz/ansible-molecule-ubuntu:22.04
    ansible-molecule.docker.ubuntu:22.04 (docker-push): The push refers to repository [docker.io/huyz/ansible-molecule-ubuntu]
    ansible-molecule.docker.ubuntu:22.04 (docker-push): 1cdb0b846b12: Preparing
    ansible-molecule.docker.ubuntu:22.04 (docker-push): 6142b8f76de4: Preparing
    ansible-molecule.docker.ubuntu:18.04 (docker-push): errors:
    ansible-molecule.docker.ubuntu:18.04 (docker-push): denied: requested access to the resource is denied
    ansible-molecule.docker.ubuntu:18.04 (docker-push): unauthorized: authentication required
    ansible-molecule.docker.ubuntu:18.04 (docker-push): Logging out...
    ansible-molecule.docker.ubuntu:18.04 (docker-push): Removing login credentials for https://index.docker.io/v1/
    ansible-molecule.docker.ubuntu:18.04 (docker-push): WARNING: could not erase credentials:
    ansible-molecule.docker.ubuntu:18.04 (docker-push): https://index.docker.io/v1/: error erasing credentials - err: exit status 1, out: `The specified item could not be found in the keychain.`
    ansible-molecule.docker.ubuntu:18.04 (docker-push): Removing temporary Docker configuration directory
Build 'ansible-molecule.docker.ubuntu:18.04' errored after 6 minutes 4 seconds: 1 error(s) occurred:

* Post-processor failed: Bad exit status: 1
    ansible-molecule.docker.ubuntu:22.04 (docker-push): 6142b8f76de4: Layer already exists
    ansible-molecule.docker.ubuntu:22.04 (docker-push): 1cdb0b846b12: Layer already exists
    ansible-molecule.docker.ubuntu:22.04 (docker-push): errors:
    ansible-molecule.docker.ubuntu:22.04 (docker-push): denied: requested access to the resource is denied
    ansible-molecule.docker.ubuntu:22.04 (docker-push): unauthorized: authentication required
    ansible-molecule.docker.ubuntu:22.04 (docker-push): Logging out...
    ansible-molecule.docker.ubuntu:22.04 (docker-push): Removing login credentials for https://index.docker.io/v1/
    ansible-molecule.docker.ubuntu:22.04 (docker-push): WARNING: could not erase credentials:
    ansible-molecule.docker.ubuntu:22.04 (docker-push): https://index.docker.io/v1/: error erasing credentials - err: exit status 1, out: `The specified item could not be found in the keychain.`
    ansible-molecule.docker.ubuntu:22.04 (docker-push): Removing temporary Docker configuration directory
Build 'ansible-molecule.docker.ubuntu:22.04' errored after 6 minutes 7 seconds: 1 error(s) occurred:

* Post-processor failed: Bad exit status: 1
@huyz huyz added the bug label Feb 1, 2023
huyz added a commit to huyz/packer-plugin-docker that referenced this issue Feb 3, 2023
@huyz
Copy link
Contributor Author

huyz commented Feb 4, 2023

As I explained in #142 (comment) , the best solution is simply to not do login = true and just handle it on my own, out of band.

So perhaps this may not even be considered a bug as long as the documentation were updated to make it clear that docker login isn't supported for simultaneous docker-push post-processors.

huyz added a commit to huyz/packer-plugin-docker that referenced this issue Feb 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant