This post will walk through setting up a continuous integration, deployment, and testing pipeline for a Node.js app using CircleCI, Heroku, and Assertible.
Continuous integration is large part of modern development workflows. Most of us are familiar with basic CI services that automatically build code as new changes are pushed. But what if you took that a step further and not only built your code, but also deployed and tested it within the same pipeline? This is continuous development.
Let's outline the steps of the pipeline:
- Continuous integration: Push new code to GitHub, which is then built by CircleCI.
- Continuous deployment: Automatically deploy the new application to Heroku.
- Continuous testing: Execute post-deployment tests with Assertible.
I've created an example Node.js app for the code in this post. In the end, you'll have a workflow that will automatically build, deploy, and test your app after every push.
Continuous integration with CircleCI
The pipeline is initiated when code is pushed to a repository on GitHub. CircleCI will automatically pull the new changes, build the code, and run the unit tests. Setting this up only takes two steps:
- Add a
circle.ymlto our repository. You can see the example app's config file in the
nodejs-examplerepo on GitHub.
- Tell CircleCI to watch the project. This is done in your CircleCI dashboard, by adding projects
Now, every time code is pushed to the GitHub repository, CircleCI will run the unit tests and fail if there are any issues:
Continuous deployment with Heroku
After our code has been built and the unit tests have passed, CircleCI
will look for a
deployment step in our configuration. In the example
app, I'm deploying the application to Heroku.
In the example project's
circle.yml file, take a look at the
deployment step again:
deployment: production: branch: master commands: # ...removed lines for brevity # Deploy the app to heroku - git push firstname.lastname@example.org:assertible-nodejs-example.git $CIRCLE_SHA1:refs/heads/master
This configuration tells CircleCI to deploy our application to
production when you push to the
master branch of the repo. The
deployment is executed by running each step in
This is continuous deployment: every time changes are pushed to the repo, CircleCI will build the app, and the deploy it to Heroku. Automatically. Every time. That's pretty cool!
Continuous testing with Assertible
After the application is deployed, you want to run an automated test suite on the new version to verify the release ensure it meets a certain standard. To do this, you use Assertible.
Let's look at the last couple of lines in our
deploying to Heroku:
# Download github_deploy script - curl https://raw.githubusercontent.com/assertible/deployments/master/github_deploy > github_deploy - chmod +x github_deploy # Send a deployment event to GitHub. GitHub will then send that # event to Assertible, and Assertible will run your API tests. - | APPROOT=https://assertible-nodejs-example.herokuapp.com/ DEPLOY_ID=$(ENVIRONMENT_NAME="production" ./github_deploy $CIRCLE_SHA1 $CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME $APPROOT "pending") ./github_deploy $CIRCLE_SHA1 $CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME $APPROOT "success" $DEPLOY_ID
github_deploy script to
send "deployment" events to our GitHub repository. Assertible watches
your repo for these events, and when a successful deployment occurs,
your API tests will automatically be executed. This is
post-deployment testing, a part of automated QA testing.
In the image below, you can see that Assertible tested the new deployment and ran the defined assertions on the application. It even says what commit the deployment was from:
Connecting Assertible to GitHub is easy! Just follow our GitHub Quick Start Guide.
Continuous testing is important for any team or developer releasing software. Automating API and QA tests not only saves time, but covers more cases faster than traditional, manual testing methods.
Testing staging environments from Pull Requests
A lot of times you're not deploying to production, but rather to a staging environment or Heroku review app. Assertible knows about your different environments and will run your API tests on the correct application.
When you deploy to a staging environment from a GitHub pull request, Assertible will show a status check that ensures all of your API tests are passing before the new changes are merged. Awesome!
Resources and examples
Even more automation and integrations
There's even more you can automate. Heroku has a ton of addons you can use to automate various parts of your build. Assertible supports integrations like Zapier that can be used to customize how you use your test results and get alerts of failures.
Integration with other CI services
Nothing about this pipeline is specific to GitHub, CircleCI, Heroku, or even Assertible. Learn more about setting up this pipeline with different CI providers, like Wercker, in the assertible/deployments repo.
Do you have anything to add to this list? Let me know!
What does your continuous development workflow look like? Shoot us a message on Twitter and let us know! Check it out and sign up for a free Assertible account to start testing every single deployment!
Automate your QA pipeline
Reduce bugs in web applications by using Assertible to create an automated QA pipeline that helps you catch failures & ship code faster.Get started with GitHubSign up for free
New feature: JSON schema validation 4/10/2017