Written by Souvik Biswas
Most software companies face one big challenge, delivering their product on time and meeting deadlines. 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.
The process of Continuous Integration (for app) mainly comprises of the following steps:
- Building the app (from code)
- Running various tests (Unit tests, Integration tests, etc.)
- 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.
- There is also 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.
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 be 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 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 and to get faster feedback from 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 benefits. While it’s great to have choices, it also is 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.
- One of the biggest benefit 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”. Jenkins is the best example for this as it has support for over 1500 plugins.
- Even if your chosen self hosted CI/CD does not have first-class support for a plugin, you can usually make things work with some shell scripts and a little bit of creativity.
- Self hosted solutions have fewer limitations on things like build configurations and concurrent build jobs, as you are using your own hardware for running the pipelines.
- 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.
- 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.
- 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 an 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 a click of a button.
Some of the main steps that every pipelining script contains are:
- Source phase
- Building phase
- Testing phase
- Deployment 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 presents the repository to trigger a pipeline script to run.
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.
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 and 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.
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 smoother 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.
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 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.
Ultimately, CI/CD results in a much faster and consistent deployment workflow with fewer bugs, producing 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:
- How Mac Pro is saving you 40% of your build time
- How to add Flutter modules to native Android project and test it on Codemagic
- Why Android Developers should pay attention to Flutter in 2020