Skip to content

Commit

Permalink
Log everything redis
Browse files Browse the repository at this point in the history
  • Loading branch information
Pandoks committed Dec 5, 2024
1 parent eb9a9d7 commit 72be386
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
11 changes: 9 additions & 2 deletions .kamal/secrets
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,22 @@ SECRETS=$(sst secret list | sed '1,2d')

KAMAL_REGISTRY_PASSWORD=$(echo "$SECRETS" | grep "GhToken" | sed "s/GhToken=//")

# used to setup postgres
POSTGRES_USER=$(echo "$SECRETS" | grep "MainDatabaseUsername" | sed "s/MainDatabaseUsername=//")
POSTGRES_PASSWORD=$(echo "$SECRETS" | grep "MainDatabasePassword" | sed "s/MainDatabasePassword=//")
POSTGRES_DB=$(echo "$SECRETS" | grep "MainDatabaseName" | sed "s/MainDatabaseName=//")
PGUSER=$POSTGRES_USER
PGDATABASE=$POSTGRES_DB

# used to setup redis
REDIS_PASSWORD=$(echo "$SECRETS" | grep "MainRedisPassword" | sed "s/MainRedisPassword=//")

# application env
USER_DB_USERNAME=$(echo "$SECRETS" | grep "MainDatabaseUsername" | sed "s/MainDatabaseUsername=//")
USER_DB_PASSWORD=$(echo "$SECRETS" | grep "MainDatabasePassword" | sed "s/MainDatabasePassword=//")
USER_DB_DATABASE=$(echo "$SECRETS" | grep "MainDatabaseName" | sed "s/MainDatabasename=//")

MAIN_REDIS_PASSWORD=$(echo "$SECRETS" | grep "MainRedisPassword" | sed "s/MainRedisPassword=//")
MAIN_REDIS_HOST=redis
MAIN_REDIS_PORT=6379

# Option 3: Read secrets via kamal secrets helpers
# These will handle logging in and fetching the secrets in as few calls as possible
Expand Down
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- [ ] See if you can setup tests to use .env file
- [ ] Make env variables and sst secret consistent
21 changes: 14 additions & 7 deletions config/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,18 @@ registry:

builder:
arch: amd64
# env:
# clear:
# DB_HOST: 192.168.0.2
# secret:
# - RAILS_MASTER_KEY

env:
clear:
MAIN_REDIS_PORT: 6379
MAIN_REDIS_HOST: redis
USER_DB_HOST: db
USER_DB_PORT: 5432
secret:
- MAIN_REDIS_PASSWORD
- USER_DB_PASSWORD
- USER_DB_USERNAME
- USER_DB_DATABASE

# Aliases are triggered with "bin/kamal <alias>". You can overwrite arguments on invocation:
# "bin/kamal logs -r job" will tail logs from the first server in the job section.
Expand Down Expand Up @@ -88,7 +95,7 @@ accessories:
- web
env:
secret:
- MAIN_REDIS_PASSWORD
cmd: "/bin/sh -c 'redis-server --requirepass $MAIN_REDIS_PASSWORD'"
- REDIS_PASSWORD
cmd: "/bin/sh -c 'redis-server --requirepass $REDIS_PASSWORD'"
directories:
- redis-data:/data
4 changes: 3 additions & 1 deletion packages/core/src/redis/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ const MAIN_REDIS_PASSWORD = process.env.MAIN_REDIS_PASSWORD;
const MAIN_REDIS_HOST = process.env.MAIN_REDIS_HOST;
const MAIN_REDIS_PORT = process.env.MAIN_REDIS_PORT;

console.log("HERE:", MAIN_REDIS_PORT);
console.log(MAIN_REDIS_PASSWORD);
console.log(MAIN_REDIS_HOST);
console.log(MAIN_REDIS_PORT);
export const redis = createClient({
password: MAIN_REDIS_PASSWORD,
socket: {
Expand Down
2 changes: 1 addition & 1 deletion packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"setup": "pnpm run reset && docker compose -f ../core/compose.yaml -p setup up -d",
"reset": "docker compose -p setup down",
"dev": "pnpm run setup && PORT=5173 vite dev",
"dev": "pnpm run setup && dotenv -e ../../.env -- vite dev",
"build": "vite build",
"test:unit": "pnpm run setup && vitest",
"test:int": "if [ -z \"$CI\" ]; then dotenv -e ../../.env -- playwright test; else playwright test; fi",
Expand Down

0 comments on commit 72be386

Please sign in to comment.