Building a CI Pipeline with Stackery
Originally published at www.stackery.io.
At Stackery, we’ve been brainstorming the best approach to implement a CI pipeline for p/reviewing PRs, viewing tests, and deploying environment builds. The first part of the chain is building a tool that provides an efficient way to review a PR, preview it in the browser, and ensure its tests pass — without disrupting local development. This challenge presented the perfect opportunity for me to: better understand serverless architecture, use Stackery as a tool, and build a utility that will add efficiency to our CI workflow.
Here is a look at the steps involved to build this piece of our pipeline:
- Use the Github webhook Api (repo > settings) to send a request to a Stackery Rest Api endpoint whenever a PR is “opened”, “edited”, or “reopened”
- The Rest Api endpoint has a link to a Stackery Function node that receives the response containing everything we need to assemble the build
- The Function will clone the PR, run npm commands, then upload a www-ready build (using Stackery.output) to a Stackery Object Store
- When finished, the Function will send a request back to Github, adding a comment to the PR with a log of
npm run testoutput and a url to preview the build that links to the Object Store where the build files were uploaded.
- Implementation details
Configure a stack using the Stackery dashboard with 3 nodes: Rest Api -> Function -> Object Store
The Rest Api endpoint will receive a request from a Github webhook when a PR is “opened”, “edited”, or “reopened”.
The Function node
runBuild receives the response as its
message parameter (output from the Rest Api node). Memory was increased to 1536MB to ensure that the process would complete as quickly as possible. Since execution is infrequent, cost to increase memory is nominal.
runBuild performs the following steps using a Promise() chain:
- Clone the repo and checkout the branch into a /tmp directory using properties from the Github webhook response object
(Lambda is a read-only environment but supports writing to a /tmp directory)
- Run npm install, build, and test inside the /tmp directory (each command a separate .then() handler in the chain)
- Output each file using Stackery.output() (returns a promise) from the completed build to the Object Store
- Send a request back to Github and add a comment to the PR with the test output and a url to the Object Store
Building this tool helped me discover one of the many possibilities of using Stackery as an operational tool and also exposed some unique challenges when performing familiar workflow commands within an AWS Lambda environment. More to come on our blog and guides as we build-out our CI pipeline.