Skip to content

Setting up your instance

Ted Hwang edited this page Dec 17, 2020 · 27 revisions

Setting up your instance of mipa

After obtaining a copy of mipa (best done by forking and cloning the repository if you wish to contribute), do the following to run your instance.

These instructions are current as of 2020.10.14. If you notice that something in the process has changed, please help update this documentation.

Create a project on Google Firebase

  1. Go to https://console.firebase.google.com/ (you may need to create an account first)
  2. Click Add project. Name the new project something like "mipa-your-name". Enabling Google Analytics is optional.
  3. Once the Firebase project is created, click on the </> icon to add a web app. Give the app a nickname, like "my mipa web app". Check the box to set up Firebase Hosting. Then click Register app.
  4. Ignore "Add Firebase SDK" instructions. Mipa's code already has this set up. So just click Next.
  5. Install firebase-tools per on-screen instructions.
  6. Per on-screen instructions, sign in to Google; but don't initiate your project with firebase init or deploy it yet. Just click continue to console.
  7. On the firebase console, click Authentication. Then Get started to set up sign-in methods; enable Email/Password.
  8. On the firebase console, click Cloud Firestore. Then Create database; select Start in production mode; pick a database location that makes sense for you (note down the location; we'll need it later), then enable.
  9. From the bottom of the left navigation panel, change the Spark plan to Blaze plan. (This is needed to make http requests from Cloud Functions, which we need for updating the currency exchange rates used within mipa.)

Add your project's credentials

  1. Make a copy of the .env_sample file and name it .env.
  2. Back on the Firebase Console, go to Settings > General.
  3. In the newly created .env file, add in your Firebase project's credentials from the above steps. .env is already in .gitignore so the file will not be synced back to the repository.

Modify .firebaserc

  1. Make a copy of the .firebaserc_sample file and name it .firebaserc.
  2. In the file, in the "default" property, use your project id. .firebaserc is likewise already in .gitignore and will not be synced back to the repository.

Install dependencies for Cloud Functions

cd functions
npm install
cd ..

Set configuration for Cloud Functions

We need this for updating currency exchange rates.

  1. Recall the location that you noted down when you created the Firestore database. Check it against this locations list: https://cloud.google.com/functions/docs/locations to find the same or nearby location. Your region code should look something like us-central1.
  2. Decide on a schedule to update the currency exchange rates. This is the string that may replace the every 12 hours in the call functions.pubsub.schedule('every 12 hours'). For the syntax, see https://cloud.google.com/appengine/docs/standard/python/config/cronref#schedule_format. If you have no other special considerations, every 12 hours is a reasonable choice.
  3. If you need to specify the time zone, use a value from the TZ database name column from https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
  4. go to fixer.io and sign up for a free account to get an access key.
  5. Run the command below with the information you just prepared:
firebase functions:config:set update_exchange_rates.region="your-region-code" update_exchange_rates.schedule="daily" update_exchange_rates.time_zone="Etc/UTC" fixer_io.access_key="your-access-key"

Install dependencies for other parts of the project

For the rest of the project we use yarn instead of npm because of the more deterministic way it chooses dependencies. This helps us developers keep our dependencies identical.

If you don't have yarn installed yet, follow these instructions to install it: https://classic.yarnpkg.com/en/docs/install/

Then:

yarn install

Build the app and deploy to Firebase

This will deploy to the environment you configured in your .env file.

quasar build
firebase deploy

If all went well, mipa will be running at https://your-project-id.web.app. Register an account for yourself, and try things out!