Support Google Cloud Function
RayBB opened this issue · comments
Do you want to request a feature or report a bug?
Feature
What is the current behavior?
You have to to modify the code to support a Cloud Function deploy
What is the expected behavior?
Ability to deploy application without modifying code.
If this is a feature request, what is motivation or use case for changing the behavior?
To make it as easy as possible for users to setup this application.
I'm not sure what the best way to add cloud function support is without breaking anything.
It could be as simple as changing the start script to point to a different file that runs the app.listen
while still allowing cloud functions to import the named function.
I can make a PR if you let me know how it makes sense to change it.
In the meantime folks can use the steps listed below to get it running in cloud functions.
Current steps required to deploy to cloud function
git clone git@github.com:nytimes/Chronicler.git
cd Chronicler
# in package.json change "main" from index.js to src/index.js
# this is needed choose entrypoint for cloud function
gsed -i 's/"index.js"/"src\/index.js"/' package.json
# add a named export called chronicler to index.js
echo "module.exports.chronicler = require('./main')" >> src/index.js
# export the express app for usage by cloud function
echo "module.exports = app" >> src/main.js
# finally, we need to manually remove the lines involving app.listen from main.js
# this avoids conflict with the cloud function about port usage
gcloud --project my-great-project functions deploy chronicler \
--runtime nodejs12 --trigger-http --allow-unauthenticated \
--set-env-vars GH_TOKEN=github_key_here,SECRET=a_good_secret_here \
--entry-point chronicler