orlangure/gnomock

Bug: `WithUseLocalImagesFirst()` doesn't work with local only images

Omar-V2 opened this issue · 2 comments

Describe the bug
Trying to create a container from a local image (one that is not hosted on any container registry) doesn't work when using WithUseLocalImagesFirst().

To Reproduce
Repo: https://github.com/Omar-V2/temporal-coffeeshop/blob/main/internal/customer/integration-tests/customer/customer_test.go

  1. Build docker image from local dockerfile and tag it with a name. For example from the root of this repo run the following:
    docker build -f internal/customer/Dockerfile.worker -t customer-worker .

  2. Execute the integration test here
    go test -v -run ^TestCustomerServiceIntegrationTestSuite internal/customer/integration-tests/customer/customer_test.go. Which attempts to start the container from the image as follows

s.temporalWorker, err = gnomock.StartCustom(
  "customer-worker",
  gnomock.DefaultTCP(8082),
  gnomock.WithUseLocalImagesFirst(),
  gnomock.WithDebugMode(),
  gnomock.WithEnv(fmt.Sprintf("TEMPORAL_ADDRESS=%s", s.temporalServer.DefaultAddress())),
)
  1. The local container is not found and I keep getting the error:
              Error:          Received unexpected error:
                                can't start container: can't prepare container: can't pull image: can't pull image: Error response from daemon: pull access denied for customer-worker, repository does not exist or may require 'docker login': denied: requested access to the resource is denied

Expected behavior
I expected the container to be created from the local image - however it seems that the container is not even found. After some digging around in gnomock's source code I discovered the function isExistingLocalImage and after some debugging I realise it's expecting an image named library/customer-worker which Im not sure why it expects it to be named like this? I notice it's using strings.HasSuffix(image, repoTag) - are these parameters the wrong way round? For example, if my image is named "customer-worker:latest" repoTag will be "library/customer-worker:latest" and so strings.HasSuffix(image, repoTag) will always return false - unless the parameters are swapped then this would make sense?

Anyway, as a workaround I tried naming my image "library/customer-worker" and this did indeed allow it to be discovered however now I get a different error

                Error:          Received unexpected error:
                                can't start container: container network isn't ready: can't inspect container 5e93d9b5f5eec2764bec9a9aeb92127b58fcd6403fccb3cb48998468248ba342: Error: No such container: 5e93d9b5f5eec2764bec9a9aeb92127b58fcd6403fccb3cb48998468248ba342

Screenshots
If applicable, add screenshots to help explain your problem.

System (please complete the following information):

  • OS: Mac OS Ventura
  • Version: 13.1
  • Docker version: 20.10.21, build baeda1f

Additional context
Add any other context about the problem here.

I'm experiencing a very similar issue. Any leads would be highly appreciated. @orlangure

Hi @Omar-V2, @claraisrael 😼
Thank you for your reports.

Can you try the fix from #798? With it I managed to create a container using a local image without adding library/ or version tag. I'll wait for your feedback a couple of days before merging it.