Skip to content

Commit

Permalink
Merge pull request #166 from autonomys/fix-production-env
Browse files Browse the repository at this point in the history
fix: production environment
  • Loading branch information
clostao authored Jan 31, 2025
2 parents 58f9dca + ac48c88 commit e718787
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 43 deletions.
1 change: 1 addition & 0 deletions backend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
database.json
28 changes: 28 additions & 0 deletions backend/src/awsSetup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import AWS from 'aws-sdk'

export const setupFinished = new Promise<void>((resolve) => {
const secretsManager = new AWS.SecretsManager({
region: process.env.AWS_REGION,
})

const secrets = Object.entries(process.env).filter(
([key, value]) => key.startsWith('AWS_SECRET_') && value !== undefined,
) as [string, string][]

const promises = secrets.map(async ([key, SecretId]) => {
return new Promise((resolve) => {
secretsManager.getSecretValue({ SecretId }, (err, data) => {
if (err) {
throw err
}
const realKey = key.replace('AWS_SECRET_', '')
process.env[realKey] = data.SecretString
resolve(true)
})
})
})

Promise.all(promises).then(() => {
resolve()
})
})
26 changes: 0 additions & 26 deletions backend/src/server.prod.ts

This file was deleted.

11 changes: 9 additions & 2 deletions backend/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
import './api.js'
import './worker.js'
const loadServer = async () => {
if (process.env.NODE_ENV === 'production') {
await import('./awsSetup.js').then(({ setupFinished }) => setupFinished)
}
await import('./worker.js')
await import('./api.js')
}

loadServer()
4 changes: 2 additions & 2 deletions backend/start-server.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
yarn db-migrate up
node dist/server.js
yarn db-migrate up -e ${NODE_ENV:-development}
yarn start
15 changes: 2 additions & 13 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,8 @@ services:
ports:
- "3000:3000"
restart: unless-stopped
environment:
DATABASE_URL: ${DATABASE_URL}
RPC_ENDPOINT: ${RPC_ENDPOINT}
PRIVATE_KEYS_PATH: ${PRIVATE_KEYS_PATH}
CORS_ALLOWED_ORIGINS: ${CORS_ALLOWED_ORIGINS}
OBJECT_MAPPING_ARCHIVER_URL: ${OBJECT_MAPPING_ARCHIVER_URL}
MAX_CACHE_SIZE: ${MAX_CACHE_SIZE}
JWT_SECRET: ${JWT_SECRET}
FILES_GATEWAY_URL: ${FILES_GATEWAY_URL}
FILES_GATEWAY_TOKEN: ${FILES_GATEWAY_TOKEN}
AUTH_SERVICE_URL: ${AUTH_SERVICE_URL}
AUTH_SERVICE_API_KEY: ${AUTH_SERVICE_API_KEY}
ACCEPT_UNAUTHORIZED_CERTS: ${ACCEPT_UNAUTHORIZED_CERTS}
env_file:
- .env
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000/health"]
interval: 15s
Expand Down

0 comments on commit e718787

Please sign in to comment.