mirror of
https://github.com/fsouza/fake-gcs-server.git
synced 2026-04-26 06:05:54 +03:00
[GH-ISSUE #982] Unable to access uploaded file (go + testcontainers) #154
Labels
No labels
bug
compatibility-issue
docker
documentation
enhancement
help wanted
needs information
pull-request
question
stale
unfortunate
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/fake-gcs-server#154
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @rtrzebinski-usc on GitHub (Nov 6, 2022).
Original GitHub issue: https://github.com/fsouza/fake-gcs-server/issues/982
Hi, here is my issue with the emulator - I use
testcontainersfor integration test, uploading works fine (I see the file in the container) but there is no way to access it via HTTP or from the code, here is the script to reproduce:When you run it will print the base url like
http://localhost:49405/storage/v1- I try to add bucked and object name and access likehttp://localhost:49405/storage/v1/foo/bar- getting 404.Then since script is paused by
time.Sleep(1000 * time.Second)I can inspect the image - I see that:What I do wrong? Any help will be appreciated, thank you :)
@rtrzebinski-usc commented on GitHub (Nov 6, 2022):
I found out that the url to download the file would be
http://localhost:49409/download/storage/v1/b/foo/o/bar- but how do I check whether file was uploaded using the code (reader) so I don't receivefailed to create reader, storage: object doesn't existerror?@dezyh commented on GitHub (Nov 13, 2022):
I'm also able to reproduce the above (with my own implementation). The issue is related to the
-public-hostargument not being set.If I adapt the go example to create an object and then read that object, this only works
-public-host localhost:8080is set (ci script). Without it, I also getstorage: object doesn't existwhen executing it.Solution
Journey
Exploring the source code, you can see that one of the
downloadObject'sMatcherFunc's uses thepublicHostMatcher(which uses thepublic-hostargument andpublicHostconfig.github.com/fsouza/fake-gcs-server@071372eda6/fakestorage/server.go (L274-L277)So taking a look at this
MatcherFunc, it will match requests only for a specific port if one is given, but falls back to matching any port if none is given.github.com/fsouza/fake-gcs-server@071372eda6/fakestorage/server.go (L293-L300)@dezyh commented on GitHub (Nov 13, 2022):
The documentation in the README mentions setting
-public-hostbut doesn't mention that-public-hostfordownloadObject(just for pre-signed urls).-public-hostIt might be nice to document this, because it also cost me about 2 hours to work through everything (especially because I initially thought it was an implementation bug in my code)?
@fsouza commented on GitHub (Nov 16, 2022):
@dezyh thanks for digging into this. Since you did the investigation, do you also want to send a PR with improvements to the docs? I can do it if you prefer!
@dezyh commented on GitHub (Nov 16, 2022):
I'll make a readme PR, just wanted to check that I wasn't missing something obvious.
@fsouza commented on GitHub (Nov 16, 2022):
@dezyh oh, that sounds good. I'll dig into that sample code to see if there's a better fix, but yeah sounds like we need to clarify the role of
public-hostin the docs.@sourabhsparkala commented on GitHub (Nov 22, 2022):
@fsouza @dezyh I followed the instructions given here and I just ran the code given above and set the
public-hostto0.0.0.0. But I still face the same issue. Am I missing anything?@rtrzebinski-usc were you able to run this test case successfully?
@dezyh commented on GitHub (Dec 2, 2022):
Sorry, I was busy for a while.
I'm personally using dockertest and running containers inside a docker network. This works perfectly both local and on GitHub Actions with my above comment.
One small subtlety, is that connecting through the network's hostname for the container (not sure on terminology) doesn't work in GitHub Actions. While this is partly dockertest specific, it might also apply with testcontainers.
I have to connect through a port that's bound to the default network (again, sorry don't know the correct terminology)