Closed garcianavalon closed 5 years ago
See https://github.com/GoogleCloudPlatform/nodejs-docs-samples/tree/master/appengine/hello-world/flexible for example Node.js project.
Not sure why (if) port 8080 works without configuration. See information about configuring port forwarding: https://cloud.google.com/appengine/docs/flexible/custom-runtimes/configuring-your-app-with-app-yaml
All righty, well!
I just wanted to deploy postGraphile with nothing more than command-line arguments to the cloud to serve between my psql hosted in Google Cloud SQL and an Angular App hosted in Google App Engine.
In the past, I've used Google App Engine to host middle-tiers. After MUCH struggle, I figured out that I need to use cloud_sql_instances to connect to the psql instance, and that I needed to set the host and port in the command line.
Make sure you've got a project with your Cloud SQL postgres database, with the Google Cloud Admin SQL turned on, and App Engine turned on. Reserve the default service in App Engine for whatever your front-end is.
Here's my app.yaml, the deployment file:
beta_settings:
cloud_sql_instances: webstr-dev-######:us-central1:webstr-dev=tcp:5432
# [START runtime]
runtime: nodejs
env: flex
threadsafe: yes
service: wgraphile
manual_scaling:
instances: 1
resources:
cpu: .5
memory_gb: .5
disk_size_gb: 10
health_check:
enable_health_check: False
# [END runtime]
handlers:
- url: /(.*)
static_files: ./\1
upload: ./(.*)
# settings to keep gcloud from uploading files not required for deployment
skip_files:
- ^node_modules$
- ^README\..*
- ^package-lock.json
- \.gitignore
- \.es*
- ^\.git$
- ^errors\.log
under beta_set
cloud_sql_instances: webstr-dev-######:us-central1:webstr-dev=tcp:5432
tells us that we are opening a unix pipe to a cloud instance in the gcp project in this case 'webstr-dev-######' in central region 1
, connecting to cloud sql instance websr-dev
.=tcp:5432
maps that unix socket to tcp port 5432. In my package.json, I specify postgraphile, and some project details, and the start script. For short:
{
"name": "myprojectname",
"version": "1.0.0",
"scripts": {
"start": "postgraphile --port 8080 -o --watch --enhance-graphiql -o -q / --host 0.0.0.0 -c postgres://user:password@172.17.0.1:5432/str_dev",
},
"engines": {
"node": "^10.15",
"npm": "^6.9"
},
"license": "ISC",
"dependencies": {
"postgraphile": "^4.4.3"
}
}
The project will end up at https://[project-name].appspot.com/
https://[project-name].appspot.com/graphiql
Regarding the start command, the saving graces are:
--port 8080
Google cloud will map port 8080 to the name of the service you are creating, so you won't need to specify :5000 like we do on a local postgraphile, just the end point url https://[project-name].appspot.com/
-q /
switch puts the graphql endpoint at the name of the service itself--host 0.0.0.0
allows GAE's nginx to successfully bind to the service-o
circumvents annoying CORS nonsense--watch
lets postgraphile keep up with your database changesDEPLOYING: I deployed the project with gcloud. I used
gcloud init
to setup my connection to my google cloud project. Then I usedgcloud app deploy
in this directory to push it up.
Thanks Pol!
My pleasure! :) Maybe the website could have a section of tutorials to deploy postGraphile. Maybe for supporters? :)
On Wed, Sep 18, 2019 at 1:20 AM Benjie Gillam notifications@github.com wrote:
Thanks Pol!
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/graphile/graphile.github.io/issues/161?email_source=notifications&email_token=ABE6KQOQYWNNSFW43EDU6UTQKHQEDA5CNFSM4IXN3G62YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD67HPUQ#issuecomment-532576210, or mute the thread https://github.com/notifications/unsubscribe-auth/ABE6KQPGHVB2DAKKI3M2LIDQKHQEDANCNFSM4IXN3G6Q .
--
-=-=-==-=-=-=-==-=-=-=-=-=-=-=-=-=- Pol Stafford Storyteller, Writer, Geek, Sensei
I was thinking we could add this to Guides
and when we have enough of them we'd split to it's own section "deployment".
Sounds awesome! Would have helped me a ton! :) I spent 4 days = 32 hours = $4000 on this, so I'm guessing it's valuable. :)
I've shipped this; if someone wants to edit it please be my guest, it's just a hotchpotch of the above content for now:
https://github.com/graphile/graphile.github.io/blob/develop/src/pages/postgraphile/deploying-gcp.md
Is there a way to run this on Cloud Run? i.e. a Cloud Run PostGraphile server on a Cloud Postgres instance
I doubt many people are following this issue; recommend you ask in our chat instead.
Cloud Run works without any additional configuration, much simpler than App Engine. Just link to your github and let it deploy. Plus subscriptions (WebSockets) work out of the box, too.
I'm on a rush and I haven't had time to finish a full guide, but as a quick reference for the future, this is the configuration required to run postgraphile on App Engine
flexible
environment for websocket support (subscriptions and live queries). If you are not interested in real-time features you can usestandard
environment and save some bucks. In that case, remove thebeta_settings
sectionin package.json
In index.js