Categories:
Search articles

Search for articles

Sorry, but we couldn't find any matches...

But perhaps we can interest you in one of our more popular articles?

The Complete Guide to Continuous Integration and Delivery (CI/CD)

Jan 31, 2020

Written by Souvik Biswas

Most software companies face one big challenge, delivering their product on time and meeting the deadline. To make their work easier there's an amazing tool known as CI/CD.

Some of the topics that I will be covering in this article are:

  • What is CI/CD?
  • Choosing between Self Hosted and Cloud based CI/CD
  • What is a Pipeline?
  • Benefits of using CI/CD
  • Why a dedicated CI/CD is necessary for Flutter?

Let's take a deep dive into CI/CD.

What is CI/CD?

CI/CD is a tool that helps to automate the tedious tasks, from building the app to deploying it into production, which makes every developer's life a lot easier. There are different kinds of CI/CD solutions available for app, web, and even for ML/AI.

The acronym CI stands for Continuous Integration and CD can either mean Continuous Delivery or Continuous Deployment. Let's explore these in more details.

In this article I will mostly be focusing on CI/CD for apps.

Continuous Integration

The process of Continuous Integration (for app) mainly comprises of the following steps:

  1. Running various tests (Unit tests, Integration tests, etc.)
  2. Building the app (from code)
  3. Creating artifacts (.apk, .ipa, etc.) which can be later used in the distribution.

The Continuous Integration for ML/AI is a bit different from the traditional CI steps.

  • In building stage of ML/AI, data is also sent along with the code.
  • Also there is an additional stage after building, that is the training stage for the ML model, which takes the most compute time in the entire process.
  • A trained ML model is generated as the artifact in this case.

For more information regarding CI/CD for ML & AI, you can take a look at this article.

Continuous Delivery

Continuous Delivery is used to release a newly built version of your app to the customers as quickly as possible. Every time a new version is built successfully, it can merged with the git-based repository hosting platform (like, GitHub, GitLab, etc.) and you can easily deploy the new version of your application at any point of time with the click of a button.

Continuous Deployment

Continuous Deployment goes one step further than the continuous delivery. It also prevents the last level of human intervention in the pipeline by automating the deployment of your app build. Only a failed build or test will prevent a new change to be deployed into production. This is mainly used to accelerate the app production, to get faster feedbacks from the customers. Also, teams following this process of deployment, doesn't need to have a Release Day anymore!

Choosing between Self Hosted and Cloud based CI/CD

The CI/CD platform market has grown over the years as DevOps become more mainstream, and now encompasses a huge variety of tools, each with their own flavor. While it’s great to have choices, it proved to be a really tough decision to choose the right tool.

Some of the pros and cons of these two kinds of CI/CD solution are listed below.

Self-hosted

Self-hosted CI/CD solutions basically run on the local machine of the user with the software packages installed on that machine. Some examples of self-hosted CI/CD tools are Jenkins, TeamCity, etc.

Pros

  • One of the biggest benefits of a self-hosted solution is extensibility. Some self-hosted services can be customized with plugins to enable functionality that is not included β€œout of the box”.
  • Managing security of the entire CI/CD system is your own responsibility. This can be an extremely time consuming and difficult job, but you do not have to rely on the security of the external providers. Eliminating the need to go outside of your private networks helps to minimize security threats.

Cons

  • You have to maintain your own hardware systems and keep the softwares updated for preventing build failures in the future.
  • Initially, there can be a very time intensive setup process for linking your projects with VCS, issue tracking and notification systems.
  • Have to manage all the authentication needed for the team members for accessing the projects.

Cloud-based

Cloud-based CI/CD (also known as SaaS tools) uses hardware systems and the softwares stored on a cloud server. Some examples of cloud-based CI/CD tools are Travis CI, CircleCI, Codemagic, etc.

Pros

  • The biggest benefit of using cloud-based CI/CD solution is that you do not have to maintain any hardware or software infrastructure. All the software updates are also handled by the cloud based CI/CD provider.
  • Initial setup is fast and easy. Also most of the SaaS CI/CD solutions have a good integration with git based VCS like GitHub, GitLab, Bitbucket, etc.

Cons

  • There might be some extra cost that you have to bear, as per the service you will be using. And the price of a Cloud based CI/CD service may go up as your team gets larger.
  • All Cloud based CI/CD solutions do not have support for all platforms, tools, and environments.

What is a Pipeline?

The path that software follows from start to finish for its deployment is known as a pipeline. In other words, it is the step by step specification that a new version of software follows.

