Automate whatever you can automate and share the responsibility for the remaining tasks\n---------------------------------------------------------------------------------------\n\n_This blog post is part of a series where I share our migration from monolithical applications (each with their own source repository) deployed on AWS to a distributed services architecture (with all source code hosted in a monorepo) deployed on Google Cloud Platform._\n\n* _Part 1: “_[_A monorepo, GitHub Flow and automation FTW_](https://hackernoon.com/a-monorepo-github-flow-and-automation-ftw-c41a2d9c48bb)_”_\n* _Part 2: “_[_One vs. many — Why we moved from multiple git repos to a monorepo and how we set it up_](https://medium.com/@mikenikles/one-vs-many-why-we-moved-from-multiple-git-repos-to-a-monorepo-and-how-we-set-it-up-f4abb0cfe469)_”_\n* _Part 3 (this post): “A (mostly) automated release process”_\n* _Part 4: “_[Our approach to software development consistency](https://medium.com/@mikenikles/our-approach-to-software-development-consistency-d101995bb843)_”_\n* _Part 5 (coming soon): “Debug microservices locally”_\n\n### What is a “release process”?\n\n> Release management is the process of managing, planning, scheduling and controlling a software build through different stages and environments; including testing and deploying software releases. \n> Source: [Wikipedia](https://en.wikipedia.org/wiki/Release_management)\n\nWoah… That’s one long-a\\*\\* sentence, it reminds me of German sentences I wrote in my essays when I grew up in 🇨🇭.\n\nA slightly less verbose way of putting it:\n\n> “How to get code from my laptop to production.” \n> Source: [Me](https://twitter.com/mikenikles)\n\nIn the end, it’s all about code and along the journey we want to do certain things to or with the code. Such as:\n\n* [KISS](https://en.wikipedia.org/wiki/KISS_principle); tools like [ESLint](https://eslint.org/docs/about/) can help with that.\n* Keep consistent formatting. [Prettier](https://prettier.io/) is your must-have tool here.\n* Run tests.\n* Bundle reusable code into packages and deploy them to NPM.\n* Build services that leverage the aforementioned packages.\n* Give stakeholders a chance to review code in some more or less safe environment, often referred to as “staging”.\n* Take that reviewed code and deploy it to where it really matters: 🥁 … \n the production environment 🎉\n\n### Why “automated”?\n\nGreat question, glad you asked. Mainly, because we can. More importantly though, most developers I know spend day after day writing code because they feel good when they release software that helps others (your mileage may vary). Rarely (never?) have I met passionate developers who say, “You know, I simply love to manually ssh into my virtual machine, run `git pull`, then `sh ./scripts/release-carefully.sh --production=true` and hope for the best 🤞”.\n\nAs a rule of thumb,\n\n> If a task can be automated in roughly the time it takes to execute it manually, automate it. Now.\n\nHere’s why: Passionate software engineers want to spend their time dealing with more important situations. Automating mundane tasks should be a priority for anyone in the software industry. Let’s do some math and see why:\n\n* Manually deploying a new feature to your staging environment takes 21 minutes, give or take.\n* You do that once a day, five days a week.\n* Here’s the math: 21 minutes x 5 days per week = 105 minutes per week x 4 weeks = 420 minutes per month.\n\n!(https://hackernoon.com/hn-images/1*I2UEJj2yLfpeH734V8oT0A.png)\n\nSource: [Google](https://www.google.ca/search?ei=5j4_Wv2MOpiajwOvjLz4CQ&q=400+minutes+to+hours&oq=400+minutes+to+hours&gs_l=psy-ab.3..0j0i5i10i30k1j0i5i30k1j0i8i30k1l2.126360.126360.0.126718.104.22.168.0.0.0.176.176.0j1.1.0....0...1.1.64.psy-ab..0.1.175....0.Tsb9aXPHVHE)\n\nSeven hours per month is **1 full business day**. As an exercise for the reader, you could add the time it takes to deploy to production plus dealing with potential hotfix deployments.\n\nLet’s say you end up with 2 to 3 business days as the grand total. Instead of spending that time month after month, invest it into writing automation scripts. In the second month, you’ll have 2 to 3 extra business days where you can mentor a more junior team member or organize a lunch & learn to share the ins and outs of your release automation script with the community in your city 🙌.\n\n### Why “mostly”?\n\nI have yet to encounter a 100% automated release process for a software application. While this is certainly achievable for libraries, frameworks, etc., it is a different beast for an application.\n\nAt the very least, and this is what our goal at work was before we started automating the release process, an automated release requires two manual approvals:\n\n1. To deploy to staging.\n2. To deploy to production.\n\n### So… Here’s how we release our services\n\nWith the above in mind, the following diagram which I briefly mentioned in [my first blog post of this series](https://hackernoon.com/a-monorepo-github-flow-and-automation-ftw-c41a2d9c48bb) outlines our (mostly) automated release process:\n\n!(https://hackernoon.com/hn-images/1*i8ySffq8oMkVGng82RkDlw.png)\n\nAs you can see, we use [CircleCI](https://circleci.com/). With CircleCI 2.0 and [Workflows](https://circleci.com/docs/2.0/workflows/), the above translates to the following `[.circleci/config.yml](https://circleci.com/docs/2.0/configuration-reference/)` file:\n\nYou notice 7 configured workflow jobs, they correspond to the 7 rectangles in the diagram above.\n\nThe `yarn deploy:*` scripts we call during the deployment jobs are thin wrappers around the Google Cloud Platform `gcloud` CLI. The scripts run some validation and a bit of logic to deal with the staging vs production situation.\n\nThis is all pretty new for us. It works well, but we always look at ways to speed up the process or simplify it. One next major step is to integrate a way to automatically create `CHANGELOG.md` files for each package / service and let the system determine the appropriate [semver](https://semver.org/) version when publishing to NPM. Something like [https://conventionalcommits.org/](https://conventionalcommits.org/) looks interesting 🤔.\n\n### Conclusion\n\nIt’s been a great journey with ups and downs, but the end result is something that makes our day to day life simple.\n\nStarting in 2018, each microservice will have owners, a team of at least two developers. Being a service owner follows the “You build it, you run it” principle. With the release process described in this blog post, each pull request gets deployed to production before it gets merged into `master`. The owners will be responsible not only for the development, but also for the service’s deployment, it’s monitoring and support. \nAnyone at the company is free to open PRs in services they don’t own if there’s a bug. The service owners though [will have the final word on approving PRs](https://help.github.com/articles/about-codeowners/).\n\nLet me know if you have questions, thoughts, suggestions etc about the above approach. I’d love to discuss and learn how others deploy to production.