The Shippening: Part 1.8, Micro Madness
Tags: opensource, helphowdoiwritetags, traefik, docker
Published: 2021-03-13 00:56:50

Earlier this week I decided to pause progress of my microservice today to instead test @humphd's dockerized Firebase emulator. I needed to ensure this works for ~~three~~ two reasons:

- ~~To get a grade in OSD700 by testing a PR~~
- To ensure that I could insert data into a local, traefik, dockeriz'd, offline, version of the Firebase Firestore.
- To ensure a smooth integration into my User microservice.

[Last week I participated in a hackathon](https://dev.to/chrispinkney/hackathon-update-2mng) and used Firebase as my db of choice. I ran into some issues that were preventing me from inserting data into my local version of the db. I had assumed that this was due to the fact that I had never specified a private API key to use. <u>This is a big issue as having to specify a private API key to use the offline emulator means that we have to authenticate each and every developer who needs to use Firestore (this also ruins our potential CI pipeline.)</u> Assuming the worst, I reported my grim findings during our triage meeting on Tuesday.

Evidently this is not the case as I did not specify one when testing this PR. Hopefully the fact that the emulated version now works is due to PEBKAC, RTFM, or both. I need to release a draft PR in order to get more devs to test my code.

I tested this PR by making a separate (*i.e. bastardized*) version of my current microservice work that I use to send data to my Firestore, and pointing it to the dockerized version. It sounds simple but there were a few things that I had to do first:  I had to lighty reintroduce myself to Docker, fix my Ubuntu WSL2 install (*god I need to get Ubuntu working with my fakeraid system...*), and do some reading and catching up about Firestore Emulator. After some time I finally got it to work and reported by findings on the PR.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hsbq7m5yf3q2aducpdpk.png)

Anyway, testing this PR was a lot of fun and a headache at the same time. I imagine this feeling is a lot like raising children. 



After finishing my review, I proceeded to continue working my microservice. It's finally nearing a point where I can release it to the wild for review. I needed (and am eternally grateful for) guidance, direction, and help to push this thing into a PR. The only thing that I lack now is time. Time, and brain cells mostly. It's getting late in the week and the last 10% of something always takes as much time as the 90% did. Well, maybe not 90% in this case, but it sure felt like it given all the work I've rushed into this in the last few days.

Here is my leftover todo list:

1. Finish up making some more tests, specifically ones that test Celebrate's validation rules
   a. **Mostly done.** I still could use several tests testing various smaller bits of code but those can always be added in later and spending too much time on this won't get a PR up sooner.
2. Migrate to https://www.npmjs.com/package/@firebase/rules-unit-testing because `@firebase/testing` is deprecated
   a. **Done.**
3. Create a basic README.md file
   a. **Done.** I'm rather proud of it actually. It does need some more work as I need to specify exactly how the service and docker + traefik work together to get data where it needs to go.
4. Implement a list of current deficiencies and issues to discuss when the draft PR goes up
   a. **Done. Kind of.** I've been keeping track of this but at lot of them have been fixed and a lot of things have changed in the last few days. 
5. Implement [Satellite](https://github.com/Seneca-CDOT/satellite)
   a. **Done.** I was having some issues with this though, as after implementing Satellite all my tests were failing. My problem, as expected, was minor and silly:  `const { app } = require('../../index');`, I wasn't de-structuring `app` from `index`, so all the function calls were failing as they didn't exist in `app`.
6. Dockerize the microservice
   a. **Done.** I'm a great admirer of Docker (and traefik) but it's still confusing to me. I just need more experience. Mostly I lack the context of how things are interconnected to each other via multiple Dockers + Traefik.
7. Add Firestore private key placeholders to  `env.production` and `env.staging`
   a.  **Not done.** I'm lacking both files so I'll need to iterate on this. Thanks, checklist!
8. ~~Tidy up the `package.json` run commands using [npm-run-all](https://www.npmjs.com/package/npm-run-all)~~
   a.  Unnecessary since the entire microservice is run via Docker, having npm run commands are a thing of the past.
9. Create an update (*put*) route
   a.  **Done**, along with accompanying tests.
10. Create a delete route
      a.  **Done**, along with accompanying tests.
11. ~~Add date/time users were created (*mostly for funsies*)~~
      a.  **Not done.** Scrapped for time.
12. ~~Add date/time users were updated (*again, for funsies*)~~
      a.  **Not done.** Scrapped for time.
13. Migrate unnecessary `package.json` dependencies to dev-dependencies
      a.  **Done.**
14. Finally, **create a PR!**
      a.  **[Done!](https://github.com/Seneca-CDOT/telescope/pull/1915)**



So now that the microservice is finally up, I'm hoping for a lot of feedback. I still have things that I need to fix, though mostly minor things and documentation edits. I have a few tests that need to pass, and I'm hoping to make the time for it this week around my work schedule. I'd also like to expand on how exactly to test the PR on the PR page. Sometimes it's hard to translate what little goes on in my head, to fingers and keyboard.

Something else that needs answers that I didn't think about until now: How do I ensure my delete route can only be ran by admins? Any fellow proletariat can execute ~~the bourgeoisie~~ a delete route and delete a bunch of users. Questions, questions that need answers and riddles in the dark.

Minor list of things that did dun need doing:

- Create a `env.production` and `env.staging` file

- Clean up the readme

- Fix the Dockerfile

- Add a section on how to test the PR (on the PR page)

- Fix the failing tests

  - Expected value:  {**"displayName": "Galileo Galilei",** "feeds": ["https://dev.to/feed/galileogalilei"], "firstName": "Galileo", "github": {"avatarUrl": "https://avatars.githubusercontent.com/u/7242003?s=460&u=733c50a2f50ba297ed30f6b5921a511c2f43bfee&v=4", "username": "galileogalilei"}, "id": 10001, "isAdmin": true, "isFlagged": true, "lastName": "Galilei"}
    vs.
  - Received object: {"feeds": ["https://dev.to/feed/galileogalilei"], "firstName": "Galileo", "github": {"avatarUrl": "https://avatars.githubusercontent.com/u/7242003?s=460&u=733c50a2f50ba297ed30f6b5921a511c2f43bfee&v=4", "username": "galileogalilei"}, "id": 10001, "isAdmin": true, "isFlagged": true, "lastName": "Galilei"}

- How are we going to do security?

- Switch my port to 7777 since [SOMEONE](https://github.com/Seneca-CDOT/telescope/pull/1833/files#diff-4e3af2b0cd9bb7198b4b3aa1fcd33b2e6233eb335c90b79c132c5ea4f4f83720R107) took my satanic panic port 6666, my disappointment is immeasurable and my day Is ruined.

Oh, and I just reviewed [Tony's microservice](https://github.com/Seneca-CDOT/telescope/pull/1833)! I unfortunately missed out on Abdul's and I kept my head buried in the sand for the last week or so trying to finish this up, so I'm glad I got to play around with someone else's. [Got](https://www.npmjs.com/package/got) looks like a sweet library, that plus celebrate is really turning me towards NodeJS development.

Anyway that's it for me right now. Fun but busy week, and as always looking forward to the next one.