You can also setup notifications at the end of every important process of the pipeline, so that all the team members remain in sync during the whole timeline of the project. Most of the CI/CD solutions provide a easy setup of the notifications in terms of email, Slack, etc.

Pipelining is used to automate the process of deployment because you just have to specify the pipeline script once, and from the next time onwards the whole script will run with just click of a button.

Some of the main steps that every pipelining script contains are:

  1. Source phase
  2. Testing phase
  3. Building phase
  4. Deployment phase

Source Phase

This is the phase which marks the starting point of a CI/CD pipeline. It is mostly a source code repository (like GitHub, GitLab, etc.). A change in the code present in the repository triggers a pipeline script to run.

Testing Phase

In the testing phase, all automated tests are run to validate the correctness of the code. This phase may consist of several types of tests, like Unit tests, UI tests, Integration tests. This acts as a safety net that prevents some of the unusual bugs from reaching the end-users. A failure during the testing phase exposes problems in the code that might have been looked over by the developer while writing the code.

Building Phase

In this phase the code and dependencies are combined to create a runnable instance of the software. If this step fails then there is an issue with the code or its dependencies.

In case of an app, code signing is an important step in this phase if you are building it for production use and want to deploy it to Google Play Store or Apple App Store.

Deployment Phase

At this phase the software is properly tested and the build artifact is ready to be deployed. There are multiple ways to deploy the final artifact, for example “alpha", “beta” or “production” environment.

Benefits of using CI/CD

CI/CD pipeline makes it a lot easier for teams to keep organized and make fast deployments on time.

  • Developers can just worry about their code and dependencies, not runtime configuration.
  • Every code change has to pass through the testing phase, which prevents any code mistakes to be pushed and merged in the final version of the app. Thus every mistake is fixed at point of occurrence.
  • The process of introducing new versions and bug fixes are a lot smooth using CI/CD. So, this results in a much faster production.
  • This also helps to get faster feedback from the developers as well as from the end-users of the software.
  • Pipelining script helps you to visualize the whole software delivery process from building to deployment at a glance.

Why a dedicated CI/CD is necessary for Flutter?

Flutter is a cross-platform app development framework created by Google, which uses a single codebase for mobile (Android & iOS), web and desktop.

You can use most of the CI/CD tool with Flutter, but in that case, you need to set up for each platform separately, which completely overlooks the advantage of having a single code base. Apart from this, you might have to use separate pipelines for generating the build artifacts for each platform, which is really very painful.

So, there is a need for a dedicated CI/CD tool that can do all the steps, from building to deployment, for every platform using just a single pipeline.

Codemagic was introduced as the first dedicated CI/CD solution only for Flutter. But now it also has support for non-Flutter apps using codemagic.yaml. This makes it capable of building, testing and delivering native Android & iOS apps with Flutter modules added to it.

Simple workflow

You can define workflows on Codemagic simply by using the Codemagic UI. You can use a single workflow for multiple platforms, or you can just make separate workflows for different platforms and run them concurrently.

Codemagic Docs for Creating multiple workflows

Multiple platform support

Codemagic has support for Android, iOS, Web, macOS and Linux, which is a must have for a dedicated CI/CD tool for Flutter.

Painless code signing

As you might know code signing is an important step for publishing an Android or iOS app to Play Store or App Store respectively. Codemagic provides really easy code signing process for both the mobile platforms. Even you can sign your iOS apps without owning a Mac yourself.

Codemagic Docs for Android code signing

Codemagic Docs for iOS code signing

Great testing support

Codemagic supports all types of Flutter tests including unit, integration and widget tests as well as static code analysis with flutter analyze.

Advanced configuration with YAML

This feature helps you to specify the whole pipeline using a single YAML file, known as codemagic.yaml. Additionally, you can use this advanced feature for running your native apps with Flutter Modules.

You can check out this article for more info about adding Flutter modules to a native Android project.

Conclusion

Ultimately, CI/CD results in a much faster and consistent deployment workflow with fewer bugs, produce great end-user products. A good CI/CD pipeline helps to build faster, deploy faster and as a team, grow faster. A dedicated CI/CD for new emerging technologies (like Flutter) is great to have because it simplifies the deployment workflow to a large extent.


Souvik Biswas is a passionate Mobile App Developer (Android and Flutter). He has worked on a number of mobile apps throughout his journey. Loves open source contribution on GitHub. He is currently pursuing a B.Tech degree in Computer Science and Engineering from Indian Institute of Information Technology Kalyani. He also writes Flutter articles on Medium - Flutter Community.

More articles by Souvik: