0.4.1-alpha • Published 8 years ago

firebase-ci v0.4.1-alpha

Weekly downloads
550
License
MIT
Repository
github
Last release
8 years ago

firebase-ci

Simplified Firebase interaction for continuous integration

NPM version Build Status Dependency Status Code Climate Code Coverage License Code Style

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

  1. Generate a CI token through firebase-tools by running firebase login:ci
  2. Place this token within your CI environment under the variable FIREBASE_TOKEN
  3. Install firebase-ci into your project (so it is available on your CI): npm install --save-dev firebase-ci
  4. 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 .firebaserc

    For instance within a travis.yml:

    after_success:
      - npm i -g firebase-ci
      - firebase-ci deploy

    NOTE: firebase-ci can be used through the nodejs bin instead of being installed globally

  5. Set different Firebase instances names to .firebaserc like 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_TOKEN

This 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 from package.json to functions/package.json
  • createConfig - Create a config file based on CI environment variables (defaults to src/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 functions folder, npm install will be run for you within your functions folder
  • copyVersion is called before deployment based on settings in .firebaserc, if you don't want this to happen, use simple mode.
  • mapEnv is 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 hosting

mapEnv

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

  • setCORS option 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
0.15.1

5 years ago

0.15.0

5 years ago

0.14.0

6 years ago

0.14.0-alpha

6 years ago

0.13.0

6 years ago

0.12.2

6 years ago

0.12.1

6 years ago

0.12.0

6 years ago

0.11.1

6 years ago

0.11.0

6 years ago

0.10.0

6 years ago

0.9.1

6 years ago

0.9.0

6 years ago

0.8.0

6 years ago

0.7.0

6 years ago

0.6.0

7 years ago

0.5.8

7 years ago

0.5.7

7 years ago

0.5.6

7 years ago

0.5.5

7 years ago

0.5.4

7 years ago

0.5.3

7 years ago

0.6.0-alpha

7 years ago

0.5.2

7 years ago

0.5.1

7 years ago

0.5.0

7 years ago

0.5.0-beta.3

7 years ago

0.5.0-beta.2

7 years ago

0.5.0-beta

8 years ago

0.5.0-alpha.5

8 years ago

0.5.0-alpha.4

8 years ago

0.5.0-alpha.3

8 years ago

0.5.0-alpha.2

8 years ago

0.5.0-alpha

8 years ago

0.4.6

8 years ago

0.4.5

8 years ago

0.4.4

8 years ago

0.4.3

8 years ago

0.4.2

8 years ago

0.4.1

8 years ago

0.4.1-alpha

8 years ago

0.4.0

8 years ago

0.4.0-beta

8 years ago

0.4.0-alpha.9

8 years ago

0.4.0-alpha.8

8 years ago

0.4.0-alpha.7

8 years ago

0.4.0-alpha.6

8 years ago

0.4.0-alpha.5

8 years ago

0.3.1

8 years ago

0.4.0-alpha.4

8 years ago

0.4.0-alpha.3

8 years ago

0.4.0-alpha.2

8 years ago

0.4.0-alpha

8 years ago

0.3.0

8 years ago

0.2.2

9 years ago

0.2.2-alpha.4

9 years ago

0.2.2-alpha.3

9 years ago

0.2.2-alpha.2

9 years ago

0.2.2-alpha

9 years ago

0.2.1

9 years ago

0.2.0

9 years ago

0.2.0-beta

9 years ago

0.2.0-alpha.48

9 years ago

0.2.0-alpha.47

9 years ago

0.2.0-alpha.46

9 years ago

0.2.0-alpha.45

9 years ago

0.2.0-alpha.44

9 years ago

0.2.0-alpha.43

9 years ago

0.2.0-alpha.42

9 years ago

0.2.0-alpha.41

9 years ago

0.2.0-alpha.40

9 years ago

0.2.0-alpha.39

9 years ago

0.2.0-alpha.38

9 years ago

0.2.0-alpha.37

9 years ago

0.2.0-alpha.36

9 years ago

0.2.0-alpha.35

9 years ago

0.2.0-alpha.34

9 years ago

0.2.0-alpha.33

9 years ago

0.2.0-alpha.32

9 years ago

0.2.0-alpha.31

9 years ago

0.2.0-alpha.30

9 years ago

0.2.0-alpha.29

9 years ago

0.2.0-alpha.28

9 years ago

0.2.0-alpha.27

9 years ago

0.2.0-alpha.26

9 years ago

0.2.0-alpha.25

9 years ago

0.2.0-alpha.24

9 years ago

0.2.0-alpha.23

9 years ago

0.2.0-alpha.22

9 years ago

0.2.0-alpha.21

9 years ago

0.2.0-alpha.20

9 years ago

0.2.0-alpha.19

9 years ago

0.2.0-alpha.18

9 years ago

0.2.0-alpha.17

9 years ago

0.2.0-alpha.16

9 years ago

0.2.0-alpha.15

9 years ago

0.2.0-alpha.14

9 years ago

0.2.0-alpha.13

9 years ago

0.2.0-alpha.12

9 years ago

0.2.0-alpha.11

9 years ago

0.2.0-alpha.10

9 years ago

0.2.0-alpha.9

9 years ago

0.2.0-alpha.8

9 years ago

0.2.0-alpha.7

9 years ago

0.2.0-alpha.6

9 years ago

0.2.0-alpha.5

9 years ago

0.2.0-alpha.4

9 years ago

0.2.0-alpha.3

9 years ago

0.2.0-alpha.2

9 years ago

0.2.0-alpha

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago

0.1.0-rc.7

9 years ago

0.1.0-rc.6

9 years ago

0.1.0-rc.5

9 years ago

0.1.0-rc.4

9 years ago

0.1.0-rc.3

9 years ago

0.1.0-rc.2

9 years ago

0.1.0-rc.1

9 years ago

0.1.0-beta

9 years ago

0.1.0-alpha

9 years ago

0.0.8

9 years ago

0.0.7

9 years ago

0.0.6

9 years ago

0.0.5

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago