Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance local dev env #900

Merged
merged 36 commits into from
Mar 13, 2024
Merged

Enhance local dev env #900

merged 36 commits into from
Mar 13, 2024

Conversation

huumn
Copy link
Member

@huumn huumn commented Mar 7, 2024

closes #799 #391

I think this at the stage where it is mergeable. It doesn't do everything we might want it to do but it's already 100x better than what we had before. This is almost at the point where I'd use it over my bespoke local setup.

I can confirm this works as expected on mac. It'd be nice to also confirm it works on linux at least.

Should be pretty straightforward to qa:

./sndev start

Then visit localhost:3000 and give it whirl.

./sndev help

To see other stuff you can do.


Just getting started on this, but so far:

  • makes worker hot reload
  • makes docker compose shituation more reliable with restart logic and stuff
  • begins a sndev posix shell script for managing all the kinds of things one might want to do in our local dev with commands: sndev start|stop|delete|help
  • uses .env.sndev for docker env which is created from .env.sample when sndev start is run

TODO:

  • finish up adding db seed (I've configured postgres to load it but I need to add to repo)
    • make db seed smaller by sampling the sample
  • add an lnd regtest network to docker compose
    • give lnd static certs/macaroons
    • auto-mine
    • make channels
    • configure circular payments for testing lnaddr
  • have db seed also populate opensearch
  • mock s3 on disk for image uploads
  • add remaining commands for sndev
    • sndev login $nym
    • sndev makeinvoice $all_the_lnd_params
    • sndev payinvoice $all_the_lnd_params
  • refine the crap out it with lots of helpful and encouraging messages
    • help messages for all sndev commands
    • better log management
    • prompting?
  • setup a reverse tunnel?

Am I missing anything? After this I'll try and see if I can get this all working in github codespaces.


Copy link

socket-security bot commented Mar 7, 2024

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/jest@29.7.0 Transitive: environment, eval, filesystem, network, shell, unsafe +181 20 MB simenb

🚮 Removed packages: npm/puppeteer@20.8.2

View full report↗︎

@huumn
Copy link
Member Author

huumn commented Mar 7, 2024

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/jest@29.7.0 Transitive: environment, eval, filesystem, network, shell, unsafe +181 20 MB simenb
🚮 Removed packages: npm/puppeteer@20.8.2

View full report↗︎

none of that changed you wanker

sndev Outdated Show resolved Hide resolved
sndev Show resolved Hide resolved
sndev Show resolved Hide resolved
.env.sample Outdated Show resolved Hide resolved
docker-compose.yml Outdated Show resolved Hide resolved
package.json Show resolved Hide resolved
@ekzyis
Copy link
Member

ekzyis commented Mar 7, 2024

mock s3 on disk for image uploads

What about not mocking and hardcoding a S3 bucket that we will regularly delete and limit the amount the bucket can store if that's possible?1 That would require no code change at all (just an environment setting) and is thus closer to production.

The downside would be opening us for bots that scrape for public buckets and then do whatever with them (hence the storage limitation and regular deletion) and that devs would overwrite the images of each other since their local db has no knowledge which id comes next in the bucket (could be fixed with unique, random prefixes).

Am I missing anything? After this I'll try and see if I can get this all working in github codespaces.

sndev deploy 👀 Just kidding, more future music. But I am really looking forward to deployments for PRs and feels like whatever we do to make local dev setups very easy will be helpful to have automated branch deployments.

I still remember my first encounter with them which was here and it blew my mind.2 Maybe if we have something like this it will also blow the minds of contributors?

The SquadMC one uses Netlify but for NextJS, we could use Vercel if we want to use some managed solution instead of AWS or VPS. I'd prefer trying to go VPS first (could run on AWS) since this should be as straightforward as what I did here.

Footnotes

  1. fwiw, I did a quick search and didn't find documentation mentioning it's possible

  2. Apparently, the branch is still deployed which also blew my mind lol

@huumn
Copy link
Member Author

huumn commented Mar 7, 2024

What about not mocking and hardcoding a S3 bucket that we will regularly delete and limit the amount the bucket can store if that's possible?

I thought of that too but it sounds like more work. We could also add another container that mocks s3: https://github.com/adobe/S3Mock

But I am really looking forward to deployments for PRs and feels like whatever we do to make local dev setups very easy will be helpful to have automated branch deployments.

Agreed. The real hard part is going to be some kind of db multitenancy ... unless we can do something with docker.

@huumn
Copy link
Member Author

huumn commented Mar 7, 2024

If you have anymore bash posix shell scripting tips let me know. I'd like to keep it posix based, but I'm a total noob with shell scripts.

@huumn huumn added the sndev label Mar 8, 2024
docker-compose.yml Outdated Show resolved Hide resolved
docker-compose.yml Outdated Show resolved Hide resolved
@huumn huumn mentioned this pull request Mar 10, 2024
@huumn huumn marked this pull request as ready for review March 11, 2024 00:46
@huumn huumn requested a review from ekzyis March 11, 2024 00:52
Copy link
Member

@ekzyis ekzyis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this at the stage where it is mergeable. It doesn't do everything we might want it to do but it's already 100x better than what we had before. This is almost at the point where I'd use it over my bespoke local setup.

I can confirm this works as expected on mac. It'd be nice to also confirm it works on linux at least.

Should be pretty straightforward to qa:

./sndev start

Then visit localhost:3000 and give it whirl.

Me after running the command:

giphy

Works great! Immediately ran install -m=755 sndev ~/.local/bin so I can simply type sndev. I might use this over my current setup.

One suggestion (I can do this in another PR): We could add LNbits container for sndev login $nym.

Not sure if you already know but one approach for logging in as any nym is to use pubkey auth and then move the pubkey to the user you want to impersonate as I did in #905 (probably works very similar with any auth method).

Nostr login with nostr extension worked out of the box.

Also tested funding and withdrawing but noticed that the help message is lacking arguments for these commands. Here is a patch:

patch
diff --git a/sndev b/sndev
index c76fbe36..3d1506cd 100755
--- a/sndev
+++ b/sndev
@@ -123,26 +123,26 @@ USAGE
   $ sndev [COMMAND]

 COMMANDS
-  help            show help
+  help               show help

   env:
-    start         start env
-    stop          stop env
-    restart       restart env
-    status        status of env
-    delete        delete env
+    start            start env
+    stop             stop env
+    restart          restart env
+    status           status of env
+    delete           delete env

   lnd:
-    fund          pay a bolt11 for funding
-    withdraw      create a bolt11 for withdrawal
+    fund <bolt11>    pay a bolt11 for funding
+    withdraw <sats>  create a bolt11 for withdrawal

   db:
-    psql          open psql on db
+    psql             open psql on db

   raw:
-    compose       docker compose passthrough
-    sn_lncli      lncli passthrough on sn_lnd
-    stacker_lncli lncli passthrough on stacker_lnd
+    compose          docker compose passthrough
+    sn_lncli         lncli passthrough on sn_lnd
+    stacker_lncli    lncli passthrough on stacker_lnd
 "
         echo "$help"
     fi

Tested sn_lncli and stacker_lncli by simply running it and expecting the LND help which showed up.

Nice work, this is where bash shines ☀️

sndev Show resolved Hide resolved
# containers can't use localhost, so we need to use the container name
IMGPROXY_URL_DOCKER=http://imgproxy:8080
MEDIA_URL_DOCKER=http://s3:4566/uploads

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I spent the better part of 10 hours trying to avoid this 😮‍💨 and all the related changes.

Things that didn't work:

  • any kind of normal docker compose configuration that uses the default network
  • running a reverse proxy container
    • I almost got it working with imgproxy.localhost and s3.localhost and docker compose links but after I got that all figured out, I learned macos doesn't support localhost subdomains
  • intercepting fetches in the service worker transforming domains, e.g. imgproxy:3001 -> localhost:3001

... I'm not sure what else I could have tried. We more or less need the host, app, worker, s3, and imgproxy to all share some kind of name resolution service. This is easy enough to configure in containers, but we can't reliably alter (nor should we) the host's dns.

@huumn
Copy link
Member Author

huumn commented Mar 13, 2024

I think this is good to merge after I take a breathe and do another once over. I'll add the remaining todos as issues.

@huumn huumn merged commit 23ee62f into master Mar 13, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add regtest lightning network to docker-compose setup
2 participants