Why Use CI/CD for Flutter Apps?
Faster Releases
Fewer Mistakes
Better Code Quality
Good for Remote Teams
Why Combine CI/CD with Docker?
No More “It Works on My Machine”
Fixed Versions
Reusable Environment
Step-by-Step Guide to Set Up CI/CD for Flutter with Docker
Step 1: Create a Dockerfile
The Dockerfile tells Docker how to set up the environment for your app. Here’s a simple Dockerfile:
FROM cirrusci/flutter:stable
WORKDIR /app
COPY . .
RUN flutter pub get
CMD ["flutter", "build", "apk"]
This does the following:
-
Uses the latest stable Flutter Docker image.
-
Sets the working directory to /app.
- Copy your code into the container.
- Runs flutter pub get to install packages.
-
Builds the APK (Android app) when the container starts.
Step 2: Add a .dockerignore File
This file tells Docker to ignore certain folders and files that are not needed in the container.
build
.dart_tool
.idea
packages
*.iml
Skipping these files makes your build faster and smaller.
Step 3: Build Your Docker Image
Now, run this command to create the Docker image from your Dockerfile:
docker build -t flutter-app .
This creates a new image with the name flutter-app.
Step 4: Test the Docker Image Locally
Run the container using:
docker run -it flutter-app
This builds your Flutter app inside the container and shows any errors or warnings, just like on your local machine.
Step 5: Set Up GitHub Actions (Your CI/CD Pipeline)
Here’s the code:
name: Flutter CI/CD Pipeline
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Docker
uses: docker/setup-buildx-action@v2
- name: Build Docker Image
run: docker build -t flutter-app .
- name: Export APK
run: docker run -v ${{ github.workspace }}:/app flutter-app
-
Runs the workflow every time code is pushed to the main branch.
-
Builds the Docker image.
- Runs the Flutter build inside Docker.
- Places the built APK in your project folder.
Bonus Step: Add Deployment
-
Firebase App Distribution – Share your APK with testers.
-
Google Play Store – Use Fastlane to automate Play Store uploads.
- Apple App Store – Use Codemagic + Fastlane for iOS releases.
CI/CD + Docker = Happy Developers
- “Organizations using CI/CD pipelines reduced deployment failures by 47% and time-to-market by 62%.”
Conclusion
-
Flutter app development
-
Docker-based environments
- Building CI/CD pipelines for mobile apps
Mohit Kokane
A highly skilled Flutter Developer. Committed to delivering efficient, high-quality solutions by simplifying complex projects with technical expertise and innovative thinking.
Reply