Deploying a Flutter application to production is mostly easy - simply make a build and upload it to the store. However, for web applications built with Flutter, we need to upload our build to the web server.
To build a web application, simply run:
flutter build web --base-href "/webapp/" --release
But what if we would like to deploy it to our server right away? To do this, we can use a great Docker image instrumentisto/flutter, which is basically a ready-to-use Flutter development environment packed into a Docker image.
One of the simplest ways is to run our pipeline directly on the web server. The prerequisite is that we have Docker installed there.
So to build a Flutter app, use this code in the pipeline:
docker run --rm -v ./:/app -w /app instrumentisto/flutter flutter build web --release
This would deploy the web application into the ./build/webapp folder. Now you can copy it to your web server like this:
rsync -r --delete build/web/* /my/sebserver/location
and here is the full pipeline as an example:
pipelines:
default:
- step:
name: build staging web app
runs-on:
- 'self.hosted'
- 'linux.shell'
script:
- docker run --rm -v ./:/app -w /app instrumentisto/flutter flutter build web --release
- rsync -r --delete ./build/web/* /opt/webapp/