1
votes

I have a simple site built using revel containerized in a docker image. I'm trying to run this image in Cloud Run. Unfortunately when I go to the URL for the site, I see a 502 in the browser and this log line

2020/10/30 17:27:07 http: proxy error: dial tcp 0.0.0.0:16166: connect: connection refused

I would assume it had something to do with the port, but I tried mapping the port originally to 9898 and I still saw a random port number in the log line. Currently I have the port in my revel application set to ${PORT} as recommended by the GCP documentation.

I should mention I can deploy the container locally with no issues.

Dockerfile:

FROM golang:1.15 AS build
ENV CGO_ENABLED 0
ADD . /go/src/app

# Install revel framework
RUN go get -u github.com/revel/revel
RUN go get -u github.com/revel/cmd/revel
# Run revel app
EXPOSE ${PORT}
ENTRYPOINT revel run -a /go/src/app -p ${PORT} -m dev

Revel app.conf snippet:

# The IP address on which to listen.
http.addr = 0.0.0.0

# The port on which to listen.
http.port = ${PORT}

UPDATE: It was suggested to use the hardcoded port of 8080 and see if that works. I still see the 502. I tried running it locally again and it looks like revel is trying to set up on one port and then listenining as a reverse proxy on another. So unless I'm thinking this may be a revel issue and not a Cloud Run issue

docker run --publish 8080:8080 app
Revel executing: run a Revel application
Changed detected, recompiling
Parsing packages, (may require download if not cached)... Completed
INFO  02:34:24    app     run.go:34: Running revel server
INFO  02:34:24    app   plugin.go:9: Go to /@tests to run the tests.
Revel engine is listening on.. 0.0.0.0:44795

Time to recompile 8.0340966s
Revel proxy is listening, point your browser to : 8080

Notice the last line Revel proxy is listening, point your browser to : 8080 but also Revel engine is listening on.. 0.0.0.0:44795

1
Nothing jumps to me. But it seems like your container is trying to establish connection to 0.0.0.0:16166 for proxying purposes and it's failing. Why would revel do this?Ahmet Alp Balkan
I'm unfamiliar with Revel but familiar with Cloud Run. The Cloud Run service wants to provide ${PORT} to your container but the service currently (always?) defaults this value to 8080. So, you need Revel to run on 8080 too. It's unclear why you specify ${PORT} in both the Dockerfile's revel run ... -p ${PORT} and app.conf since, presumably, the former overrides the later. You want to ensure that your container, when given an env var of ${PORT} will run (!) on ${PORT} but you should be able to hack this by replacing both ${PORT} with 8080 in your Dockerfile (!)DazWilkin
Ensure that revel run uses 0.0.0.0 rather than localhost too. I suspect this is already true since you can run and access the container locally.DazWilkin
Once built... if you can docker run ... --publish=8080:8080 ... and then curl localhost:8080, you should be good to deploy it to Cloud Run.DazWilkin
I tried running on 8080 @DazWilkin, and it does work locally. But I do see now there is still a strange localhost port. I'm also new to revel and it seems like it's setting up and then listening on a reverse proxy at 8080 editing my answer with thisSevvy325

1 Answers

0
votes

So after further investigation and discussion, it seems like when you run revel applications via revel run a proxy is set up on a random port and that connection was what was failing. Furthermore, the largest benefit of running via revel run is hot swapping of deployed code, which is unnecessary in a deployed context. So the solution here was to build the application via revel build and running that application that way so that only the application port is used for connections.