Skip to content

Commit

Permalink
added docker file and necessary utils for production environment
Browse files Browse the repository at this point in the history
  • Loading branch information
aruokhai committed Nov 27, 2024
1 parent 11d060a commit 5d30c84
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 44 deletions.
44 changes: 44 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# compiled output
/dist
/node_modules

# Logs
logs
*.log
npm-debug.log*
pnpm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# OS
.DS_Store

# Tests
/coverage
/.nyc_output

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# misc
/.silent-pay-indexer

#e2e
/e2e/.logs

#dev
/config/dev.config.yaml
/config/e2e.config.yaml
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ lerna-debug.log*

#e2e
/e2e/.logs

#dev
/config/dev.config.yaml
40 changes: 40 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Stage 1: Build the NestJS application
FROM node:22-alpine AS builder

WORKDIR /app

# Copy package.json and package-lock.json for efficient layer caching
COPY package*.json ./

# Install dependencies
RUN npm install

# Copy the rest of the application code
COPY . .

# Build the application
RUN npm run build

# Stage 2: Production image
FROM node:22-alpine AS production

WORKDIR /app

#Copy the compiled application from the build stage
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/migrations ./migrations

#Copy package.json and install only production dependencies
COPY package*.json ./
RUN npm install --omit=dev

# Set environment variables for SQLite path and app port
ENV DB_PATH="/app/data/database.sqlite"
ENV APP_PORT="80"

VOLUME /app/data

EXPOSE $APP_PORT

# Set up entrypoint to handle database migration and config generation
ENTRYPOINT ["sh", "-c", "npm run migration:run && mv dist/config/example.config.yaml dist/config/config.yaml && node dist/main.js"]
22 changes: 0 additions & 22 deletions config/config.yaml

This file was deleted.

21 changes: 0 additions & 21 deletions config/dev.config.yaml

This file was deleted.

18 changes: 18 additions & 0 deletions config/example.config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
db:
path: '~/.silent-pay-indexer/db/database.sqlite'
synchronize: false
app:
port: 3000
verbose: false
debug: true
network: regtest
requestRetry:
delay: 500 # delay in Milliseconds
count: 3
providerType: BITCOIN_CORE_RPC
bitcoinCore:
protocol: http # http | https
rpcHost: localhost
rpcPass: password
rpcUser: polaruser
rpcPort: 18443
2 changes: 1 addition & 1 deletion src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function mergeEnvVariablesRecursive(
for (const key of Object.keys(config)) {
const currentEnvVarName = envVarName
? `${envVarName}_${camelToSnakeCase(key)}`
: key.toUpperCase();
: camelToSnakeCase(key);
const currentEnvVarValue = process.env[currentEnvVarName];
if (config[key] && typeof config[key] === 'object') {
mergeEnvVariablesRecursive(config[key], currentEnvVarName);
Expand Down

0 comments on commit 5d30c84

Please sign in to comment.