firebase-ci v0.4.1-alpha
firebase-ci
Simplified Firebase interaction for continuous integration
Features
- Skip For Pull Requests
- Deploy to Different Firebase Instances based on Branch
- Mapping of CI environment variables to Firebase Functions Config
- Create a config file based on CI environment variables
- Optional Deploying of targets Functions, Hosting, Database (rules) and Storage (rules)
Getting Started
- Generate a CI token through
firebase-toolsby runningfirebase login:ci - Place this token within your CI environment under the variable
FIREBASE_TOKEN - Install
firebase-ciinto your project (so it is available on your CI):npm install --save-dev firebase-ci Add the following scripts to your CI config:
npm i -g firebase-ci@latest # install firebase-ci tool firebase-ci deploy # deploys only on branches that have a matching project name in .firebasercFor instance within a
travis.yml:after_success: - npm i -g firebase-ci - firebase-ci deployNOTE:
firebase-cican be used through the nodejsbininstead of being installed globallySet different Firebase instances names to
.firebaserclike so:{ "projects": { "prod": "prod-firebase", "master": "dev-firebase", "default": "dev-firebase" } }
Examples
- Basic - Basic html file upload to Firebase hosting of different projects (or "environments")
Why?
Advanced configuration of Firebase deployment is often necessary when deploying through continuous integration environment. Instead of having to write and invoke your own scripts, firebase-ci provides an easy way to create/modify advanced configurations.
What about Travis's firebase deploy option?
Using the built in travis firebase deploy tool is actually a perfect solution if you want to do general deployment. You can even include the following to install stuff functions dependencies on Travis:
after_success:
- npm install --prefix ./functions
deploy:
provider: firebase
project: $TRAVIS_BRANCH
skip_cleanup: true
token:
secure: $FIREBASE_TOKENThis lets you deploy to whatever instance you want based on your branch (and config in .firebaserc).
firebase-ci is for more advanced implementations including only deploying functions, hosting
Commands
copyVersion- Copy version frompackage.jsontofunctions/package.jsoncreateConfig- Create a config file based on CI environment variables (defaults tosrc/config.js)deploy- Deploy to Firebase (runs other actions by default)mapEnv- Map environment variables from CI Environment to Firebase functions environment
copyVersion
It can be convenient for the version within the functions/package.json file to match the top level package.json. Enabling the copyVersion option, automatically copies the version number when calling deploy if the following config is provided:
"ci": {
"copyVersion": true
}createConfig
Create a config file based on CI environment variables (defaults to src/config.js)
With the following environment variables:
GA_TRACKINGID - Your google analytics tracking id
INT_FIREBASE_WEBAPIKEY - API key of your integration/main Firebase instance (this can also be hard coded if you prefer since it doesn't)
PROD_FIREBASE_WEBAPIKEY - API key of your production Firebase instance
And a .firebaserc that looks like so:
"ci": {
"createConfig": {
"master": {
"version": "${npm_package_version}",
"gaTrackingId": "${GA_TRACKINGID}",
"firebase": {
"apiKey": "${INT_FIREBASE_WEBAPIKEY}",
"authDomain": "firebase-ci-int.firebaseapp.com",
"databaseURL": "https://firebase-ci-int.firebaseio.com",
"projectId": "firebase-ci-int",
"storageBucket": "firebase-ci-int.appspot.com"
}
},
"prod": {
"version": "${npm_package_version}",
"gaTrackingId": "${GA_TRACKINGID}",
"firebase": {
"apiKey": "${PROD_FIREBASE_WEBAPIKEY}",
"authDomain": "firebase-ci.firebaseapp.com",
"databaseURL": "https://firebase-ci.firebaseio.com",
"projectId": "firebase-ci",
"storageBucket": "firebase-ci.appspot.com"
}
}
}
}building on master branch, produces a file in src/config.js that looks like so:
export const version = "0.0.1" // or whatever version your package is
export const gaTrackingId = "123GA" // your google analytics tracking ID
export const firebase = {
apiKey: "<- your app API key ->",
authDomain: "<- your app name ->.firebaseapp.com",
databaseURL: "https://<- your app name ->.firebaseio.com",
projectId: "<- your app name ->",
storageBucket: "<- your app name ->.appspot.com"
}
export default { version, gaTrackingId, firebase }deploy
firebase-ci deploy
Options:
Deploy to Firebase. Following the API of firebase-tools, specific targets (i.e. functions, hosting) can be specified for deployment.
Default
- Everything skipped on Pull Requests
- Deployment goes to default project
- If you have a
functionsfolder,npm installwill be run for you within yourfunctionsfolder copyVersionis called before deployment based on settings in.firebaserc, if you don't want this to happen, use simple mode.mapEnvis called before deployment based on settings in.firebaserc, if you don't want this to happen, use simple mode.
Simple Mode
Option: --simple
Flag: -s
Skip all firebase-ci actions and only run Firebase deployment
Info Option
Option : --info
Flag: -i
Provide extra information from internal actions (including npm install of firebase-tools).
Skipping Deploying Functions
If you have a functions folder, your functions will automatically deploy as part of using firebase-ci. For skipping this functionality, you may use the only flag, similar to the API of firebase-tools.
after_success:
- npm i -g firebase-ci
- firebase-ci deploy --only hostingmapEnv
firebase-ci mapEnv
Set Firebase Functions variables based on CI variables. Does not require writing any secure variables within config files.
NOTE: Called automatically during firebase-ci deploy
Set the mapEnv parameter with an object containing the variables you would like to map in the following pattern:
TRAVIS_VAR: "firebase.var"Example
CI variable is SOME_TOKEN="asdf" and you would like to set it to some.token on Firebase Functions you would provide the following config:
"ci": {
"mapEnv": {
"SOME_TOKEN": "some.token"
}
}Internally calls firebase functions:config:set some.token="asdf". This will happen for every variable you provide within mapEnv.
Roadmap
setCORSoption for copying CORS config file to Cloud Storage Bucket- only setting non existent env vars with
mapEnv - Support for Continuous Integration Tools other than Travis-CI
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago