DEV Community

Toma
Toma

Posted on

Automating Flutter Build

Recently I’ve automated building one of my Flutter projects and I’m planning to continue with every other Flutter (and not only) project. I use Git as a Source Management System. To get myself more up to date with the current trends, I used Docker.

First I grabbed the container from here: https://github.com/jenkinsci/docker/blob/master/README.md

I’ve used the script that maps a directory from the host machine to a directory in the Container:
docker run -p 8080:8080 -p 50000:50000 -v jenkins_home:/var/jenkins_home jenkins/jenkins:lts

This is the starting point to get Jenkins up and running to do whatever you want – in my case Java & Flutter Building, Deployment, Monitoring and fixing stuff, Daily Backups. You could do whatever you’d like.

Part of the building process is placing a hook in “origin” git repository. I’ve updated “post-update” file – to trigger a Jenkins build from remote script so every time I push something, I get a warning if something is broken. If the Jenkins Job has a Deployment subroutine, It is preferred to deploy to a Dev environment, especially if the team is big. Jenkins gives the possibility to link Jobs in a chain so if everything is OK – to proceed ahead.

Next I grabbed a docker file shared by this smart dude https://medium.com/@kyorohiro that has Flutter & Dart in it and just placed the “FROM” docker container source to be the Jenkins. In my personal experience – It requires a little tuning to glue things up. Sometimes there are missing dependencies, environment variables, wrongly typed paths, etc, but, with few initial failed Jenkins Builds, everything is working.

The Flow I’ve set upped is:

  • Git Pull the latest source from the hooked “origin” to a local directory.
  • Execute Flutter Build in the above directory
  • SFTP/SCP/ Upload to my Server

In case of Flutter Web the output is a directory full of files so I've created a simple Java program (Jar) - usable in the future with any other Compile/Build task that produces multiple files - that iterates through the build directory and uploads files only if they are newer than the last modification/Build/.

As a tech guy writing code and exploring “innovative” stuff, I am seeing in myself and also in others – forget the philosophical task of any technology – “to automate things and minimize human labor “. Automating things is working smart. You don’t need special AI to delegate the work that is repeated over and over again and it is every day – the same – to the Computer.

Top comments (2)

Collapse
 
remoteportal profile image
Peter Alvin

I'm new at this but I don't understand--why would you use docker technology for an app? It's not being deployed to a server, right? You just have to upload binaries to the app stores, right?

Collapse
 
tomavelev profile image
Toma

Docker is in the core of Micro Service Architecture and most of the sites I've created are monolithic. Docker is used for the building process of my apps. I must clarify that, I'm more of a Java/Back-end/Full Stack developer. I needed to scratch a little bit Docker so I get to know it and use it. You cannot say anything authentic about any technology if haven't used it. And with Flutter - today you could create (HTML) Web Apps (or Android APKs)- that do not need app stores ( developapp.online/ - this is a Flutter Web app that creates flutter web apps (still in beta)). On my computer I run a Docker with Jenkins CRON tasks - with building, testing, etc that runs separately to all other software of my computer - so - this is a cool feature of Docker.