Remove secrets loading as this is handled by k8s now. Fix redis init
This commit is contained in:
@ -19,7 +19,6 @@
|
||||
"@google-cloud/monitoring": "^4.0.0",
|
||||
"@google-cloud/opentelemetry-cloud-trace-exporter": "^2.0.0",
|
||||
"@google-cloud/pubsub": "^4.0.0",
|
||||
"@google-cloud/secret-manager": "^5.0.1",
|
||||
"@google-cloud/storage": "^7.0.1",
|
||||
"@google-cloud/tasks": "^4.0.0",
|
||||
"@graphql-tools/utils": "^9.1.1",
|
||||
@ -156,4 +155,4 @@
|
||||
"volta": {
|
||||
"extends": "../../package.json"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,28 +0,0 @@
|
||||
import { BackendEnv, getEnv } from './util'
|
||||
import { SecretManagerServiceClient } from '@google-cloud/secret-manager'
|
||||
|
||||
// When running on GCP we want to use secrets manager instead
|
||||
// of environment variables for storing secrets. This means
|
||||
// after startup we need to query secret manager, and
|
||||
// pull in those secrets.
|
||||
// To opt into this feature you need to set the `GCP_SECRETS_NAME`
|
||||
// environment variable to the secrets name for example:
|
||||
// `omnivore-project/secrets/my-secrets/latest`
|
||||
//
|
||||
export const loadEnvFromGCPSecrets = async (): Promise<
|
||||
BackendEnv | undefined
|
||||
> => {
|
||||
if (process.env.GCP_SECRETS_NAME && process.env.GCP_PROJECT_ID) {
|
||||
const client = new SecretManagerServiceClient()
|
||||
const [version] = await client.accessSecretVersion({
|
||||
name: `projects/${process.env.GCP_PROJECT_ID}/secrets/${process.env.GCP_SECRETS_NAME}/versions/latest`,
|
||||
})
|
||||
if (!version || !version.payload || !version.payload.data) {
|
||||
throw new Error(`no data for secret: ${process.env.GCP_SECRETS_NAME}`)
|
||||
}
|
||||
let data = Buffer.from(version.payload.data.toString(), 'base64')
|
||||
const result: any = JSON.parse(data.toString())
|
||||
return getEnv(result)
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
@ -4,7 +4,6 @@
|
||||
/* eslint-disable @typescript-eslint/no-misused-promises */
|
||||
import express, { Express } from 'express'
|
||||
import { appDataSource } from './data_source'
|
||||
import { loadEnvFromGCPSecrets } from './gcp-utils'
|
||||
import { getEnv } from './util'
|
||||
import { redisDataSource } from './redis_data_source'
|
||||
import { CustomTypeOrmLogger } from './utils/logger'
|
||||
@ -12,13 +11,13 @@ import { SnakeNamingStrategy } from 'typeorm-naming-strategies'
|
||||
import { refreshAllFeeds } from './jobs/rss/refreshAllFeeds'
|
||||
import { Job, Worker, QueueEvents } from 'bullmq'
|
||||
import { refreshFeed } from './jobs/rss/refreshFeed'
|
||||
import { env } from './env'
|
||||
|
||||
export const QUEUE_NAME = 'omnivore-backend-queue'
|
||||
|
||||
const main = async () => {
|
||||
console.log('[queue-processor]: starting queue processor')
|
||||
|
||||
let env = (await loadEnvFromGCPSecrets()) ?? getEnv(process.env)
|
||||
const app: Express = express()
|
||||
const port = process.env.PORT || 3002
|
||||
|
||||
|
||||
@ -8,7 +8,7 @@ export type RedisDataSourceOptions = {
|
||||
|
||||
export class RedisDataSource {
|
||||
options: RedisDataSourceOptions
|
||||
isInitialized: Boolean
|
||||
isInitialized: boolean
|
||||
|
||||
redisClient: Redis | undefined = undefined
|
||||
workerRedisClient: Redis | undefined = undefined
|
||||
@ -18,6 +18,7 @@ export class RedisDataSource {
|
||||
this.isInitialized = false
|
||||
}
|
||||
|
||||
// Forcing this to be async as we might do some more initialization in the future
|
||||
async initialize(): Promise<this> {
|
||||
if (this.isInitialized) throw 'Error already initialized'
|
||||
|
||||
@ -25,7 +26,7 @@ export class RedisDataSource {
|
||||
this.workerRedisClient = createIORedisClient(this.options)
|
||||
this.isInitialized = true
|
||||
|
||||
return this
|
||||
return Promise.resolve(this)
|
||||
}
|
||||
|
||||
setOptions(options: RedisDataSourceOptions): void {
|
||||
@ -34,10 +35,10 @@ export class RedisDataSource {
|
||||
|
||||
async shutdown(): Promise<void> {
|
||||
if (this.redisClient && this.redisClient.status == 'ready') {
|
||||
this.redisClient.quit()
|
||||
await this.redisClient.quit()
|
||||
}
|
||||
if (this.workerRedisClient && this.workerRedisClient.status == 'ready') {
|
||||
this.workerRedisClient.quit()
|
||||
await this.workerRedisClient.quit()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -45,7 +46,7 @@ export class RedisDataSource {
|
||||
const createIORedisClient = (
|
||||
options: RedisDataSourceOptions
|
||||
): Redis | undefined => {
|
||||
let redisURL = options.REDIS_URL
|
||||
const redisURL = options.REDIS_URL
|
||||
if (!redisURL) {
|
||||
throw 'Error: no redisURL supplied'
|
||||
}
|
||||
|
||||
@ -335,7 +335,7 @@ on smaller screens we display the note icon
|
||||
vertical-align: bottom;
|
||||
word-wrap: initial;
|
||||
font-family: 'SF Mono', monospace !important;
|
||||
white-space: pre;
|
||||
white-space: break-spaces;
|
||||
direction: ltr;
|
||||
unicode-bidi: embed;
|
||||
color: var(--font-color);
|
||||
|
||||
Reference in New Issue
Block a user