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

May not be possible to run Dockerfile on Google Cloud Run #331

Closed
danoc opened this issue Sep 9, 2019 · 8 comments
Closed

May not be possible to run Dockerfile on Google Cloud Run #331

danoc opened this issue Sep 9, 2019 · 8 comments

Comments

@danoc
Copy link

danoc commented Sep 9, 2019

Hi! Thanks for this great resource.

I'm trying to run the Dockerfile on Google Cloud Run. One of the requirements of Cloud Run is:

The service must listen for requests on the port defined by the PORT environment variable.

The Browserless site suggests using docker run -p 8080:3000, but Cloud Run doesn't provide a way to do this kind of port mapping.

Is there another way to do this? Or would this require a change to Browserless?

Thanks!

@knksmith57
Copy link
Contributor

knksmith57 commented Sep 9, 2019

The batteries-included browserless/chrome image actually does respect $PORT; however, because the container process is configured to run as a non-privileged user, only ports > 1024 are going to bind successfully.

Unfortunately, Cloud Run doesn't make any guarantees about the port range it'll request, and, after trying myself, I can confirm that Cloud Run can set $PORT < 1024.

Given you're likely already re-tagging + publishing the browserless image to your own GCR registry, there's a quick fix: extend the browserless/chrome image you're currently targeting and change the user to one with privileges to bind to all ports (eg: back to root):

FROM browserless/chrome:1-chrome-stable
USER root

note: running as root isn't a particularly good idea, and Joel definitely opted to run the browserless server this way for a reason (see his blog post where he talks about sandboxing). that said, unlike browserless.io, you're probably not going to be operating a multi-tenant environment (I'm guessing?). so maybe this is an acceptable amount of risk for your particular use case. YMMV!

@joelgriffith
Copy link
Collaborator

Pretty much what @knksmith57 said: you'll likely need to run as a privileged user if the port assignments are less than 1024. Otherwise it'd be nice if they could specify a range?

@joelgriffith
Copy link
Collaborator

@danoc
Copy link
Author

danoc commented Sep 9, 2019

Thanks, @joelgriffith and @knksmith57! I'll try this out tonight and report back. I'll share my Dockerfile if it works well. 😄

@joelgriffith
Copy link
Collaborator

joelgriffith commented Sep 9, 2019

Looks like websockets aren't really supported on Cloud Run https://github.com/ahmetb/cloud-run-faq#are-websockets-supported-on-cloud-run. I had success using the REST API, but I had to disable the ENTRYPOINT in my dockerfile to do so

@danoc
Copy link
Author

danoc commented Sep 10, 2019

Ah, right!

They list the lack of support as a "Known Issue" which, I imagine, means that they plan to add support in the future.

I'll close this for now and then circle back once they have support for it! Thanks again for digging into this.

@danoc danoc closed this as completed Sep 10, 2019
@joelgriffith
Copy link
Collaborator

Yup, no worries. I did a test and their service took roughly 2-3 seconds to screenshot example.com with Chrome pre-started. Our usage-based cluster does it in roughly 600ms, and wo Chrome pre-started.

I know others have complained about slow start times in GCP, so use caution if speed is necessary.

@danoc
Copy link
Author

danoc commented Sep 10, 2019

I know others have complained about slow start times in GCP, so use caution if speed is necessary.

Yeah, the Chrome built into Cloud Functions is sadly very slow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants