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

Default http.server configuration prevents Docker deployment #129

Closed
oerni74 opened this issue May 31, 2024 · 4 comments
Closed

Default http.server configuration prevents Docker deployment #129

oerni74 opened this issue May 31, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@oerni74
Copy link

oerni74 commented May 31, 2024

Hi,

first of all I would like to say that I really like working with Fuego. It is a nice experience so far.

However, I recently wanted to deploy my Fuego application to the Cloud (Google Cloud Run) and there are some problems with the default behavior imho.
The fuego.NewServer() function automatically calls the withPort() function, which itself sets the Addr field of the underlying http/server to localhost:port. Unfortunately, this has a side effect. When running the application inside a Docker container, you have to add the --net=host argument to make it accessible from the outside. This is different from the default bahavior of the http/server where the Addr field is just set to :port.

I would have expected that withPort only sets the port and not the host. In the end the only solution for Cloud Run was to use withAddr(":"+port). Then it can be accessed via the browser on localhost:8080, however the log says Server running ✅ on http://:8080, which is a bit confusing.
Therefore, I would suggest to make the behavior equal to the one in the standard library to avoid confusion when making a deployment.

That being said, I am still new to Go, so maybe there is a deeper reason I don´t know yet 😄)

To Reproduce
Steps to reproduce the behavior:

  1. Create a new fuego server
    fuego.NewServer()
  2. Dockerize the application (example Dockerfile: https://github.com/GoogleCloudPlatform/cloud-run-hello/blob/master/Dockerfile)
  3. Run the Docker container with the default bridge network
  4. (optional) Run the Docker container in the cloud (e.g. on Google Cloud Run)
  5. Try to access the application.

Expected behavior
Application is accessible without further configuration like when using the standard library http/server.

Framework version (please check if it happens with the last Fuego version before posting):
0.13
Go version (please check if it happens with the last Go version before posting):
1.22

@oerni74 oerni74 added the bug Something isn't working label May 31, 2024
@chenjr0719
Copy link

I think using fuego.WithAddr("0.0.0.0:8080") when creating a new server should work.
https://go-fuego.github.io/fuego/docs/guides/options#address

Could you give it a try?

@EwenQuim
Copy link
Member

EwenQuim commented Jun 5, 2024

I will fix the behaviour of WithAddr in next version.

Don't forget that in the meantime you can always access server.Addr as it is a public field and not used before server.Run()

@dylanhitt
Copy link
Collaborator

dylanhitt commented Jun 5, 2024

@EwenQuim not sure I understand? What seems to be the problem with WithAddr?

@oerni74 the fuego WithAddr function is essentially pass through behavior of setting .Server.Addr = "localhost:9090"

I'm pretty sure to get what you're after you can just WithAddr(":9090"). Also we stop using WithPort as our default recently in the New command so maybe try using fuego 0.13.4

@dylanhitt
Copy link
Collaborator

@oerni74 was you issue resolved? If so please close.

@oerni74 oerni74 closed this as completed Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants