Buildserverless is an example of how to build Node.js builds on serverless platforms (specifically Google Cloud Functions)
- Create a Google Cloud project and enable the GCS API
- Generate Service Account Credentials and put those credentials in the project root in a file called credentials.json
- Modify the configuration constants in index.js to match your application (to start, you can just modify the OUTPUT_BUCKET)
- Deploy the Cloud Function called
buildserverless
(if you use Docker, modify thedeploy
target in the Makefile and callmake deploy
)
At a high level, the steps are pretty simple:
- Download source code — simply clone a Github repo.
- Run the build — execute a build command that you would execute on the command line, like
npm run build
. - Package the build results — since the build might output multiple files, it is easiest to package all those results into a tarball and compress it so it can be pushed somewhere else…
- Push the results — Cloud Functions execute in temporary environments, so the build results must be pushed somewhere persistent to be utilized later. Having them packaged and compressed makes this easier and saves on network egress. I chose to push the packaged build to GCS, but it can really be pushed anywhere.