I am building a serverless web application with all the source code managed by Google's Cloud Source Repository. My directory looks like this:
/webapp
/functions
*serverless functions*
/static
/css
app.css
/js
app.js
I have build triggers active on this repository monitoring the serverless functions and redeploying them as Google Cloud Functions every time a change is pushed, which is great. My problem now is that I can't seem to find a way to get my css and js automatically pushed into a Cloud Storage bucket for general availability in a likewise manner.
How is this generally done?
You didn't specify how you implemented your automated deployment but you may have used Cloud Build like shown in this official doc on Cloud Functions continuous deployment.
Building on this, you can simply add a build step to deploy your static files to Cloud Storage using the gsutil tool. For example:
steps:
- name: 'gcr.io/cloud-builders/gcloud'
args: ['functions', 'deploy', '[YOUR_DEPLOYED_FUNCTION_NAME]', '[YOUR_FUNCTION_TRIGGER]', '--runtime', '[YOUR_RUNTIME]', '--entry-point', '[YOUR_FUNCTION_NAME_IN_CODE]']
dir: 'webapp/functions'
- name: gcr.io/cloud-builders/gsutil
args: ['rsync', '-R', 'webapp/static', 'gs://your_gcs_bucket/']