Page MenuHomePhabricator

[Keyserver] Migrate to non-apache config, update native
ClosedPublic

Authored by jon on Dec 8 2022, 11:37 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Jun 22, 6:24 AM
Unknown Object (File)
Thu, Jun 20, 8:06 AM
Unknown Object (File)
Thu, Jun 13, 10:15 AM
Unknown Object (File)
Tue, Jun 11, 8:21 PM
Unknown Object (File)
Fri, Jun 7, 5:20 AM
Unknown Object (File)
Sat, Jun 1, 9:07 PM
Unknown Object (File)
Sat, Jun 1, 8:36 AM
Unknown Object (File)
Sat, Jun 1, 3:48 AM
Subscribers

Details

Summary

Use keyserver migration logic to apply developoment defaults which
work without use of Apache.

Update native url logic to account for explicit port usage

https://linear.app/comm/issue/ENG-2260

Test Plan

First need to create an existing app, which uses the apache configuration

git checkout master
nix develop # optional, if legacy dev env already applied

# In one terminal
cd keyserver
yarn dev

# In another terminal
cd native
yarn dev

# Run follwoing command in another terminal
yarn react-native run-ios --simulator='iPhone 14 Pro' --configuration=Debug

# Should be able to do normal iOS Dev workflow:
#   No "DISCONNECTED" bar appears, able to create chat threads
#   Profile > Developer tools, should show http://localhost/comm

Screen Shot 2022-12-19 at 6.44.48 AM.png (594×698 px, 66 KB)

Next, we need apply url-utils changes:

arc patch D5846

# Keyserver should apply the migration, but still needs to restart for routing changes
# restart `yarn dev` in `keyserver/`

# App should update to new defaultURL without intervention, but to start it again
yarn react-native run-ios --simulator='iPhone 14 Pro' --configuration=Debug
# Should be able to do normal iOS Dev workflow:
#   No "DISCONNECTED" bar appears, able to create chat threads
#   Profile > Developer tools, should show http://localhost:3000/comm

Screen Shot 2022-12-19 at 6.47.07 AM.png (604×660 px, 65 KB)

Diff Detail

Repository
rCOMM Comm
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

There are a very large number of changes, so older changes are hidden. Show Older Changes

How are you making sure that this doesn't mess up the config in our production environment? Can you update your Test Plan to include steps to address that?

The developer paths seem to fallback to hardcoded paths here: https://github.com/CommE2E/comm/blob/824a62323ca29e4fbff784ecdf87e822ac5ca1fb/native/utils/url-utils.js#L57-L63

I'll try launching the native app in release mode and post the "Profile > Developer Tools" output.

Nevermind, release mode removes developer tools section from profile.

Instead I was able to submit a friends request when running it in release:

Screen Shot 2022-12-11 at 10.02.12 AM.png (1×674 px, 76 KB)

ashoat requested changes to this revision.Dec 13 2022, 7:28 AM

Thanks for updating the Test Plan! Last step here is this one:

How are you making sure that this doesn't mess up the config in our production environment? Can you update your Test Plan to include steps to address that?

To be clear, I'm more concerned about the keyserver side of production (eg. that we're going to create facts/squalcal_url.json / facts/commapp_url.json / facts/landing.json in production)... not worried about the native side of production (where I agree the app will just used the hardcoded paths).

