codeforbtv / cvoeo-app

The "Money on My Mind" app helps CVOEO's Reach-Up clients stay on track with their personal finance coaching.
Apache License 2.0
11 stars 4 forks source link

Define firebase environments and deployment processes #75

Open iritush opened 5 years ago

iritush commented 5 years ago

-Define what environments and deployment processes are needed for firebase once app is released to the public (production?/development?/staging?) -Define what environments and deployment processes are needed pre-release; Once front and back end are hooked, define how will new changes be deployed and where, so that changes can be tested after deployment and provide needed functionalities for app, but at the same time not "break" and block app development. -Related in some ways to #25

johnneed commented 5 years ago

Assuming you want 3 environments, dev, staging and prod, here is the general process:

  1. In Expo, create a new "Release Channel" for staging. You will be using your existing release channel for prod. You can create a dev release channel but it’s not needed since developers typically run the code from their own computer.

  2. In FIrebase create 2 new projects to correspond to your new enviroments: CVOEO-DEV, CVOEO-STAGING. You already have prod project, CVOEO-45350.

  3. You will need to create an environment.js file that holds the config for each of these Firebase projects. Currently you are using firebase-config.js to hold your production config.

Your environment.js file should look like this:

/** ***************************
 * environment.js
 * path: '/environment.js' (root of your project)
 ******************************/

import Constants from 'expo-constants';

const ENV = {
    dev: {
        apiKey: "YOUR apiKey FOR CVOEO_DEV",
        authDomain: "YOUR authDomain KEY FOR CVOEO_DEV",,
        databaseURL: "YOUR databaseURL FOR CVOEO_DEV",",
        projectId: "YOUR projectId FOR CVOEO_DEV",,
        storageBucket: "YOUR storageBucket FOR CVOEO_DEV",,
        messagingSenderId:"YOUR messagingSenderId FOR CVOEO_DEV",
    },
    staging: {
            apiKey: "YOUR apiKey FOR CVOEO_STAGING", 
            authDomain: "YOUR authDomain KEY FOR CVOEO_STAGING",,
            databaseURL: "YOUR databaseURL FOR CVOEO_STAGING",
            projectId: "YOUR projectId FOR CVOEO_STAGING",,
            storageBucket: "YOUR storageBucket FOR CVOEO_STAGING",,
            messagingSenderId:"YOUR messagingSenderId FOR CVOEO_STAGING",
    },
    prod: {
            apiKey: "YOUR apiKey FOR CVOEO_PROD",
            authDomain: "YOUR authDomain KEY FOR CVOEO_PROD",,
            databaseURL: "YOUR databaseURL FOR CVOEO_PROD",
            projectId: "YOUR projectId FOR CVOEO_PROD",,
            storageBucket: "YOUR storageBucket FOR CVOEO_PROD",,
            messagingSenderId:"YOUR messagingSenderId FOR CVOEO_PROD",
    }
};

const getEnvVars = (env = Constants.manifest.releaseChannel) => {
    // What is __DEV__ ?
    // This variable is set to true when react-native is running in Dev mode.
    // __DEV__ is true when run locally, but false when published.
    if (__DEV__) {
        return ENV.dev;
    } else if (env === "staging") {
        return ENV.staging;
    } else if (env === "prod") {
        return ENV.prod;
    }
};

export default getEnvVars;
  1. Change firebase-config.js to look like this:
import getEnvVars from "../environment";

const { apiKey, authDomain, databaseURL, projectId, storageBucket, messagingSenderId } = getEnvVars();

export const firebaseConfig = { apiKey, authDomain, databaseURL, projectId, storageBucket, messagingSenderId };
  1. Remove firebase-config.js from the .gitignore file.

  2. Add environment.js to the .gitignore file.

  3. Check everything in.

  4. Create a new branch in your repo called "RELEASE"

  5. Change the RELEASE branch settings so it's fully protected. Only a trusted few should be allowed to merge to this branch.

  6. Setup a continuous integration system that triggers on pushes to the master branch. The CI system should publish your code to your new staging release channel.

  7. Build your app against the staging release channel. You should now have an .ipa and an .apk file for Ios and Android.

  8. Deploy the iOS to Apple Test flight for iOS QA testers. Android QA users can still use the Expo app to test. If you really want to, the .ipa and .apk files can be loaded on phones for QA folks to test staging, but it's not necessary.