Automating Flutter Build
Toma
Posted on September 7, 2019
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.
Posted on September 7, 2019
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.