If you are doing manually, the deployment of a web app can be repeated. Whenever you put the code on your reservoir, the Gut Hub Action Permanently deploy your app to firebase hosting and automate it.
This guide operates by the establishment of a firebase hosting, the formation of the actions of the gut hub, and the management of the deployment. Finally, you will have a reliable CI/CD pipeline for your fluttering web project.
Table of contents:
Provisions
Before diving, make sure you have these ready:
1.: You can install the sprouts FlutteringThen confirm the installation:
flutter --version
2. Firebase CLI installed: The Fire Base CLI allows you to discuss with the firebase hosting. Install through the NPM like this:
npm install -g firebase-tools
Check with installation:
firebase --version
3. A gut hub repository: Your flurry plan should be pushed towards the gut hub.
4. Firebase project formed: Barley Firebase consoleMake a project, and enable firebase hosting.
Step 1: Set up a firebase hosting
Start the firebase in your project
Open your terminal and go to your project:
cd path/to/your/flutter/project
Start the firebase hosting:
firebase init
During the setup, you will need to provide some information:
Hosting: Select firebase hosting.
Public Directory: Enter
build/web
(This is the place where the web -emitting webs make it).Single page app: Select Yes (Write all routes again
/index.html
,Automatic construction: You can leave because we will manually form gut hub actions.
Step 2: Create a firebase hosting
A file called firebase.json
Will be created. Make sure it seems:
{
"hosting": {
"public": "build/web",
"ignore": (
"firebase.json",
"**/.*",
"**/node_modules/**"
)
}
}
hosting.public
The firebase tells where your bullet app is to find (build/web
,ignore
Files should not upload the firebase (hidden files, configured files,node_modules
,
You can also see A .firebaserc
File for Project Eliasing:
{
"projects": {
"default": "your-project-id"
}
}
It connects your local project to your firebase project ID.
Step 3: Add a firebase formation in the flurry
When you connect the firebase with a flurry (through flutterfire
CLI), it produces a file like firebase_options.dart
.
In you main.dart
Start the Fire Base:
import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
runApp(MyApp());
}
WidgetsFlutterBinding.ensureInitialized()
This ensures that the flock engine is already ready before the start of the firebase.Firebase.initializeApp()
Using auto -made options connect your app to the firebase.
Step 4: Create the actions of the Gut Hub
Now we will create a workflow that automatically manufactures and deploys your fluttering web app.
Create a file in your repo: .github/workflows/firebase-hosting.yml
name: Deploy to Firebase Hosting
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build_and_deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Set up Flutter
uses: subosito/flutter-action@v3
with:
flutter-version: '3.24.1'
- name: Install Dependencies
run: flutter pub get
- name: Build Flutter Web
run: flutter build web --release
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install Firebase CLI
run: npm install -g firebase-tools
- name: Deploy to Firebase Hosting
run: firebase deploy --only hosting --project
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
What is happening in this code is here:
Check Out Repository: Pulls your code into a runner.
Fluttering: Instals a specific version.
Install dependent: Moves
flutter pub get
.Create a web fluttering: Create the release version of your web app.
Node. Set JS: Firebase is required for CLI.
Install Firebase CLI: Firebase deployment device installs.
Deploy in firebase hosting: Deploy built -in files to the fire base.
Step 5: Set up a firebase token
Gut hub needs a token to verify with the firebase.
Drive it locally:
firebase login:ci
Then copy the token shown.
Next, go to yourself Gut hub repository → Settings → Secret and variable → Actions.
Create a new secret whose name is: FIREBASE_TOKEN
And paste into the token you copied. It protects your credentials.
Step 6: Verification and Monitor deployment
Thus commit a workflow file:
git add .github/workflows/firebase-hosting.yml
git commit -m "Setup GitHub Actions for Firebase Hosting"
git push origin main
Go to your gut hub repo, select the action tab, and then watch the workflow run. You will see an interface that looks like these images:
Once it succeeds, go to it:
Advanced compositions
Custom Blood
If you need a specific presentants (eg, HTML instead of canvaskat):
run: flutter build web --release --web-renderer html
Multiple environments (staging and production)
run: firebase deploy --only hosting --project ${{ secrets.FIREBASE_PROJECT }}
Specify FIREBASE_PROJECT
As a secret to each environment.
Cache depends (high -speed Bloods)
- name: Cache Flutter Dependencies
uses: actions/cache@v3
with:
path: ~/.pub-cache
key: ${{ runner.os }}-pub-cache-${{ github.sha }}
restore-keys: |
${{ runner.os }}-pub-cache-
Tracing defects
You may face some common problems. There are some quick fixes to help you deal with:
Skip | Fix |
There is no active project | Drive firebase use --add Check locally and .firebaserc . |
node.js version matching | Be sure node-version: '18' In the workflow |
Firebase CLI errors | Re -install with npm install -g firebase-tools . |
Outdated warnings in the index HTML | Update the latest fluttering web template. |
Wrap
By connecting a firebase hosting with gut hub action, now you have a CI/CD Pipeline For your fluttering web app.
Every push main
Keep your app live with zero manual effort.
To make a deep diver, check: