10 points · by diceduckmonk · 4y ago · 11 comments
======
My team has a web server in a Docker image. There is an ENV variable for the Postgres URL address. Locally, this has the form: "postgres://$USER:$PASSWORD@localhost:5432/$DB_NAME". When this server starts up, it uses that ENV variable and connects to Postgres.
We tried to deploy this to GCP. GCP CloudRun is the stop-gap between Functions ( one HTTP request handler, rather than an app with many ) and GKE ( multiple containers at once). We've used GKE before but we have simpler architecture in this case and CloudRun is, in theory, intended for this use case where you just have a single container. There's AppEngine but CloudRun appears to be more barebones.
We thought we'd use CloudSQL for managed Postgres. You fill out the webform, it creates a machine running Postgres that has some kind of URL address. From the above local example, there's really just two values to consider: the port ( probably the default 5432 ) and the host (which in this case is the IP, rather than "localhost").
On the CloudRun side, we upload our Docker image and specify the environment variable for the Postgres address.
Turns out this exceedingly difficult. It's not obvious at all how to establish this simple connection. After drudging through a dozen form questions, half a dozen rabbit-holes of gibberish docs, and side-questing to enable half a dozen APIs, it seems your CloudRun app can't actually talk to your CloudSQL. You have to go create a default VPC because it is not created by default. Then apparently you have to go create a "VPC connector". After half a dozen attempt at creating these networking resources, you finally succeed. You back to attempt provisioning CloudRun but discover you can't because the VPC connector is not in the same region as the CloudRun instance. So you backtrack once more.
After doing all of this, the CloudRun "service" / Docker image fails to start. We seek clues whether we should investigate that we've incorrectly specified the Postgres address or whether our network config insufficiently provided visibility. We're told something went wrong with the container and there will be clues in logs. We open up the logs viewer and the only errors are from GCP's implementation detail and Daemon. "terminated: Application failed to start: Failed to create init process: failed to load /usr/local/bin/docker-entrypoint.sh: exec format error" rather than the one from our application log. Now CloudRun is in an infinite loop / pending state, so we'll just have to delete it and try all over again.
How are people using CloudRun in production if you can't tell what made the container fail?
Use these docs https://cloud.google.com/sql/docs/mysql/connect-run
The error about the entry point is unrelated — it sounds like you might be doing something like `FOO=1 path/to/process foo var` instead of the dedicated proper syntax for specifying env, process, and args using YAML, etc.
https://www.evonence.com/blog/cloud-run-accessing-cloud-sql-...
The official GCP set of docs for this matter feels like gibberish, and just giving literal zero-value add explanations of form fields.
https://cloud.google.com/run/docs/configuring/connecting-vpc
For example, "3. Click create connector. 4. In the Name field, enter a name for your connector. This must be in accordance with the Compute Enginenaming convention, with the additional restriction that it be less than 21 characters with hyphens (-) counting as two characters."
So your app runs at 0 CPU when there is no requests ongoing, and can't use more than 1 processes in the same container. It means you can't have a container with nginx+rails, as only nginx will have a core to execute, rails has no core and it leads to a timeout.
Maybe you should ensure your app is not trying to use a second process?
[0] https://cloud.google.com/run/docs/configuring/cpu-allocation
But the problems with having multiple processes are weird. I'd have expected patterns where the http server blocks while waiting for a helper process to work. That sounds like a rather annyoing limitation, and I saw no mention of it in the documentation.
Can you double check if there is really such a limitation and not a misattribution?
This feels like a leaky abstraction that defeats the purpose of container-as-service especially when the intended audience is hobbyists / small teams who don't have a networking SRE, much less keeping track of fragile infrastructure assumptions.
If we have to stick with GCP, then it seems GCE VMs are a safer bet.
That's funny, no arm64 options are one of my complaints about GCP.
In the 10 minutes since reading your comment, I breezed through documentation, downloaded the CLI, authenticated, tweaked the code in 2 places: (1) the ENV variable key for the Postgres url and (2) the port of the app from 3000 to 8080. Ran `go build` and in theory, based on the way we structured our app, the one Go binary file is ready to go. I have confidence this might "just work", compared to the 3 hours I already sunk into GCP and who knows how much longer.
However, I'm blocked on needing credit card access / friction to proceed further due to my overseas CC. Would be great if someone from Fly.io is reading this and can provide free credits ( in exchange for user research ).
We'll see how pricing scales. Maybe GCP/AWS scales at higher scale, but the minimum requirements of GCP to run this single "serverless" container has already involved provisioning half a dozen VMs ( the VPC connector alone needs a minimum of 2. This feels like GCP's problem rather than the customers if they are promoting uploading a container and it "just works". ).
======
> no VPC connector is needed.
That's not true. It's enough that Google has released 2 forms of docs on this matter. Additionally, the webform to provision CloudRun also includes a section on VPC Connectors. You need to provision a VPC connector in order for CloudRun, Functions or App Engine to "see" CloudSQL with private IP.
https://codelabs.developers.google.com/connecting-to-private...
The VPC connector is a product which is backed by VMs. Its provisioning / validation rules require at least 2 VMs. You can see the web form yourself: https://console.cloud.google.com/networking/connectors/add?p...
> but that is abstracted and won't be in your list
Yes, that's abstracted but you are billed for the vCores. You can see the price sheets and minimum monthly costs here: https://cloud.google.com/sql/pricing
In the case of CloudSQL, sure, it's abstracted, but CloudRun is revealing its leaky abstraction. Here are implementation details you have to know about: https://cloud.google.com/run/docs/container-contract. For example, it seems my issue could be related to building the container on an M1 mac. https://stackoverflow.com/questions/66127933/cloud-run-faile...