{"id":18930369,"url":"https://github.com/mitocgroup/tutorial-ci-for-serverless","last_synced_at":"2025-07-08T15:05:36.798Z","repository":{"id":143629546,"uuid":"112222277","full_name":"MitocGroup/tutorial-ci-for-serverless","owner":"MitocGroup","description":"Tutorial Continuous Integration for Serverless Applications","archived":false,"fork":false,"pushed_at":"2018-06-09T17:07:48.000Z","size":42,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-15T17:16:42.181Z","etag":null,"topics":["code-climate","continuous-integration","e2e-testing","serverless","serverless-applications","snyk-io","travis-ci","tutorial","unit-testing"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MitocGroup.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-11-27T16:46:42.000Z","updated_at":"2019-09-04T00:53:09.000Z","dependencies_parsed_at":null,"dependency_job_id":"b6fdfb9f-1282-4b74-973e-739dc5644d27","html_url":"https://github.com/MitocGroup/tutorial-ci-for-serverless","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/MitocGroup/tutorial-ci-for-serverless","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MitocGroup%2Ftutorial-ci-for-serverless","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MitocGroup%2Ftutorial-ci-for-serverless/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MitocGroup%2Ftutorial-ci-for-serverless/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MitocGroup%2Ftutorial-ci-for-serverless/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MitocGroup","download_url":"https://codeload.github.com/MitocGroup/tutorial-ci-for-serverless/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MitocGroup%2Ftutorial-ci-for-serverless/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264292934,"owners_count":23586061,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["code-climate","continuous-integration","e2e-testing","serverless","serverless-applications","snyk-io","travis-ci","tutorial","unit-testing"],"created_at":"2024-11-08T11:37:24.636Z","updated_at":"2025-07-08T15:05:36.773Z","avatar_url":"https://github.com/MitocGroup.png","language":"JavaScript","readme":"# Tutorial: Continuous Integration for Serverless Applications\n\nContinuous Integration is the practice of merging all working copies of\ndeveloper code into one shared mainline several times a day. Best practices\ninclude automation of builds and deployments, with fast and self-testing\nbuilds, as well as production-like testing environments. With serverless, the\ncontinuous integration pipeline evolves from a one-lane, one-way street into a\nmultiple-lane, two-way highway.\n\nIn this tutorial, we take a simple serverless application and walk you through\nthe steps to set up unit testing, end-to-end testing, code coverage, code\nanalysis, code security, code performance, and peer code review. You can learn\nhow to use AWS serverless components in combination with GitHub, Travis-CI,\nCodeClimate, Snyk and other serverless-friendly services.\n\n## Getting Started\n\n### Step 1: Your Serverless Application\n\n\u003e Step 1 Branch:\nhttps://github.com/MitocGroup/tutorial-ci-for-serverless/tree/tutorial-step1\n\nFor this tutorial, we went with Single Page Application from\n[todomvc.com](http://todomvc.com), transformed by our team into\n[TodoMVC Serverless App](https://github.com/MitocGroup/deep-microservices-todomvc).\nSimilar approach can be applied to serverless applications described in\n[Serverless Single Page Apps](https://pragprog.com/book/brapps/serverless-single-page-apps)\nor [Serverless Stack](https://serverless-stack.com),\nas well as any other serverless applications from\n[Curated List of Awesome Serverless](https://github.com/anaibol/awesome-serverless).\n\n```shell\n# download locally todomvc serverless application codebase\ngit clone git@github.com:MitocGroup/deep-microservices-todomvc.git\n\n# download locally tutorial repository codebase\ngit clone git@github.com:MitocGroup/tutorial-ci-for-serverless.git\n\n# copy serverless application into a new branch, part of tutorial repository\ncd ./tutorial-ci-for-serverless\ngit checkout -b tutorial-step1\ncp -R ../deep-microservices-todomvc/src ../deep-microservices-todomvc/bin .\ngit commit -a -m \"initial serverless application\"\ngit push --set-upstream origin tutorial-step1\n```\n\n### Step 2: Setup Travis CI\n\n\u003e Step 2 Branch:\nhttps://github.com/MitocGroup/tutorial-ci-for-serverless/tree/tutorial-step2\n\nTravis CI takes care of running your tests and deploying your apps. Quoting\nofficial [Getting Started](https://docs.travis-ci.com/user/getting-started/)\nguide:\n\n\u003e To start using Travis CI, make sure you have all of the following:\n\u003e - GitHub login\n\u003e - Project hosted as a repository on GitHub\n\u003e - Working code in your project\n\u003e - Working build or test script\n\nHere below is our initial `.travis.yml` file:\n\n```yaml\nlanguage: node_js\ndist: trusty\ngit:\n  depth: 1\ncache:\n  bundler: true\n  directories:\n    - node_modules\n    - \"$(npm root -g)\"\n    - \"$(npm config get prefix)/bin\"\nnode_js:\n  - 6\n  - 8\nscript: echo \"Hello World!\"\n```\n\nOnce we have updated `.travis.yml`, we can commit the code back to our\nrepository:\n\n```shell\n# assuming you're still inside the tutorial repository\ngit checkout -b tutorial-step2\ngit add .travis.yml\ngit commit -m \"enable travis ci\"\ngit push --set-upstream origin tutorial-step2\n```\n\nAnd there you go, our first successful build:\nhttps://travis-ci.org/MitocGroup/tutorial-ci-for-serverless/builds/283669984\n\n### Step 3: Setup Unit Testing\n\n\u003e Step 3 Branch:\nhttps://github.com/MitocGroup/tutorial-ci-for-serverless/tree/tutorial-step3\n\nTravis CI inspired us with its simplicity and streamlined process. On the other\nhand, we were surprised that triggering tests execution is not part of the\nservice. And we couldn't find any other tool that does it well, so we wrote\none: https://www.npmjs.com/package/recink\n\nTo get started with this tool, just install it on your machine and configure:\n\n```shell\n# install recink as global nodejs library\nnpm install -g recink\n\n# configure recink in your repository\nrecink configure recink\n```\n\nLast command will dump an example of `recink.yml` (conceptually the same\napproach as `.travis.yml`), which helps to simplify and streamline the\nexecution of unit tests, e2e tests and more:\n\n```yaml\n---\n$:\n  npm:\n    scripts: []\n    dependencies:\n      chai: 'latest'\n  emit:\n    pattern:\n      - /.+\\.js$/i\n    ignore:\n      - /^(.*\\/)?bin(\\/?$)?/i\n      - /^(.*\\/)?node-bin(\\/?$)?/i\n      - /^(.*\\/)?node_modules(\\/?$)?/i\n      - /^(.*\\/)?vendor(\\/?$)?/i\n  test:\n    mocha:\n      options:\n        ui: 'bdd'\n        reporter: 'spec'\n    pattern:\n      - /.+\\.spec\\.js$/i\n    ignore: ~\n\ndeep-todomvc:\n  root: 'src/deep-todomvc'\n```\n\nIn order to let Travis CI know that we have some tests to execute, we go\nback to `.travis.yml` and change the script that will be executing from \n`script: echo \"Hello World!\"` to this:\n\n```yaml\nbefore_install:\n  - npm install -g recink\nscript: recink run unit\n```\n\nOnce we have updated `.recink.yml` and `.travis.yml`, we can commit the code\nback to our repository:\n\n```shell\n# assuming you're still inside the tutorial repository\ngit checkout -b tutorial-step3\ngit add .travis.yml .recink.yml\ngit commit -m \"enable unit testing\"\ngit push --set-upstream origin tutorial-step3\n```\n\n### Step 4: Setup Code Coverage\n\n\u003e Step 4 Branch:\nhttps://github.com/MitocGroup/tutorial-ci-for-serverless/tree/tutorial-step4\n\nNo matter what unit testing tool you might be using, most of them include code\ncoverage capability, which is a measurement in percentage used to describe the\ndegree to which the source code is executed when a particular test suite runs.\nHigher percentage in code coverage has lower probability of bugs and undetected\nissues, especially when you need to make changes to the code.\n\nTo enable code coverage, you need to simply add the following config block to\n`.recink.yml`, after test config block:\n\n```yaml\n---\n$:\n  [...]\n  test:\n    [...]\n  coverage:\n    reporters:\n      text-summary: ~\n    pattern:\n      - /.+\\.js$/i\n    ignore:\n      - /.+\\.spec\\.js$/i\n      - /.+\\.e2e\\.js$/i\n      - /^(.*\\/)?node_modules(\\/?$)?/i\n\ndeep-todomvc:\n  root: 'src/deep-todomvc'\n```\n\nNo changes are necessary to `.travis.yml`.\n\nOnce we have updated `.recink.yml`, we can commit the code back to our\nrepository:\n\n```shell\n# assuming you're still inside the tutorial repository\ngit checkout -b tutorial-step4\ngit add .travis.yml .recink.yml\ngit commit -m \"enable code coverage\"\ngit push --set-upstream origin tutorial-step4\n```\n\n### Step 5: Setup Code Climate\n\n\u003e Step 5 Branch:\nhttps://github.com/MitocGroup/tutorial-ci-for-serverless/tree/tutorial-step5\n\nCode Climate empowers organizations to take control of their code quality by\nincorporating fully configurable test coverage and maintainability data\nthroughout the development workflow. This service allowed us to:\n\n1. Report code analysis over time and enforce industry accepted coding standards\n2. Report code coverage over time and enforce qualitative processes like\n    - fail when code coverage percentage drops lower than X percent\n    - fail when code coverage difference between two consecutive reports drops\n      more than Y percentage points\n\nIn order to do that, we need to update both `.travis.yml` and `.recink.yml`\nlike we did in previous step. Travis CI will store securely Code Climate token,\nwhile recink allow us to cache code coverage reports and enforce above\ndescribed quality metrics.\n\nWe imported GitHub repository into Code Climate (follow\n[this link](https://docs.codeclimate.com/v1.0/docs/importing-repositories)\nfor detailed instructions) and retrieved the code coverage token (follow\n[this link](https://docs.codeclimate.com/v1.0/docs/finding-your-test-coverage-token)\nfor detailed instructions).\n\nUpdate `.recink.yml` with below configuration and replace with your token:\n\n```yaml\n---\n$:\n  [...]\n  coverage:\n    [...]\n  codeclimate:\n    token: '[replace_with_your_token]'\n\ndeep-todomvc:\n  root: 'src/deep-todomvc'\n```\n\nSupport for Code Climate was implemented as an independent recink component,\ntherefore we need to update `.travis.yml` by changing `before_install` and\n`script` lines, as shown below:\n\n```yaml\nbefore_install:\n  - npm install -g recink\n  - npm install -g recink-codeclimate\nscript: recink run unit -c recink-codeclimate\n```\n\nOnce we have updated `.recink.yml` and `.travis.yml`, we can commit the code\nback to our repository:\n\n```shell\n# assuming you're still inside the tutorial repository\ngit checkout -b tutorial-step5\ngit add .travis.yml .recink.yml\ngit commit -m \"enable code climate\"\ngit push --set-upstream origin tutorial-step5\n```\n\n### Step 6: Setup Encryption\n\n\u003e Step 6 Branch:\nhttps://github.com/MitocGroup/tutorial-ci-for-serverless/tree/tutorial-step6\n\nHopefully you felt very uncomfortable to put your code climate token as plain\ntext into GitHub. Don't even want to think that you didn't.\n\nWell, Travis CI offers encryption capability, that allows you to store your\ntokens, credentials and any other secrets. We have integrated this feature into\nrecink as follows:\n\n```shell\n# encrypt Code Climate token\nrecink travis encrypt -x \"CODECLIMATE_REPO_TOKEN=[replace_with_your_token]\"\n```\n\nThis command automatically updates your `.travis.yml`. All that you need to do\nit to update your `.recink.yml` as follows:\n\n```yaml\n---\n$:\n  [...]\n  coverage:\n    [...]\n  codeclimate:\n    token: 'process.env.CODECLIMATE_REPO_TOKEN'\n  preprocess:\n    '$.codeclimate.token': 'eval'\n\ndeep-todomvc:\n  root: 'src/deep-todomvc'\n```\n\nOnce we have updated `.recink.yml` and `.travis.yml`, we can commit the code\nback to our repository:\n\n```shell\n# assuming you're still inside the tutorial repository\ngit checkout -b tutorial-step6\ngit add .travis.yml .recink.yml\ngit commit -m \"enable token encryption\"\ngit push --set-upstream origin tutorial-step6\n```\n\n### Step 7: Setup Code Coverage Compare\n\n\u003e Step 7 Branch:\nhttps://github.com/MitocGroup/tutorial-ci-for-serverless/tree/tutorial-step7\n\nGoing back to code coverage, in theory, you want to have 100% code coverage.\nIn practice, though, this is really difficult to achieve and sustainably\nmaintain. That is why we have adopted a relative comparision process, which\nallows engineers NOT to drop lower than couple of percentage points for each\ncommit or pull request.\n\nFirst, in order to store persistently each code coverage report and reuse it\nfor code coverage compare, we are engaging Amazon S3 as our caching layer.\nTo work with S3, we need\n[AWS credentials](http://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html)\nand [S3 bucket region](http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingBucket.html).\nSimilar to Code Climate token, let's encrypt these secrets:\n\n```shell\n# encrypt aws access key id\nrecink travis encrypt -x \"AWS_ACCESS_KEY_ID=[replace_with_your_access_key]\"\n\n# encrypt aws secret access key\nrecink travis encrypt -x \"AWS_SECRET_ACCESS_KEY=[replace_with_your_secret_key]\"\n\n# encrypt aws region\nrecink travis encrypt -x \"AWS_DEFAULT_REGION=[replace_with_your_region]\"\n```\n\nSecond, in order to allow code coverage reports to be stored in Amazon S3,\nupdate `.recink.yml` as shown below:\n\n```yaml\n---\n$:\n  [...]\n  coverage:\n    [...]\n    compare:\n      negative-delta: 1\n      storage:\n        driver: 's3'\n        options:\n          - 's3://[replace_with_your_s3_bucket]/[replace_with_your_s3_key_space]'\n          -\n            region: 'process.env.AWS_DEFAULT_REGION'\n            accessKeyId: 'process.env.AWS_ACCESS_KEY_ID'\n            secretAccessKey: 'process.env.AWS_SECRET_ACCESS_KEY'\n  codeclimate:\n    token: 'process.env.CODECLIMATE_REPO_TOKEN'\n  preprocess:\n    '$.codeclimate.token': 'eval'\n    '$.cache.options.1.region': 'eval'\n    '$.cache.options.1.accessKeyId': 'eval'\n    '$.cache.options.1.secretAccessKey': 'eval'\n\ndeep-todomvc:\n  root: 'src/deep-todomvc'\n```\n\nOnce we have updated `.recink.yml` and `.travis.yml`, we can commit the code\nback to our repository:\n\n```shell\n# assuming you're still inside the tutorial repository\ngit checkout -b tutorial-step7\ngit add .travis.yml .recink.yml\ngit commit -m \"enable code coverage compare\"\ngit push --set-upstream origin tutorial-step7\n```\n\n### Step 8: Setup Snyk\n\n\u003e Step 8 Branch:\nhttps://github.com/MitocGroup/tutorial-ci-for-serverless/tree/tutorial-step8\n\nSnyk continuously finds and fixes vulnerabilities in your dependencies.\nThis service allowed us to:\n\n1. Automatically test our applications dependencies\n2. Fix security risks through upgrades and patches\n3. Prevent us from adding vulnerable dependencies\n4. Stay alert about new vulnerabilities\n\nSimilar to Code Climate, we need to update both `.travis.yml` and `.recink.yml`\nto enable this feature as part of our Continuous Integration process.\n\nAgain, like in Code Climate step, first retrieve the token from your account\n(follow [this link](https://snyk.io/docs/ci#api-token-configuration) for\ndetailed instructions). Next, encrypt Snyk token, which will update your\n`.travis.yml` file:\n\n```shell\n# encrypt snyk token\nrecink travis encrypt -x \"SNYK_API_TOKEN=[replace_with_your_token]\"\n```\n\nBecause Snyk is built as an independent recink component, we need to enable\nthis feature in `.travis.yml` by changing `before_install` and `script` lines,\nas shown below:\n\n```yaml\nbefore_install:\n  - npm install -g recink\n  - npm install -g recink-codeclimate\n  - npm install -g recink-snyk\nscript: recink run unit -c recink-codeclimate -c recink-snyk\n```\n\nAfter updating `.recink.yml` with below several lines, we'll be able to collect\nsecurity reports from Snyk service:\n\n```yaml\n---\n$:\n  [...]\n  codeclimate:\n    [...]\n  snyk:\n    token: 'process.env.SNYK_API_TOKEN'\n  preprocess:\n    [...]\n    '$.snyk.token': 'eval'\n\ndeep-todomvc:\n  root: 'src/deep-todomvc'\n```\n\nOnce we have updated `.recink.yml` and `.travis.yml`, we can commit the code\nback to our repository:\n\n```shell\n# assuming you're still inside the tutorial repository\ngit checkout -b tutorial-step8\ngit add .travis.yml .recink.yml\ngit commit -m \"enable snyk\"\ngit push --set-upstream origin tutorial-step8\n```\n\n### Step 9: Setup S3 Caching\n\n\u003e Step 9 Branch:\nhttps://github.com/MitocGroup/tutorial-ci-for-serverless/tree/tutorial-step9\n\nTo be updated.\n\nOnce we have updated `.recink.yml` and `.travis.yml`, we can commit the code\nback to our repository:\n\n```shell\n# assuming you're still inside the tutorial repository\ngit checkout -b tutorial-step9\ngit add .travis.yml .recink.yml\ngit commit -m \"enable s3 caching\"\ngit push --set-upstream origin tutorial-step9\n```\n\n### Final Step: Summary\n\nIn this tutorial, we walked you through how to:\n\n1. Setup Continuous Integration (using GitHub and Travis CI)\n2. Setup Unit Testing (using Mocha and REciNK)\n3. Setup Code Coverage and Code Analysis (using Code Climate and REciNK)\n4. Setup Continuous Security (using Snyk and REciNK)\n\nAt the time of writing, our team is working on several more features that will\nbe updated in this tutorial later:\n\n5. Setup Continuous Deployment (using Travis CI and DevOps tools)\n6. Setup End to End Testing (using TestCafe and REciNK)\n7. Setup Continuous Performance (using PageSpeed and REciNK)\n\nAny feedback is welcome! Feel free to reach us at www.mitocgroup.com, report bugs\n[by filing issues here](https://github.com/MitocGroup/tutorial-ci-for-serverless/issues)\nor contribute directly [as described here](CONTRIBUTING.md). Thank you!","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmitocgroup%2Ftutorial-ci-for-serverless","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmitocgroup%2Ftutorial-ci-for-serverless","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmitocgroup%2Ftutorial-ci-for-serverless/lists"}