This revision now requires changes to proceed.Dec 13 2022, 7:28 AM
keyserver/src/database/migration-config.js
123 ↗(On Diff #19259)

Typo here, worries me that this wasn't tested

123–125 ↗(On Diff #19259)

As discussed, this should not be done in Docker environment, where we don't use JSON configs. This should be wrapped in a check of either whether the file exists or whether an environmental variable is set, see importJSON

Test plan should be modified to check two more things:

  1. localhost:3000/ (root), not localhost:3000/comm/
  2. Docker keyserver build. Your keyserver/.env should look something like this:
COMM_DATABASE_DATABASE=<database>
COMM_DATABASE_USER=<db_user>
COMM_DATABASE_PASSWORD=<password>
COMM_JSONCONFIG_facts_landing_url='<landing_url>'
COMM_JSONCONFIG_facts_commapp_url='<commapp_url>'
COMM_JSONCONFIG_facts_squadcal_url='<squadcal_url>'
keyserver/src/database/migration-config.js
123 ↗(On Diff #19259)

Also this needs proxy: "apache"

jon edited the test plan for this revision. (Show Details)

Minor fixes, address feedback

jon added inline comments.
keyserver/src/database/migration-config.js
123–125 ↗(On Diff #19259)

I tested to see if the keyserver was being executed in a docker environment, and omitted writing the files in that case.

I still don't like the idea of coupling configuration management and migrations; never going to be a case where there is 100% alignment in intent and effect.

ashoat requested changes to this revision.Dec 19 2022, 2:18 PM
ashoat added inline comments.
keyserver/src/database/migration-config.js
123 ↗(On Diff #19729)

I think something is wrong here... the old Apache config redirected http://localhost/comm/ to http://localhost:3000/, which means that the basePath and baseRoutePath have to be different. The point of the squadcal_url.json file is to work with this specific Apache config, so you need to make sure it works there.

I once again suspect your Test Plan needs to be expanded. When the basePath is wrong the app may still initially load, but because it doesn't know how to construct URLs correctly you'll start to see issues when navigatind around and playing with the app. Perhaps you didn't do far enough in doing that?

123–125 ↗(On Diff #19729)

Why is this an async function if you're not awaiting anything?

This function will resolve immediately, and let its three invocations of moveToNonApacheConfig resolve "in the background". This breaks the "transactionality" of the migration.

Please await the three calls

192–194 ↗(On Diff #19729)

I think we can skip this warning. There's nothing really to warn about in my opinion

197 ↗(On Diff #19729)

Typo

203 ↗(On Diff #19729)

Shorthand

This revision now requires changes to proceed.Dec 19 2022, 2:18 PM

Also I don't think both of these things are in the test plan yet:

Test plan should be modified to check two more things:

  1. localhost:3000/ (root), not localhost:3000/comm/
  2. Docker keyserver build. Your keyserver/.env should look something like this:
COMM_DATABASE_DATABASE=<database>
COMM_DATABASE_USER=<db_user>
COMM_DATABASE_PASSWORD=<password>
COMM_JSONCONFIG_facts_landing_url='<landing_url>'
COMM_JSONCONFIG_facts_commapp_url='<commapp_url>'
COMM_JSONCONFIG_facts_squadcal_url='<squadcal_url>'

"localhost:3000/ root" was something I jotted down quickly during a 1:1 after explaining to you that squdcal_url.json was supposed to handle that baseRoutePath, but I'm guessing you didn't fully grasp that in the 1:1, and the diff comment didn't have much detail. Either way, you should make sure to test that, as based on my previous comment I think your solution here won't work.

As for the Docker keyserver build, we need you to test that to make sure the production environment doesn't break. Just like the rest of the environments you test, you should make sure to play around with the app a little bit to make sure it works.

jon marked 4 inline comments as done.

Address feedback

jon added inline comments.
keyserver/src/database/migration-config.js
123 ↗(On Diff #19729)

I was able to post in personal thread using this setup. Given, the debug iOS application will reload with the new endpoint while the application is still open. So it might be that applying the url-utils.js changes causes this to not be an issue.

123–125 ↗(On Diff #19729)

Thanks!

jon added inline comments.
keyserver/src/database/migration-config.js
60–61 ↗(On Diff #19734)

whitespace plugin wanted to delete, this. reverting

123–125 ↗(On Diff #19729)

Promise.all seemed to cause the actions to run many times. I just added awaits, and had the expected behavior.

ashoat requested changes to this revision.Dec 19 2022, 3:52 PM

Almost there!!

Heads-up, your screenshot failed to attach... see here: https://www.notion.so/commapp/Attaching-files-and-images-on-Phabricator-af8e2195fc91462689cc8de5c96a6759

Thanks for the context on the testing. Maybe the reason the basePath being / wasn't an issue is that native is the only place that has the "sticky" configuration, and maybe native's usage doesn't rely so much on keyserver being able to construct URLs. Either glad, glad it's fixed.

keyserver/src/database/migration-config.js
123–125 ↗(On Diff #19745)

Interesting about the Promise.all issue... that's really unexpected. Can you share any more details about that?

Your earlier solution had all three going at the same time, just like my Promise.all solution. So that can't be the problem.

I'd love if you could try again and do some investigation... I'm struggling to imagine how that is possible, so I'm suspecting there maybe was a typo or something

188 ↗(On Diff #19745)

Maybe call this fileHandler, writeFile.writeFile seems like messy variable naming

This revision now requires changes to proceed.Dec 19 2022, 3:52 PM
jon added inline comments.
keyserver/src/database/migration-config.js
123–125 ↗(On Diff #19745)

I'd love if you could try again and do some investigation... I'm struggling to imagine how that is possible, so I'm suspecting there maybe was a typo or something

I think the issue was that i forgot to await writeJSONToFilecalls. The updating ${filePath} to ${JSON.stringify(data)} message was being posted multiple times.

Earlier migrations also use the async + await paradigm. I don't have much of a preference, but let me try it again.

188 ↗(On Diff #19745)

want me to change it in the other locations? (E.g. makeSureBaseRoutePathExists, and fixBaseRoutePathForLocalhost)

Heads-up, your screenshot failed to attach.

Keep forgetting that phabricator doesn't do this by default.

jon added inline comments.
keyserver/src/database/migration-config.js
123–125 ↗(On Diff #19745)

I'd love if you could try again and do some investigation

The type for migrations map is $ReadOnlyMap<number, () => Promise<void>>, so just await Promise.all() isn't satisfactory, need it to be a function which takes no arguments. E.g. async () => { await Promise.all(); }

Address writeFile.writeFile feedback

Okay, based on my review of the code this looks good. The test plan looks thorough, too – hope we caught everything!

keyserver/src/database/migration-config.js
166 ↗(On Diff #19748)

Thanks for refactoring this!!

This revision is now accepted and ready to land.Dec 20 2022, 5:47 AM