set up local env vars

This commit is contained in:
Martin Dimitrov 2025-06-10 18:23:03 -07:00
parent 2679374dc8
commit 664fbda653
6 changed files with 90 additions and 6 deletions

1
.gitignore vendored
View File

@ -100,7 +100,6 @@ web_modules/
.env.development.local
.env.test.local
.env.production.local
.env.local
# parcel-bundler cache (https://parceljs.org/)

View File

@ -0,0 +1,36 @@
# twilio stuff (not needed for dev)
# ACCOUNT_SID=
# AUTH_TOKEN=
# aws creds (not needed for dev)
# AWS_ACCESS_KEY=
# AWS_SECRET_ACCESS_KEY=
# discord stuff (needed for notify, edit, onboarding)
# DISCORD_BOT_TOKEN=
# DISCORD_CLIENT_SECRET=
# use local ddb
AWS_ENDPOINT=http://localhost:5000
DISCORD_GUILD_ID=1299812960553795655
DISCORD_CLIENT_ID=1299810962366398494
# stage is used in metrics / logs, so just set it to username + dev suffix
STAGE=$USER-dev
# metrics
PUSHGATEWAY_URL=https://metrics.chromart.cc
PUSHGATEWAY_USER=doorman
PUSHGATEWAY_PW=doormanmetrics
# logs
LOKI_URL=https://logs.chromart.cc
LOKI_USER=doorman
LOKI_PW=doormanlogs
# use local UI endpoint for the redirects in dev
DOORMAN_URL=http://localhost:3005
# this isn't really a secret, its just to prevent spam on /notify in prod
NOTIFY_SECRET_KEY=discordnotifyme

View File

@ -82,7 +82,6 @@ web_modules/
.env.development.local
.env.test.local
.env.production.local
.env.local
# parcel-bundler cache (https://parceljs.org/)
.cache

View File

@ -1,4 +1,54 @@
## deployment is serverless
# doorman-api
The backend API for Doorman. It is resposible for managing Door state, configuring Door options and sending Discord Notifications.
## dependency services
The Doorman API has hard dependencies:
- DynamoDB
- Discord (notify, edit, and onboarding)
- Cloudflare (only in Production)
- Twilio Functions (deployed compute in staging / prod)
It has some soft dependencies on other services, mostly self hosted monitoring solutions:
- Pushgateway (prometheus metrics)
- Loki (logs)
## running locally
First install the necessary dependencies `bun install`.
When running locally, Doorman API will use [DynamoDBLocal](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.DownloadingAndRunning.html)
You will likely need java installed on your machine and in your path in order for DynamoDBLocal to work.
To run the dev server: `bun run start:local-db`
On startup, the main "doorman" DDB table is created and seeded with the a test Door.
Note: DynamoDBLocal is configured to use in memory store only, so any changes will not persist when you exit the command.
The API will run on port 8080 and DynamoDBLocal will use port 5000.
You can verify the seeding worked by calling `http://localhost:8080/api/door/info?door=test`
If you need to test Discord or against real DDB, you should set those env vars in your environment in a seperate .env file and source it before running
## troubleshooting
### Port 5000 is already in use after restarting server
When exiting `bun run start:local-db`, we try to close the previous DDB local run, though this is best efforts it may have failed to close the child process. You can manually find and kill the forked process as follows:
```
ps -ef | grep DynamoDBLocal
martin 243091 243061 93 17:57 pts/4 00:00:13 java -Xrs -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -port 5000 -inMemory
kill 243091
```
## deployment
this project deploys the UI and API to twilio functions https://doorman-6741-prod.twil.io

View File

@ -5,10 +5,10 @@
"scripts": {
"integ-test:local": "bun run build && export $(grep -v '^#' .env.twiliotemplate | grep -v '=$' | xargs) && concurrently --success first --kill-others \"bun run start-twilio\" \"bun test --timeout 30000 ./tst/integ-local.test.ts\"",
"integ-test:staging": "STAGE=staging bun test --timeout 30000 ./tst/integ-staging.test.ts",
"start-twilio": "twilio-run --load-local-env --live --port 8080",
"start-twilio": "twilio-run --load-local-env --env .env.local --live --port 8080",
"watch-build": "bun run --watch src/index.ts",
"start": "concurrently \"bun run watch-build\" \"bun run start-twilio\"",
"local-db": "bun run --watch src/local/localDdb.ts",
"local-db": "bun run src/local/localDdb.ts",
"start:local-db": "concurrently \"bun run local-db\" \"bun run start\"",
"build": "bun run src/index.ts",
"deploy": "twilio-run promote --from=staging --to=prod --load-system-env --env .env.twiliotemplate",

View File

@ -15,7 +15,7 @@ export const createDynaBridgeClient = (context: TwilioContext) => {
};
// for local DDB
if (context.AWS_ENDPOINT) {
if (context.AWS_ENDPOINT && !context.AWS_ACCESS_KEY && !context.AWS_SECRET_ACCESS_KEY) {
config = {
endpoint: context.AWS_ENDPOINT,
}