Skip to content

Commit

Permalink
Merge pull request #259 from dappradar/add-redis-instance
Browse files Browse the repository at this point in the history
Enable Redis on K8s and adjust env variables
  • Loading branch information
ebusho authored Feb 27, 2024
2 parents bb3a06f + ef5af53 commit f0df0b9
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 16 deletions.
6 changes: 5 additions & 1 deletion .env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ LOGSTASH_INDEX=
#=================== SLACK WEB HOOK ===================
SLACK_WEBHOOK_URL=
SLACK_LOGGING=false
REDIS_URL=

REDIS_HOST=
REDIS_PORT=6379
REDIS_USERNAME=
REDIS_PASSWORD=
2 changes: 1 addition & 1 deletion kubernetes/base/kustomization.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ resources:
- service.yml
- ingress.yml
- secrets.yml
# - redis.yml
- redis.yml
37 changes: 29 additions & 8 deletions kubernetes/base/redis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: defi-providers-redis-pvc
spec:
accessModes:
- ReadWriteOnce
storageClassName: gp3
resources:
requests:
storage: 1G
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: defi-providers-redis
spec:
replicas: 0
replicas: 1
selector:
matchLabels:
component: defi-providers-redis
Expand All @@ -14,27 +26,36 @@ spec:
spec:
containers:
- name: defi-providers-redis
image: redis:7.0.11
image: redis:7
imagePullPolicy: Always
args: ["--requirepass", "$(REDIS_PASS)"]
args: ["--requirepass", "$(REDIS_PASSWORD)"]
resources:
requests:
cpu: 250m
memory: 512Mi
cpu: 100m
memory: 512M
limits:
cpu: 1000m
memory: 1Gi
memory: 1G
ports:
- name: redis-port
containerPort: 6379
env:
- name: MASTER
value: "true"
- name: REDIS_PASS
- name: REDIS_PASSWORD
valueFrom:
secretKeyRef:
name: defi-providers-secrets
key: REDIS_PASS
key: REDIS_PASSWORD
volumeMounts:
- name: redis-data
mountPath: /data
volumes:
- name: redis-data
persistentVolumeClaim:
claimName: defi-providers-redis-pvc
strategy: # temporary hack around "ReadWriteOnce" access mode issue (https://stackoverflow.com/a/62230273/4725013)
type: Recreate
---
apiVersion: v1
kind: Service
Expand Down
11 changes: 8 additions & 3 deletions src/app.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { resolve } from 'path';
import * as dotenv from 'dotenv';
dotenv.config();
dotenv.config({ path: `.env.${process.env.APP_ENV || 'dev'}` });
Expand All @@ -14,7 +13,10 @@ const {
LOGSTASH_HOST,
LOGSTASH_INDEX,
BASE_URL = './blockchainCache/',
REDIS_URL,
REDIS_HOST,
REDIS_PORT,
REDIS_USERNAME,
REDIS_PASSWORD,
} = process.env;

const config = {
Expand All @@ -28,7 +30,10 @@ const config = {
SLACK_WEBHOOK_URL,
SLACK_LOGGING,
BASE_URL,
REDIS_URL,
REDIS_HOST,
REDIS_PORT,
REDIS_USERNAME,
REDIS_PASSWORD,
};

const nodeUrls: { [key: string]: string } = {};
Expand Down
6 changes: 3 additions & 3 deletions src/util/redis.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { createClient } from 'redis';
import { log } from './logger/logger';
import { config } from '../app.config';
const { REDIS_URL } = config;
const { REDIS_HOST, REDIS_PORT, REDIS_USERNAME, REDIS_PASSWORD } = config;
let client;

function Redis() {
if (!client && REDIS_URL) {
if (!client && REDIS_HOST) {
client = createClient({
url: REDIS_URL,
url: `redis://${REDIS_USERNAME}:${REDIS_PASSWORD}@${REDIS_HOST}:${REDIS_PORT}`,
});
client.connect();
}
Expand Down

0 comments on commit f0df0b9

Please sign in to comment.